瀏覽代碼

Fix Silence Pod toggle bug which inadvertently cleared configured alerts (#452)

Joe Moran 2 年之前
父節點
當前提交
99d88fef3c

+ 9 - 4
Dependencies/OmniBLE/OmniBLE/PumpManager/PodCommsSession.swift

@@ -380,15 +380,20 @@ public class PodCommsSession {
         podState.finalizedDoses.append(UnfinalizedDose(resumeStartTime: currentDate, scheduledCertainty: .certain, insulinType: podState.insulinType))
     }
 
+    // Configures the given pod alert(s) and registers the newly configured alert slot(s).
+    // When re-configuring all the pod alerts for a silence pod toggle, the optional acknowledgeAll can be
+    // specified to first acknowledge and clear all possible pending pod alerts and pod alert configurations.
     @discardableResult
     func configureAlerts(_ alerts: [PodAlert], acknowledgeAll: Bool = false, beepBlock: MessageBlock? = nil) throws -> StatusResponse {
         let configurations = alerts.map { $0.configuration }
         let configureAlerts = ConfigureAlertsCommand(nonce: podState.currentNonce, configurations: configurations)
-        var blocksToSend: [MessageBlock] = [configureAlerts]
+        let blocksToSend: [MessageBlock]
         if acknowledgeAll {
-            // requested to acknowledge any possible pending pod alerts out of an abundnace of caution
-            let acknowledgeAll = AcknowledgeAlertCommand(nonce: podState.currentNonce, alerts: AlertSet(rawValue: ~0))
-            blocksToSend += [acknowledgeAll]
+            // Do the acknowledgeAllAlerts command first to clear all previous pod alert configurations.
+            let acknowledgeAllAlerts = AcknowledgeAlertCommand(nonce: podState.currentNonce, alerts: AlertSet(rawValue: ~0))
+            blocksToSend = [acknowledgeAllAlerts, configureAlerts]
+        } else {
+            blocksToSend = [configureAlerts]
         }
         let status: StatusResponse = try send(blocksToSend, beepBlock: beepBlock)
         for alert in alerts {

+ 9 - 4
Dependencies/OmniKit/OmniKit/PumpManager/PodCommsSession.swift

@@ -386,15 +386,20 @@ public class PodCommsSession {
         podState.finalizedDoses.append(UnfinalizedDose(resumeStartTime: currentDate, scheduledCertainty: .certain, insulinType: podState.insulinType))
     }
 
+    // Configures the given pod alert(s) and registers the newly configured alert slot(s).
+    // When re-configuring all the pod alerts for a silence pod toggle, the optional acknowledgeAll can be
+    // specified to first acknowledge and clear all possible pending pod alerts and pod alert configurations.
     @discardableResult
     func configureAlerts(_ alerts: [PodAlert], acknowledgeAll: Bool = false, beepBlock: MessageBlock? = nil) throws -> StatusResponse {
         let configurations = alerts.map { $0.configuration }
         let configureAlerts = ConfigureAlertsCommand(nonce: podState.currentNonce, configurations: configurations)
-        var blocksToSend: [MessageBlock] = [configureAlerts]
+        let blocksToSend: [MessageBlock]
         if acknowledgeAll {
-            // requested to acknowledge any possible pending pod alerts out of an abundnace of caution
-            let acknowledgeAll = AcknowledgeAlertCommand(nonce: podState.currentNonce, alerts: AlertSet(rawValue: ~0))
-            blocksToSend += [acknowledgeAll]
+            // Do the acknowledgeAllAlerts command first to clear all previous pod alert configurations.
+            let acknowledgeAllAlerts = AcknowledgeAlertCommand(nonce: podState.currentNonce, alerts: AlertSet(rawValue: ~0))
+            blocksToSend = [acknowledgeAllAlerts, configureAlerts]
+        } else {
+            blocksToSend = [configureAlerts]
         }
         let status: StatusResponse = try send(blocksToSend, beepBlock: beepBlock)
         for alert in alerts {