Skip to content

Commit

Permalink
set initial expirationReminderDate after priming
Browse files Browse the repository at this point in the history
  • Loading branch information
ps2 committed Apr 12, 2019
1 parent 97acf9d commit 9d21f33
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
13 changes: 4 additions & 9 deletions OmniKit/PumpManager/OmnipodPumpManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ public class OmnipodPumpManager: RileyLinkPumpManager, PumpManager {

public weak var pumpManagerDelegate: PumpManagerDelegate? {
didSet {
pumpManagerDelegate?.clearNotification(for: self, identifier: LoopNotificationCategory.pumpExpirationWarning.rawValue)
self.queue.async {
self.clearPodExpirationNotification()
self.schedulePodExpirationNotification()
Expand Down Expand Up @@ -536,17 +535,11 @@ public class OmnipodPumpManager: RileyLinkPumpManager, PumpManager {
return
}

guard let podState = self.state.podState else {
completion(.failure(OmnipodPumpManagerError.noPodPaired))
return
}

self.podComms.runSession(withName: "Configure and prime pod", using: deviceSelector) { (result) in
switch result {
case .success(let session):
do {
let primeFinishedAt = try session.prime()
self.state.expirationReminderDate = podState.expiresAt?.addingTimeInterval(-Pod.expirationReminderAlertDefaultTimeBeforeExpiration)
completion(.success(primeFinishedAt))
} catch let error {
completion(.failure(error))
Expand Down Expand Up @@ -578,12 +571,14 @@ public class OmnipodPumpManager: RileyLinkPumpManager, PumpManager {

queue.async {

guard let podState = self.state.podState, podState.readyForCannulaInsertion else
guard let podState = self.state.podState, let expiresAt = podState.expiresAt, podState.readyForCannulaInsertion else
{
completion(.failure(OmnipodPumpManagerError.notReadyForCannulaInsertion))
return
}


self.expirationReminderDate = expiresAt.addingTimeInterval(-Pod.expirationReminderAlertDefaultTimeBeforeExpiration)

guard podState.setupProgress.needsCannulaInsertion else {
completion(.failure(OmnipodPumpManagerError.podAlreadyPaired))
return
Expand Down
12 changes: 9 additions & 3 deletions OmniKit/PumpManager/PodState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ public struct PodState: RawRepresentable, Equatable, CustomDebugStringConvertibl
}

public mutating func updateFromStatusResponse(_ response: StatusResponse) {
if activatedAt == nil {
self.activatedAt = Date() - response.timeActive
}
updateDeliveryStatus(deliveryStatus: response.deliveryStatus)
lastInsulinMeasurements = PodInsulinMeasurements(statusResponse: response, validTime: Date())
activeAlertSlots = response.alerts
Expand Down Expand Up @@ -215,7 +218,6 @@ public struct PodState: RawRepresentable, Equatable, CustomDebugStringConvertibl
let address = rawValue["address"] as? UInt32,
let nonceStateRaw = rawValue["nonceState"] as? NonceState.RawValue,
let nonceState = NonceState(rawValue: nonceStateRaw),
let activatedAt = rawValue["activatedAt"] as? Date,
let piVersion = rawValue["piVersion"] as? String,
let pmVersion = rawValue["pmVersion"] as? String,
let lot = rawValue["lot"] as? UInt32,
Expand All @@ -226,12 +228,16 @@ public struct PodState: RawRepresentable, Equatable, CustomDebugStringConvertibl

self.address = address
self.nonceState = nonceState
self.activatedAt = activatedAt
self.piVersion = piVersion
self.pmVersion = pmVersion
self.lot = lot
self.tid = tid



if let activatedAt = rawValue["activatedAt"] as? Date {
self.activatedAt = activatedAt
}

if let suspended = rawValue["suspended"] as? Bool {
self.suspended = suspended
} else {
Expand Down

0 comments on commit 9d21f33

Please sign in to comment.