Skip to content

Commit

Permalink
Merge pull request #38 from itsmojo/podAlreadyPaired-fix
Browse files Browse the repository at this point in the history
Fix for perpetual Insert Cannula "Pod Already Paired" errors
  • Loading branch information
marionbarker authored Aug 19, 2024
2 parents 03d3a1d + d9d7ce5 commit 849dc7a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
6 changes: 5 additions & 1 deletion OmniKitUI/ViewModels/InsertCannulaViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class InsertCannulaViewModel: ObservableObject, Identifiable {
}

@Published var state: InsertCannulaViewModelState = .ready

public var stateNeedsDeliberateUserAcceptance : Bool {
switch state {
case .ready:
Expand Down Expand Up @@ -187,7 +188,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")
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 {
Expand Down
22 changes: 18 additions & 4 deletions OmniKitUI/Views/InsertCannulaView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ struct InsertCannulaView: View {
if (self.viewModel.error == nil || self.viewModel.error?.recoverable == true) {
actionButton
.disabled(self.viewModel.state.isProcessing)
.animation(nil)
.zIndex(1)
}
}
.transition(AnyTransition.opacity.combined(with: .move(edge: .bottom)))
.padding()
}
.animation(.default)
.alert(isPresented: $cancelModalIsPresented) { cancelPairingModal }
.navigationBarTitle(LocalizedString("Insert Cannula", comment: "navigation bar title for insert cannula"), displayMode: .automatic)
.navigationBarBackButtonHidden(true)
Expand Down Expand Up @@ -107,8 +109,6 @@ struct InsertCannulaView: View {
}

}


}


Expand All @@ -131,9 +131,23 @@ struct InsertCannulaView: View {
}

class MockCannulaInserter: CannulaInserter {
let mockError: Bool = false
let mockPodAlreadyPairedError: Bool = false

func insertCannula(completion: @escaping (Result<TimeInterval,OmnipodPumpManagerError>) -> Void) {
let mockDelay = TimeInterval(seconds: 3)
let result :Result<TimeInterval, OmnipodPumpManagerError> = .success(mockDelay)
let result :Result<TimeInterval, OmnipodPumpManagerError>
if mockError {
if mockPodAlreadyPairedError {
// A podAlreadyPaired "error" should be treated as an immediate success
result = .failure(OmnipodPumpManagerError.podAlreadyPaired)
} else {
// Others should display the error text and show Deactivate Pod & Retry options
result = .failure(OmnipodPumpManagerError.noPodPaired)
}
} else {
let mockDelay = TimeInterval(seconds: 3)
result = .success(mockDelay)
}
completion(result)
}

Expand Down

0 comments on commit 849dc7a

Please sign in to comment.