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

Import errors

(cherry picked from commit 207f6e7508a789f6c51799ad7809ecf7ddf6a3ba)
Jon Mårtensson 2 лет назад
Родитель
Сommit
0120c7262b

+ 10 - 4
FreeAPS/Sources/Localizations/Main/en.lproj/Localizable.strings

@@ -317,12 +317,18 @@ Enact a temp Basal or a temp target */
 /* Imported Profiles Alert */
 "\nNow please verify all of your new settings thoroughly:\n\n* Basal Settings\n * Carb Ratios\n * Glucose Targets\n * Insulin Sensitivities\n\n in iAPS Settings > Configuration.\n\nBad or invalid profile settings could have disatrous effects." = "\nNow please verify all of your new settings thoroughly:\n\n* Basal Settings\n * Carb Ratios\n * Glucose Targets\n * Insulin Sensitivities\n\n in iAPS Settings > Configuration.\n\nBad or invalid profile settings could have disatrous effects.";
 
-/* Failed Profile Import Alert */
-"\nImport failed:\n\n*" = "\nImport failed:\n\n*";
-
 /* Profile Import Alert */
 "This will replace some or all of your current pump settings. Are you sure you want to import profile settings from Nightscout?" = "This will replace some or all of your current pump settings. Are you sure you want to import profile settings from Nightscout?";
 
+/* Import Error */
+"\nInvalid Nightcsout Basal Settings. \n\nImport aborted. Please check your Nightscout Profile Basal Settings!" = "\nInvalid Nightcsout Basal Settings. \n\nImport aborted. Please check your Nightscout Profile Basal Settings!";
+
+/* Import Error */
+"\nSettings were imported but the Basals couldn't be saved to pump (No pump). Check your basal settings and tap ´Save on Pump´ to sync the new basal settings" =  "\nSettings were imported but the Basals couldn't be saved to pump (No pump). Check your basal settings and tap ´Save on Pump´ to sync the new basal settings";
+
+/* Import Error Headline */
+"Import Error" = "Import Error";
+
 /* */
 "Yes, Import" = "Yes, Import";
 
@@ -339,7 +345,7 @@ Enact a temp Basal or a temp target */
 "Settings imported" = "Settings imported";
 
 /* Import Error */
-"Mismatching glucose units in Nightscout and Pump Settings. Import settings aborted." = "Mismatching glucose units in Nightscout and Pump Settings. Import settings aborted.";
+"\nMismatching glucose units in Nightscout and Pump Settings. Import settings aborted." = "\nMismatching glucose units in Nightscout and Pump Settings. Import settings aborted.";
 
 /* Import Error */
 "Can't find the default Nightscout Profile." = "Can't find the default Nightscout Profile.";

Разница между файлами не показана из-за своего большого размера
+ 10 - 4
FreeAPS/Sources/Localizations/Main/sv.lproj/Localizable.strings


+ 33 - 17
FreeAPS/Sources/Modules/NightscoutConfig/NightscoutConfigStateModel.swift

@@ -143,7 +143,7 @@ extension NightscoutConfig {
                         let fetchedProfileStore = try jsonDecoder.decode([FetchedNightscoutProfileStore].self, from: data)
                         guard let fetchedProfile: ScheduledNightscoutProfile = fetchedProfileStore.first?.store["default"]
                         else {
-                            error = "Can't find the default Nightscout Profile."
+                            error = "\nCan't find the default Nightscout Profile."
                             group.leave()
                             return
                         }
@@ -153,7 +153,7 @@ extension NightscoutConfig {
                                 .nightscout,
                                 "Mismatching glucose units in Nightscout and Pump Settings. Import settings aborted."
                             )
-                            error = "Mismatching glucose units in Nightscout and Pump Settings. Import settings aborted."
+                            error = "\nMismatching glucose units in Nightscout and Pump Settings. Import settings aborted."
                             group.leave()
                             return
                         }
@@ -167,14 +167,23 @@ extension NightscoutConfig {
                                 ) }
                         let carbratiosProfile = CarbRatios(units: CarbUnit.grams, schedule: carbratios)
 
+                        var areBasalsOK = true
                         let basals = fetchedProfile.basal
                             .map { basal -> BasalProfileEntry in
-                                BasalProfileEntry(
+                                if basal.value <= 0 || basal.value >= self.maxBasal {
+                                    error =
+                                        "\nInvalid Nightcsout Basal Settings. \n\nImport aborted. Please check your Nightscout Profile Basal Settings!"
+                                    areBasalsOK = false
+                                }
+                                return BasalProfileEntry(
                                     start: basal.time,
                                     minutes: (basal.timeAsSeconds ?? self.offset(basal.time)) / 60,
                                     rate: basal.value
                                 ) }
-
+                        guard areBasalsOK else {
+                            group.leave()
+                            return
+                        }
                         let sensitivities = fetchedProfile.sens.map { sensitivity -> InsulinSensitivityEntry in
                             InsulinSensitivityEntry(
                                 sensitivity: self.units == .mmolL ? sensitivity.value : sensitivity.value.asMgdL,
@@ -200,7 +209,6 @@ extension NightscoutConfig {
                             userPrefferedUnits: self.units,
                             targets: targets
                         )
-
                         // IS THERE A PUMP?
                         guard let pump = self.apsManager.pumpManager else {
                             self.storage.save(carbratiosProfile, as: OpenAPS.Settings.carbRatios)
@@ -211,13 +219,15 @@ extension NightscoutConfig {
                                 .service,
                                 "Settings were imported but the Basals couldn't be saved to pump (No pump). Check your basal settings and tap ´Save on Pump´ to sync the new basal settings"
                             )
+                            error =
+                                "\nSettings were imported but the Basals couldn't be saved to pump (No pump). Check your basal settings and tap ´Save on Pump´ to sync the new basal settings"
+                            group.leave()
                             return
                         }
                         let syncValues = basals.map {
                             RepeatingScheduleValue(startTime: TimeInterval($0.minutes * 60), value: Double($0.rate))
                         }
-                        // SAVE TO STORAGE
-                        // SAVE TO PUMP (LoopKit)
+                        // SSAVE TO STORAGE. SAVE TO PUMP (LoopKit)
                         pump.syncBasalRateSchedule(items: syncValues) { result in
                             switch result {
                             case .success:
@@ -226,23 +236,29 @@ extension NightscoutConfig {
                                 self.storage.save(sensitivitiesProfile, as: OpenAPS.Settings.insulinSensitivities)
                                 self.storage.save(targetsProfile, as: OpenAPS.Settings.bgTargets)
                                 debug(.service, "Settings have been imported and the Basals saved to pump!")
+                                // DIA. Save if changed.
+                                let dia = fetchedProfile.dia
+                                if dia != self.dia {
+                                    let file = PumpSettings(
+                                        insulinActionCurve: dia,
+                                        maxBolus: self.maxBolus,
+                                        maxBasal: self.maxBasal
+                                    )
+                                    self.storage.save(file, as: OpenAPS.Settings.settings)
+                                    debug(.nightscout, "DIA setting updated to " + dia.description + " after a NS import.")
+                                }
+                                group.leave()
                             case .failure:
                                 error =
-                                    "Settings were imported but the Basals couldn't be saved to pump (communication error). Check your basal settings and tap ´Save on Pump´ to sync the new basal settings"
+                                    "\nSettings were imported but the Basals couldn't be saved to pump (communication error). Check your basal settings and tap ´Save on Pump´ to sync the new basal settings"
                                 debug(.service, "Basals couldn't be save to pump")
+                                group.leave()
                             }
                         }
-
-                        // DIA. Save if changed.
-                        let dia = fetchedProfile.dia
-                        if dia != self.dia {
-                            let file = PumpSettings(insulinActionCurve: dia, maxBolus: self.maxBolus, maxBasal: self.maxBasal)
-                            self.storage.save(file, as: OpenAPS.Settings.settings)
-                            debug(.nightscout, "DIA setting updated to " + dia.description + " after a NS import.")
-                        }
-                        group.leave()
                     } catch let parsingError {
                         print(parsingError)
+                        error = parsingError.localizedDescription
+                        group.leave()
                     }
                 }
             }

+ 1 - 2
FreeAPS/Sources/Modules/NightscoutConfig/View/NightscoutConfigRootView.swift

@@ -92,14 +92,13 @@ extension NightscoutConfig {
 
                     .alert(isPresented: $importedHasRun) {
                         Alert(
-                            title: Text("Settings imported"),
+                            title: Text((fetchedErrors.first?.error ?? "").count < 4 ? "Settings imported" : "Import Error"),
                             message: Text(
                                 (fetchedErrors.first?.error ?? "").count < 4 ?
                                     NSLocalizedString(
                                         "\nNow please verify all of your new settings thoroughly:\n\n* Basal Settings\n * Carb Ratios\n * Glucose Targets\n * Insulin Sensitivities\n\n in iAPS Settings > Configuration.\n\nBad or invalid profile settings could have disatrous effects.",
                                         comment: "Imported Profiles Alert"
                                     ) :
-                                    NSLocalizedString("\nImport failed:\n\n*", comment: "Failed Profile Import Alert") +
                                     NSLocalizedString(fetchedErrors.first?.error ?? "", comment: "Import Error")
                             ),
                             primaryButton: .destructive(