From 24d721bcaaf59a2e4caa20fc21fda54c02b81828 Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Sun, 20 Sep 2026 21:12:03 -0500 Subject: [PATCH 1/2] Count only pairable pods during pairing discovery The discovery loop raised tooManyPodsFound whenever more than one pod peripheral was connected, and handed the first connected device to the pairing session. discoverPods reconnects every known device before scanning, so a user's previous pod that was still alive and known counted as a second pod, and the error told them to move away from pods that were their own. Filter the connected devices on the advertisement's pairable flag (pod id FFFF/FFFE for DASH, pdm id FFFFFFFE for O5), which each device already stores. A device with no advertisement yet is not counted; the scan fills it in for any pod that is advertising. --- OmnipodKit/Bluetooth/BlePodComms.swift | 2 +- OmnipodKit/Bluetooth/BluetoothManager.swift | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/OmnipodKit/Bluetooth/BlePodComms.swift b/OmnipodKit/Bluetooth/BlePodComms.swift index cdf0569f..5b3571a5 100644 --- a/OmnipodKit/Bluetooth/BlePodComms.swift +++ b/OmnipodKit/Bluetooth/BlePodComms.swift @@ -93,7 +93,7 @@ class BlePodComms: PodComms { // would hang without ever timing out. Always schedule on the main run loop. DispatchQueue.main.async { Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { timer in - let devices = self.bluetoothManager.getConnectedDevices() + let devices = self.bluetoothManager.getConnectedPairableDevices() if devices.count > 1 { self.log.default("Multiple pods found while scanning") diff --git a/OmnipodKit/Bluetooth/BluetoothManager.swift b/OmnipodKit/Bluetooth/BluetoothManager.swift index c765ab55..42f95905 100644 --- a/OmnipodKit/Bluetooth/BluetoothManager.swift +++ b/OmnipodKit/Bluetooth/BluetoothManager.swift @@ -1302,10 +1302,12 @@ class BluetoothManager: NSObject { // MARK: - Accessors - func getConnectedDevices() -> [Omni] { + func getConnectedPairableDevices() -> [Omni] { var connected: [Omni] = [] managerQueue.sync { - connected = self.devices.filter { $0.manager.peripheral.state == .connected } + connected = self.devices.filter { + $0.manager.peripheral.state == .connected && $0.advertisement?.pairable == true + } } return connected } From 173e413dab53c9726f9c5dd4e92ad7b30bd12ed2 Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Sun, 20 Sep 2026 21:26:25 -0500 Subject: [PATCH 2/2] Treat our own pod as a pairing candidate; pre-connect only our pod devices holds every pod advert the scan has heard, not just ours: didDiscover adds any parseable pod, and the DASH discovery filter matches every DASH pod in range, paired or not. forgetPod prunes the old pod, but the next scan re-adds it if it is still alive. On a pairing retry discoverPods then pre-connected all of them, which is how a second connected pod appeared and raised tooManyPodsFound. Pre-connect only devices in autoConnectIDs, which is what the pre-connect is for: resuming a pod that discovery already picked and that may no longer advertise as pairable. Count that pod as a candidate too, so resuming it still succeeds under the pairable filter from the previous commit. --- OmnipodKit/Bluetooth/BlePodComms.swift | 2 +- OmnipodKit/Bluetooth/BluetoothManager.swift | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/OmnipodKit/Bluetooth/BlePodComms.swift b/OmnipodKit/Bluetooth/BlePodComms.swift index 5b3571a5..3f72e2aa 100644 --- a/OmnipodKit/Bluetooth/BlePodComms.swift +++ b/OmnipodKit/Bluetooth/BlePodComms.swift @@ -93,7 +93,7 @@ class BlePodComms: PodComms { // would hang without ever timing out. Always schedule on the main run loop. DispatchQueue.main.async { Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { timer in - let devices = self.bluetoothManager.getConnectedPairableDevices() + let devices = self.bluetoothManager.getConnectedPairingCandidates() if devices.count > 1 { self.log.default("Multiple pods found while scanning") diff --git a/OmnipodKit/Bluetooth/BluetoothManager.swift b/OmnipodKit/Bluetooth/BluetoothManager.swift index 42f95905..1f4b73f8 100644 --- a/OmnipodKit/Bluetooth/BluetoothManager.swift +++ b/OmnipodKit/Bluetooth/BluetoothManager.swift @@ -846,7 +846,7 @@ class BluetoothManager: NSObject { delayedProbeInFlight = false alarmScanSuppressed = false manager.stopScan() - for device in devices { + for device in devices where autoConnectIDs.contains(device.manager.peripheral.identifier.uuidString) { let peripheral = device.manager.peripheral switch peripheral.state { case .connecting where !isConnectWatchdogActive(peripheral): @@ -1302,11 +1302,12 @@ class BluetoothManager: NSObject { // MARK: - Accessors - func getConnectedPairableDevices() -> [Omni] { + func getConnectedPairingCandidates() -> [Omni] { var connected: [Omni] = [] managerQueue.sync { connected = self.devices.filter { - $0.manager.peripheral.state == .connected && $0.advertisement?.pairable == true + $0.manager.peripheral.state == .connected && + ($0.advertisement?.pairable == true || self.autoConnectIDs.contains($0.manager.peripheral.identifier.uuidString)) } } return connected