diff --git a/OmniKit/PumpManager/OmnipodPumpManager.swift b/OmniKit/PumpManager/OmnipodPumpManager.swift index ced14701f..61b5aa259 100644 --- a/OmniKit/PumpManager/OmnipodPumpManager.swift +++ b/OmniKit/PumpManager/OmnipodPumpManager.swift @@ -499,6 +499,7 @@ extension OmnipodPumpManager { #if targetEnvironment(simulator) // If we're in the simulator, create a mock PodState let mockFaultDuringPairing = false + let mockCommsErrorDuringPairing = true DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now() + .seconds(2)) { self.jumpStartPod(address: 0x1f0b3557, lot: 40505, tid: 6439, mockFault: mockFaultDuringPairing) let fault: PodInfoFaultEvent? = self.setStateWithResult({ (state) in @@ -507,6 +508,8 @@ extension OmnipodPumpManager { }) if mockFaultDuringPairing { completion(.failure(PodCommsError.podFault(fault: fault!))) + } else if mockCommsErrorDuringPairing { + completion(.failure(PodCommsError.noResponse)) } else { let mockPrimeDuration = TimeInterval(.seconds(3)) completion(.success(mockPrimeDuration)) diff --git a/OmniKitUI/ViewControllers/PairPodSetupViewController.swift b/OmniKitUI/ViewControllers/PairPodSetupViewController.swift index 5cbc72db0..885fd87ea 100644 --- a/OmniKitUI/ViewControllers/PairPodSetupViewController.swift +++ b/OmniKitUI/ViewControllers/PairPodSetupViewController.swift @@ -17,6 +17,8 @@ class PairPodSetupViewController: SetupTableViewController { var rileyLinkPumpManager: RileyLinkPumpManager! + var previouslyEncounteredWeakComms: Bool = false + var pumpManager: OmnipodPumpManager! { didSet { if oldValue == nil && pumpManager != nil { @@ -123,17 +125,23 @@ class PairPodSetupViewController: SetupTableViewController { return } - var errorText = lastError?.localizedDescription + var errorStrings: [String] if let error = lastError as? LocalizedError { - let localizedText = [error.errorDescription, error.failureReason, error.recoverySuggestion].compactMap({ $0 }).joined(separator: ". ") + "." - - if !localizedText.isEmpty { - errorText = localizedText + errorStrings = [error.errorDescription, error.failureReason, error.recoverySuggestion].compactMap { $0 } + } else { + errorStrings = [lastError?.localizedDescription].compactMap { $0 } + } + + if let commsError = lastError as? PodCommsError, commsError.possibleWeakCommsCause { + if previouslyEncounteredWeakComms { + errorStrings.append(LocalizedString("If the problem persists, move to a new area and try again", comment: "Additional pairing recovery suggestion on multiple pairing failures")) + } else { + previouslyEncounteredWeakComms = true } } - loadingText = errorText + loadingText = errorStrings.joined(separator: ". ") + "." // If we have an error, update the continue state if let podCommsError = lastError as? PodCommsError, @@ -207,6 +215,17 @@ class PairPodSetupViewController: SetupTableViewController { } } +private extension PodCommsError { + var possibleWeakCommsCause: Bool { + switch self { + case .invalidData, .noResponse: + return true + default: + return false + } + } +} + private extension SetupButton { func setPairTitle() { setTitle(LocalizedString("Pair", comment: "Button title to pair with pod during setup"), for: .normal)