Просмотр исходного кода

improve alert message from pump and acknowledge in all cases

avouspierre 3 лет назад
Родитель
Сommit
caa63554e2

+ 3 - 0
FreeAPS/Sources/APS/APSManager.swift

@@ -35,6 +35,7 @@ enum APSError: LocalizedError {
     case glucoseError(message: String)
     case glucoseError(message: String)
     case apsError(message: String)
     case apsError(message: String)
     case deviceSyncError(message: String)
     case deviceSyncError(message: String)
+    case deviceAlert(message: String)
 
 
     var errorDescription: String? {
     var errorDescription: String? {
         switch self {
         switch self {
@@ -48,6 +49,8 @@ enum APSError: LocalizedError {
             return "APS error: \(message)"
             return "APS error: \(message)"
         case let .deviceSyncError(message):
         case let .deviceSyncError(message):
             return "Sync error: \(message)"
             return "Sync error: \(message)"
+        case let .deviceAlert(message):
+            return "Pump message: \(message)"
         }
         }
     }
     }
 }
 }

+ 2 - 0
FreeAPS/Sources/APS/DeviceDataManager.swift

@@ -432,6 +432,8 @@ extension BaseDeviceDataManager: DeviceManagerDelegate {
     func issueAlert(_ alert: Alert) {
     func issueAlert(_ alert: Alert) {
         if !alertStore.contains(where: { $0.identifier.alertIdentifier == alert.identifier.alertIdentifier }) {
         if !alertStore.contains(where: { $0.identifier.alertIdentifier == alert.identifier.alertIdentifier }) {
             alertStore.append(alert)
             alertStore.append(alert)
+            let infoMessage = APSError.deviceAlert(message: alert.foregroundContent!.body)
+            errorSubject.send(infoMessage)
             broadcaster.notify(pumpNotificationObserver.self, on: processQueue) {
             broadcaster.notify(pumpNotificationObserver.self, on: processQueue) {
                 $0.pumpNotification(alert: alert)
                 $0.pumpNotification(alert: alert)
             }
             }

+ 5 - 4
FreeAPS/Sources/Services/UserNotifiactions/UserNotificationsManager.swift

@@ -418,10 +418,11 @@ extension BaseUserNotificationsManager: pumpNotificationObserver {
                 deleteOld: true,
                 deleteOld: true,
                 trigger: nil
                 trigger: nil
             )
             )
-            self.apsManager.pumpManager?.acknowledgeAlert(alertIdentifier: alert.identifier.alertIdentifier) { error in
-                if let error = error {
-                    debug(.deviceManager, "acknowledge not succeeded with error \(error.localizedDescription)")
-                }
+        }
+        // Acknowledge in all case the alert to stop beep (in particular)
+        apsManager.pumpManager?.acknowledgeAlert(alertIdentifier: alert.identifier.alertIdentifier) { error in
+            if let error = error {
+                debug(.deviceManager, "acknowledge not succeeded with error \(error.localizedDescription)")
             }
             }
         }
         }
     }
     }