Quellcode durchsuchen

Use meal notes
- Add customizable notes from carb shortcut
- And hard coded "⌚️" as note for meal entries made in watch app
- Upload all notes to Nightscout (for visualisation in chart and treatment log)
- TODO: Add notes to LFR remote meals and show them in Trio history view (Datatable) & Upload to NS

dsnallfot vor 1 Jahr
Ursprung
Commit
79dc1dea4e

+ 1 - 0
FreeAPS/Sources/APS/Storage/CarbsStorage.swift

@@ -405,6 +405,7 @@ final class BaseCarbsStorage: CarbsStorage, Injectable {
                     enteredBy: CarbsEntry.manual,
                     bolus: nil,
                     insulin: nil,
+                    notes: result.note,
                     carbs: Decimal(result.carbs),
                     fat: Decimal(result.fat),
                     protein: Decimal(result.protein),

+ 1 - 1
FreeAPS/Sources/Models/CarbsEntry.swift

@@ -33,7 +33,7 @@ extension CarbsEntry {
         case carbs
         case fat
         case protein
-        case note
+        case note = "notes"
         case enteredBy
         case isFPU
         case fpuID

+ 1 - 1
FreeAPS/Sources/Services/WatchManager/WatchManager.swift

@@ -432,7 +432,7 @@ extension BaseWatchManager: WCSessionDelegate {
                         carbs: Decimal(carbs),
                         fat: Decimal(fat),
                         protein: Decimal(protein),
-                        note: nil,
+                        note: message["note"] as? String,
                         enteredBy: CarbsEntry.manual,
                         isFPU: false,
                         fpuID: nil

+ 15 - 2
FreeAPS/Sources/Shortcuts/Carbs/AddCarbPresetIntent.swift

@@ -8,7 +8,7 @@ import Swinject
     static var title: LocalizedStringResource = "Add carbs"
 
     // Description of the action in the Shortcuts app
-    static var description = IntentDescription("Allow to add carbs in iAPS.")
+    static var description = IntentDescription("Allow to add carbs in Trio.")
 
     internal var carbRequest: CarbPresetIntentRequest
 
@@ -45,6 +45,11 @@ import Swinject
     ) var dateAdded: Date
 
     @Parameter(
+        title: "Notering",
+        description: "Emoji or short text"
+    ) var note: String?
+
+    @Parameter(
         title: "Confirm Before applying",
         description: "If toggled, you will need to confirm before applying",
         default: true
@@ -55,12 +60,14 @@ import Swinject
             Summary("Applying \(\.$carbQuantity) at \(\.$dateAdded)") {
                 \.$fatQuantity
                 \.$proteinQuantity
+                \.$note
                 \.$confirmBeforeApplying
             }
         }, otherwise: {
             Summary("Immediately applying \(\.$carbQuantity) at \(\.$dateAdded)") {
                 \.$fatQuantity
                 \.$proteinQuantity
+                \.$note
                 \.$confirmBeforeApplying
             }
         })
@@ -82,7 +89,13 @@ import Swinject
                 )
             }
 
-            let finalQuantityCarbsDisplay = try await carbRequest.addCarbs(quantityCarbs, fatQuantity, proteinQuantity, dateAdded)
+            let finalQuantityCarbsDisplay = try await carbRequest.addCarbs(
+                quantityCarbs,
+                fatQuantity,
+                proteinQuantity,
+                dateAdded,
+                note
+            )
             return .result(
                 dialog: IntentDialog(stringLiteral: finalQuantityCarbsDisplay)
             )

+ 4 - 3
FreeAPS/Sources/Shortcuts/Carbs/CarbPresetIntentRequest.swift

@@ -6,10 +6,11 @@ import Foundation
         _ quantityCarbs: Double,
         _ quantityFat: Double,
         _ quantityProtein: Double,
-        _ dateAdded: Date
+        _ dateAdded: Date,
+        _ note: String?
     ) async throws -> String {
         guard quantityCarbs >= 0.0 || quantityFat >= 0.0 || quantityProtein >= 0.0 else {
-            return "no adding carbs in iAPS"
+            return "not adding carbs in Trio"
         }
 
         let carbs = min(Decimal(quantityCarbs), settingsManager.settings.maxCarbs)
@@ -22,7 +23,7 @@ import Foundation
                 carbs: carbs,
                 fat: Decimal(quantityFat),
                 protein: Decimal(quantityProtein),
-                note: "add with shortcuts",
+                note: note,
                 enteredBy: CarbsEntry.manual,
                 isFPU: false, fpuID: nil
             )],

+ 2 - 1
FreeAPSWatch WatchKit Extension/Views/CarbsView.swift

@@ -221,7 +221,8 @@ struct CarbsView: View {
                 let amountFat = Int(numberFormatter.string(from: fatAmount as NSNumber)!) ?? Int(fatAmount.rounded())
                 let amountProtein = Int(numberFormatter.string(from: proteinAmount as NSNumber)!) ??
                     Int(proteinAmount.rounded())
-                state.addMeal(amountCarbs, fat: amountFat, protein: amountProtein)
+                let note = "⌚️" // Hard-coded note for entries from watch
+                state.addMeal(amountCarbs, fat: amountFat, protein: amountProtein, note: note)
             }
             label: { Text("Save") }
                 .buttonStyle(.borderless)

+ 2 - 2
FreeAPSWatch WatchKit Extension/WatchStateModel.swift

@@ -69,11 +69,11 @@ class WatchStateModel: NSObject, ObservableObject {
         session.activate()
     }
 
-    func addMeal(_ carbs: Int, fat: Int, protein: Int) {
+    func addMeal(_ carbs: Int, fat: Int, protein: Int, note: String) {
         confirmationSuccess = nil
         isConfirmationViewActive = true
         isCarbsViewActive = false
-        session.sendMessage(["carbs": carbs, "fat": fat, "protein": protein], replyHandler: { reply in
+        session.sendMessage(["carbs": carbs, "fat": fat, "protein": protein, "note": note], replyHandler: { reply in
             self.completionHandler(reply)
             if let ok = reply["confirmation"] as? Bool, ok {
                 DispatchQueue.main.asyncAfter(deadline: .now() + 1) {