Browse Source

Shortcut boluses work, one bug with insulinReq guard

- Bolusing via shortcuts now works
- The guard for max bolus works
- Added extra logic so that when insulinReq is selected for guard, a second check to make sure the bolus does not exceed the max bolus setting
- TODO: bug remains with grabbing the required insulin for use in the guardrail  (see critical todo on line 7 of BolusIntentRequest.swift)
- @dnzxy started helping me with this but I did not get it to work yet
Auggie Fisher 1 year ago
parent
commit
35e8609329
1 changed files with 19 additions and 2 deletions
  1. 19 2
      FreeAPS/Sources/Shortcuts/Bolus/BolusIntentRequest.swift

+ 19 - 2
FreeAPS/Sources/Shortcuts/Bolus/BolusIntentRequest.swift

@@ -4,7 +4,7 @@ import Foundation
 
 @available(iOS 16.0,*) final class BolusIntentRequest: BaseIntentsRequest {
     private var suggestion: Determination? {
-        //TODO: CRITICAL
+        // TODO: CRITICAL
         /// This MUST update to use the latest determination's insulinRequired from Core Data
         fileStorage.retrieve(OpenAPS.Enact.suggested, as: Determination.self)
     }
@@ -30,8 +30,25 @@ import Foundation
                 bolusQuantity = apsManager.roundBolus(amount: Decimal(bolusAmount))
             }
 
-        // Block any bolus attempted if it is larger than the max bolus in settings
+        // Block any bolus attempted if it is larger than the insulin recommended
         case .limitInsulinSuggestion:
+            /*
+             case .limitInsulinSuggestion:
+                 let lastDetermination = await CoreDataStack.shared.fetchEntitiesAsync(
+                     ofType: OrefDetermination.self,
+                     onContext: coredataContext,
+                     predicate: NSPredicate.predicateFor30MinAgoForDetermination,
+                     key: "deliveryAt", ascending: false,
+                     fetchLimit: 1
+                 )
+                 guard let latest = lastDetermination.first else {
+                     return LocalizedStringResource(
+                         "Error retrieving suggested insulin amount guardrail.",
+                         table: "ShortcutsDetail"
+                     )
+                 }
+                 let insulinSuggestion = latest.insulinForManualBolus ?? 0
+             */
             let insulinSuggestion = suggestion?.insulinForManualBolus ?? 0
             if Decimal(bolusAmount) > insulinSuggestion {
                 return LocalizedStringResource(