Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Pod Pairing error message #121

Merged
merged 6 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions OmniBLE/PumpManager/PodCommsSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public enum PodCommsError: Error {
case noPodsFound
case tooManyPodsFound
case setupNotComplete
case possibleBluetoothIssue
}

extension PodCommsError: LocalizedError {
Expand Down Expand Up @@ -99,6 +100,8 @@ extension PodCommsError: LocalizedError {
return LocalizedString("Too many pods found", comment: "Error message for PodCommsError.tooManyPodsFound")
case .setupNotComplete:
return LocalizedString("Pod setup is not complete", comment: "Error description when pod setup is not complete")
case .possibleBluetoothIssue:
return LocalizedString("Possible Bluetooth issue", comment: "Error description for possible bluetooth issue")
marionbarker marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -162,6 +165,8 @@ extension PodCommsError: LocalizedError {
return LocalizedString("Move to a new area away from any other pods and try again.", comment: "Recovery suggestion for PodCommsError.tooManyPodsFound")
case .setupNotComplete:
return nil
case .possibleBluetoothIssue:
return LocalizedString("Toggle Bluetooth off and then on in iPhone Settings; then try again.", comment: "Recovery suggestion for possible bluetooth issue")
}
}

Expand Down Expand Up @@ -248,6 +253,8 @@ public class PodCommsSession {
/// - PodCommsError.rejectedMessage
/// - PodCommsError.nonceResyncFailed
/// - MessageError
/// - PeripheralManagerError
/// - PodProtocolError
func send<T: MessageBlock>(_ messageBlocks: [MessageBlock], beepBlock: MessageBlock? = nil, expectFollowOnMessage: Bool = false) throws -> T {

var triesRemaining = 2 // Retries only happen for nonce resync
Expand Down
26 changes: 24 additions & 2 deletions OmniBLE/PumpManagerUI/ViewModels/PairPodViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,28 @@ class PairPodViewModel: ObservableObject, Identifiable {
}
}

// Return a suitable DashPairingError for the returned PumpManagerError
private func mapPumpManagerError(_ pumpManagerError: PumpManagerError) -> DashPairingError {
marionbarker marked this conversation as resolved.
Show resolved Hide resolved
print("### mapPumpManagerError encountered error \(pumpManagerError.localizedDescription)")
switch (pumpManagerError) {
case .communication(let error):
if let podCommsError = error as? PodCommsError {
switch podCommsError {
case .commsError(let error):
// Return a possible bluetooth error for any lower level comms errors
let possibleBluetoothError = DashPairingError.pumpManagerError(.communication(PodCommsError.possibleBluetoothIssue))
print("### mapPumpManagerError returning error \(possibleBluetoothError.localizedDescription)")
return possibleBluetoothError
default:
break
}
}
default:
break
}
return DashPairingError.pumpManagerError(pumpManagerError)
}

private func pairAndPrime() {
if podPairer.podCommState == .noPod {
state = .pairing
Expand All @@ -193,11 +215,11 @@ class PairPodViewModel: ObservableObject, Identifiable {
switch status {
case .failure(let error):
if self.podPairer.podCommState == .noPod {
let pairAndPrimeError = DashPairingError.pumpManagerError(error)
let pairAndPrimeError = self.mapPumpManagerError(error)
self.state = .error(pairAndPrimeError)
} else if self.autoRetryAttempted {
self.autoRetryAttempted = false // allow for an auto retry on the next user attempt
let pairAndPrimeError = DashPairingError.pumpManagerError(error)
let pairAndPrimeError = self.mapPumpManagerError(error)
self.state = .error(pairAndPrimeError)
} else {
self.autoRetryAttempted = true
Expand Down