Quellcode durchsuchen

Do not enact a meal's explicit bolus when the meal is rejected

The `.meal` dispatch called `handleMealCommand` and then, independently,
enacted the payload's explicit bolus whenever `bolusAmount` was set — even
if the meal had been rejected during validation (for example, carbs over
the maximum). That could dose insulin for a meal that was never stored.

Move the explicit-bolus decision into `handleMealCommand`, after the carbs
are stored, so the bolus is only enacted once the meal itself succeeds.
Justin Maier vor 2 Wochen
Ursprung
Commit
38956a3df9

+ 9 - 6
Trio/Sources/Services/RemoteControl/TrioRemoteControl+Meal.swift

@@ -68,12 +68,15 @@ extension TrioRemoteControl {
 
         try await carbsStorage.storeCarbs([mealEntry], areFetchedFromRemote: false)
 
-        if payload.bolusAmount == nil {
-            await logSuccess(
-                "Remote command processed successfully. \(payload.humanReadableDescription())",
-                payload: payload,
-                customNotificationMessage: "Meal logged"
-            )
+        if payload.bolusAmount != nil {
+            try await handleBolusCommand(payload)
+            return
         }
+
+        await logSuccess(
+            "Remote command processed successfully. \(payload.humanReadableDescription())",
+            payload: payload,
+            customNotificationMessage: "Meal logged"
+        )
     }
 }

+ 0 - 3
Trio/Sources/Services/RemoteControl/TrioRemoteControl.swift

@@ -80,9 +80,6 @@ class TrioRemoteControl: Injectable {
             await cancelTempTarget(commandPayload)
         case .meal:
             try await handleMealCommand(commandPayload)
-            if commandPayload.bolusAmount != nil {
-                try await handleBolusCommand(commandPayload)
-            }
         case .startOverride:
             await handleStartOverrideCommand(commandPayload)
         case .cancelOverride: