Преглед изворни кода

Merge branch 'dev' of github.com:nightscout/Trio-dev into determination-data-migration

Deniz Cengiz пре 1 година
родитељ
комит
b64ccee7cd

+ 11 - 0
Trio/Sources/APS/APSManager.swift

@@ -49,6 +49,17 @@ enum APSError: LocalizedError {
             return String(localized: "Manual Temporary Basal Rate (\(message)). Looping suspended.")
         }
     }
+
+    static func pumpErrorMatches(message: String) -> Bool {
+        message.contains(String(localized: "Pump Error"))
+    }
+
+    static func pumpWarningMatches(message: String) -> Bool {
+        message.contains(String(localized: "Invalid Pump State")) || message
+            .contains("PumpMessage") || message
+            .contains("PumpOpsError") || message.contains("RileyLink") || message
+            .contains(String(localized: "Pump did not respond in time"))
+    }
 }
 
 final class BaseAPSManager: APSManager, Injectable {

+ 9 - 0
Trio/Sources/Localizations/Main/Localizable.xcstrings

@@ -124070,6 +124070,9 @@
         }
       }
     },
+    "Invalid Pump State" : {
+
+    },
     "Invalid Pump State (%@)." : {
       "localizations" : {
         "bg" : {
@@ -167255,6 +167258,12 @@
         }
       }
     },
+    "Pump did not respond in time" : {
+
+    },
+    "Pump Error" : {
+
+    },
     "Pump Error (%@)." : {
       "localizations" : {
         "bg" : {

+ 19 - 6
Trio/Sources/Modules/Main/MainStateModel.swift

@@ -6,6 +6,7 @@ import Swinject
 
 extension Main {
     final class StateModel: BaseStateModel<Provider> {
+        @Injected() private var apsManager: APSManager!
         @Injected() var alertPermissionsChecker: AlertPermissionsChecker!
         @Injected() var broadcaster: Broadcaster!
         private(set) var modal: Modal?
@@ -204,24 +205,36 @@ extension Main {
         /*
           Reclassification is needed for Medtronic pumps for 'Pump error:' RileyLink related messages.
           For details, see https://discord.com/channels/1020905149037813862/1338245444186279946/1343469793013141525.
-          Reclassification of Info type messages is based on APSManager.APSError enum values.
-          Currently, we only re-classify APSError.pumpError 'Pump error:' type to MessageType.error.
+          These messages are repeatedly displayed causing users to simply ignore them.
+          Reclassification of these Info type messages is based on APSManager.APSError enum values.
+          We reclassify APSError.pumpError and APSError.invalidPumpState as MessageType.info and MessageSubtype.pump.
+          This allows the user to disable these messages using using the 'Trio Notification' -> 'Always Notify Pump' setting.
           MessageType.error messagges are always displayed to the user and the user cannot disable them.
           Other APSManager.APSError remain as MessageType.info which allows users to disable them
           using the 'Trio Notification' -> 'Always Notify Algorithm' setting.
          */
+
         func reclassifyInfoNotification(_ message: inout MessageContent) {
             if message.title == "" {
                 switch message.type {
                 case .info:
-                    if let errorIndex = message.content.range(of: "error", options: .caseInsensitive) {
+                    if message.content.range(of: "error", options: .caseInsensitive) != nil || message.content
+                        .range(of: String(localized: "Error"), options: .caseInsensitive) != nil
+                    {
                         message.title = String(localized: "Error", comment: "Error title")
-                        if let errorPumpIndex = message.content.range(of: "Pump error:", options: .caseInsensitive) {
-                            message.type = .error
-                        }
                     } else {
                         message.title = String(localized: "Info", comment: "Info title")
                     }
+                    if APSError.pumpWarningMatches(message: message.content) {
+                        message.subtype = .pump
+                        let lastLoopMinutes = Int((Date().timeIntervalSince(apsManager.lastLoopDate) - 30) / 60) + 1
+                        if lastLoopMinutes > 10 {
+                            message.type = .error
+                        }
+                    } else if APSError.pumpErrorMatches(message: message.content) {
+                        message.subtype = .pump
+                        message.type = .error
+                    }
                 case .warning:
                     message.title = String(localized: "Warning", comment: "Warning title")
                 case .error:

+ 5 - 1
Trio/Sources/Services/UserNotifications/UserNotificationsManager.swift

@@ -497,7 +497,11 @@ extension BaseUserNotificationsManager: alertMessageNotificationObserver {
         }
         switch message.subtype {
         case .pump:
-            identifier = .pumpNotification
+            if message.type == .info || message.type == .error {
+                identifier = Identifier.alertMessageNotification
+            } else {
+                identifier = .pumpNotification
+            }
         case .carb:
             identifier = .carbsRequiredNotification
         case .glucose: