Skip to content
Merged
Changes from all 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
18 changes: 12 additions & 6 deletions OmniBLE/PumpManager/OmniBLEPumpManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1068,23 +1068,29 @@ extension OmniBLEPumpManager {

public func setTime(completion: @escaping (OmniBLEPumpManagerError?) -> Void) {

guard state.hasActivePod else {
completion(OmniBLEPumpManagerError.noPodPaired)
let timeZone = TimeZone.currentFixed
guard let podState = state.podState, podState.fault == nil else {
// With no non-faulted pod just update our pump manager
// state with the current timezone and return success
// instead of an inappropriate "No pod paired" error.
self.setState { (state) in
state.timeZone = timeZone
}
completion(nil)
return
}

guard state.podState?.setupProgress == .completed else {
guard podState.isSetupComplete else {
// A cancel delivery command before pod setup is complete will fault the pod
completion(.state(PodCommsError.setupNotComplete))
return
}

guard state.podState?.unfinalizedBolus?.isFinished() != false else {
guard podState.unfinalizedBolus?.isFinished() != false else {
completion(.state(PodCommsError.unfinalizedBolus))
return
}

let timeZone = TimeZone.currentFixed
self.podComms.runSession(withName: "Set time zone") { (result) in
switch result {
case .success(let session):
Expand Down Expand Up @@ -1119,7 +1125,7 @@ extension OmniBLEPumpManager {
}

guard state.podState?.unfinalizedBolus?.isFinished() != false else {
return .failure(.deviceState(PodCommsError.unfinalizedBolus))
return .failure(PumpManagerError.deviceState(PodCommsError.unfinalizedBolus))
}

return .success(true)
Expand Down