Skip to content

Commit

Permalink
Suggest moving to new area on persistent comms issues (#609)
Browse files Browse the repository at this point in the history
* Suggest moving to new area on persistent comms issues

* Fix typo
  • Loading branch information
ps2 authored May 18, 2020
1 parent e6ab18f commit d19631c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
3 changes: 3 additions & 0 deletions OmniKit/PumpManager/OmnipodPumpManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
31 changes: 25 additions & 6 deletions OmniKitUI/ViewControllers/PairPodSetupViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class PairPodSetupViewController: SetupTableViewController {

var rileyLinkPumpManager: RileyLinkPumpManager!

var previouslyEncounteredWeakComms: Bool = false

var pumpManager: OmnipodPumpManager! {
didSet {
if oldValue == nil && pumpManager != nil {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d19631c

Please sign in to comment.