From f8f926fa21a90492fb77531c44bfb4a86b408d23 Mon Sep 17 00:00:00 2001 From: Joe Moran Date: Thu, 15 Aug 2024 01:08:09 -0700 Subject: [PATCH 1/2] Fix for perpetual Insert Cannula "Pod Already Paired" errors + Add optional mock error Preview handling code for testing --- .../ViewModels/InsertCannulaViewModel.swift | 5 ++++- .../Views/InsertCannulaView.swift | 22 +++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/OmniBLE/PumpManagerUI/ViewModels/InsertCannulaViewModel.swift b/OmniBLE/PumpManagerUI/ViewModels/InsertCannulaViewModel.swift index 733fc36b..28502001 100644 --- a/OmniBLE/PumpManagerUI/ViewModels/InsertCannulaViewModel.swift +++ b/OmniBLE/PumpManagerUI/ViewModels/InsertCannulaViewModel.swift @@ -187,7 +187,10 @@ class InsertCannulaViewModel: ObservableObject, Identifiable { self.state = .finished } case .failure(let error): - if self.autoRetryAttempted { + if case .podAlreadyPaired = error { + print("### insertCannula treating podAlreadyPaired as success to avoid looping!") + self.state = .finished + } else if self.autoRetryAttempted { self.autoRetryAttempted = false // allow for an auto retry on the next user attempt self.state = .error(error) } else { diff --git a/OmniBLE/PumpManagerUI/Views/InsertCannulaView.swift b/OmniBLE/PumpManagerUI/Views/InsertCannulaView.swift index 30133eed..e4a66da9 100644 --- a/OmniBLE/PumpManagerUI/Views/InsertCannulaView.swift +++ b/OmniBLE/PumpManagerUI/Views/InsertCannulaView.swift @@ -132,16 +132,30 @@ struct InsertCannulaView: View { } class MockCannulaInserter: CannulaInserter { + let mockError: Bool = false + let mockPodAlreadyPairedError: Bool = false + func insertCannula(completion: @escaping (Result) -> Void) { - let mockDelay = TimeInterval(seconds: 3) - let result :Result = .success(mockDelay) + let result :Result + if mockError { + if mockPodAlreadyPairedError { + // A podAlreadyPaired "error" should be treated as an immediate success + result = .failure(OmniBLEPumpManagerError.podAlreadyPaired) + } else { + // Others should display the error text and show Deactivate Pod & Retry options + result = .failure(OmniBLEPumpManagerError.noPodPaired) + } + } else { + let mockDelay = TimeInterval(seconds: 3) + result = .success(mockDelay) + } completion(result) } - + func checkCannulaInsertionFinished(completion: @escaping (OmniBLEPumpManagerError?) -> Void) { completion(nil) } - + var cannulaInsertionSuccessfullyStarted: Bool = false } From 5e3d1c42b5e7d17b448b8a5747d83e6793923a17 Mon Sep 17 00:00:00 2001 From: Joe Moran Date: Sat, 17 Aug 2024 00:19:42 -0700 Subject: [PATCH 2/2] Use a shorter and less confusing log message --- OmniBLE/PumpManagerUI/ViewModels/InsertCannulaViewModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OmniBLE/PumpManagerUI/ViewModels/InsertCannulaViewModel.swift b/OmniBLE/PumpManagerUI/ViewModels/InsertCannulaViewModel.swift index 28502001..a26c24a6 100644 --- a/OmniBLE/PumpManagerUI/ViewModels/InsertCannulaViewModel.swift +++ b/OmniBLE/PumpManagerUI/ViewModels/InsertCannulaViewModel.swift @@ -188,7 +188,7 @@ class InsertCannulaViewModel: ObservableObject, Identifiable { } case .failure(let error): if case .podAlreadyPaired = error { - print("### insertCannula treating podAlreadyPaired as success to avoid looping!") + print("### insertCannula treating podAlreadyPaired as success") self.state = .finished } else if self.autoRetryAttempted { self.autoRetryAttempted = false // allow for an auto retry on the next user attempt