ソースを参照

Respectg Max Bolus setting when adding insulin.
Diable buttons when over Max Bolus.
Use Max Bolus also for adding insulin wihout bolusing

(cherry picked from commit cbeb5a08db0061a0518a9a3c6037300e0aa346d6)

Jon Mårtensson 2 年 前
コミット
581e3e2838

+ 3 - 0
FreeAPS/Sources/Localizations/Main/en.lproj/Localizable.strings

@@ -962,6 +962,9 @@ Enact a temp Basal or a temp target */
 /* */
 /* */
 "Bolus failed" = "Bolus failed";
 "Bolus failed" = "Bolus failed";
 
 
+/* "Max Bolus Exceeded label" */
+"Max Bolus exceeded!" = "Max Bolus exceeded!";
+
 /* */
 /* */
 "Bolus failed or inaccurate. Check pump history before repeating." = "Bolus failed or inaccurate. Check pump history before repeating.";
 "Bolus failed or inaccurate. Check pump history before repeating." = "Bolus failed or inaccurate. Check pump history before repeating.";
 
 

+ 3 - 0
FreeAPS/Sources/Localizations/Main/sv.lproj/Localizable.strings

@@ -962,6 +962,9 @@ Enact a temp Basal or a temp target */
 /* */
 /* */
 "Bolus failed or inaccurate. Check pump history before repeating." = "Misslyckad eller felaktig bolus. Kontrollera pumpens historik innan du försöker igen.";
 "Bolus failed or inaccurate. Check pump history before repeating." = "Misslyckad eller felaktig bolus. Kontrollera pumpens historik innan du försöker igen.";
 
 
+/* "Max Bolus Exceeded label" */
+"Max Bolus exceeded!" = "Du kan inte ge mer än din maxinställning!";
+
 /* */
 /* */
 "Carbs" = "Kolhydrater";
 "Carbs" = "Kolhydrater";
 
 

+ 4 - 1
FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift

@@ -25,6 +25,7 @@ extension Bolus {
         @Published var expectedDelta: Decimal = 0
         @Published var expectedDelta: Decimal = 0
         @Published var minPredBG: Decimal = 0
         @Published var minPredBG: Decimal = 0
         @Published var units: GlucoseUnits = .mmolL
         @Published var units: GlucoseUnits = .mmolL
+        @Published var maxBolus: Decimal = 0
 
 
         var waitForSuggestionInitial: Bool = false
         var waitForSuggestionInitial: Bool = false
 
 
@@ -34,6 +35,7 @@ extension Bolus {
             units = settingsManager.settings.units
             units = settingsManager.settings.units
             percentage = settingsManager.settings.insulinReqPercentage
             percentage = settingsManager.settings.insulinReqPercentage
             threshold = provider.suggestion?.threshold ?? 0
             threshold = provider.suggestion?.threshold ?? 0
+            maxBolus = provider.pumpSettings().maxBolus
 
 
             if waitForSuggestionInitial {
             if waitForSuggestionInitial {
                 apsManager.determineBasal()
                 apsManager.determineBasal()
@@ -55,7 +57,7 @@ extension Bolus {
                 return
                 return
             }
             }
 
 
-            let maxAmount = Double(min(amount, provider.pumpSettings().maxBolus))
+            let maxAmount = Double(min(amount, maxBolus))
 
 
             unlockmanager.unlock()
             unlockmanager.unlock()
                 .sink { _ in } receiveValue: { [weak self] _ in
                 .sink { _ in } receiveValue: { [weak self] _ in
@@ -71,6 +73,7 @@ extension Bolus {
                 showModal(for: nil)
                 showModal(for: nil)
                 return
                 return
             }
             }
+            amount = min(amount, maxBolus)
 
 
             pumpHistoryStorage.storeEvents(
             pumpHistoryStorage.storeEvents(
                 [
                 [

+ 7 - 3
FreeAPS/Sources/Modules/Bolus/View/BolusRootView.swift

@@ -78,8 +78,10 @@ extension Bolus {
                     header: { Text("Bolus") }
                     header: { Text("Bolus") }
                     Section {
                     Section {
                         Button { state.add() }
                         Button { state.add() }
-                        label: { Text("Enact bolus") }
-                            .disabled(state.amount <= 0)
+                        label: { Text(!(state.amount > state.maxBolus) ? "Enact bolus" : "Max Bolus exceeded!") }
+                            .disabled(
+                                state.amount <= 0 || state.amount > state.maxBolus
+                            )
                     }
                     }
                     Section {
                     Section {
                         if waitForSuggestion {
                         if waitForSuggestion {
@@ -88,7 +90,9 @@ extension Bolus {
                         } else {
                         } else {
                             Button { isAddInsulinAlertPresented = true }
                             Button { isAddInsulinAlertPresented = true }
                             label: { Text("Add insulin without actually bolusing") }
                             label: { Text("Add insulin without actually bolusing") }
-                                .disabled(state.amount <= 0)
+                                .disabled(
+                                    state.amount <= 0 || state.amount > state.maxBolus
+                                )
                         }
                         }
                     }
                     }
                     .alert(isPresented: $isAddInsulinAlertPresented) {
                     .alert(isPresented: $isAddInsulinAlertPresented) {