Explorar el Código

Add tdd to devicestatus

Jonas Björkert hace 1 año
padre
commit
e2223fe675

+ 4 - 0
Trio/Sources/Models/Determination.swift

@@ -19,7 +19,11 @@ struct Determination: JSON, Equatable {
     let reservoir: Decimal?
     var isf: Decimal?
     var timestamp: Date?
+
+    /// `tdd` (Total Daily Dose) is included so it can be part of the
+    /// enacted and suggested devicestatus data that gets uploaded to Nightscout.
     var tdd: Decimal?
+    
     var current_target: Decimal?
     let insulinForManualBolus: Decimal?
     let manualBolusErrorString: Decimal?

+ 8 - 2
Trio/Sources/Services/Network/Nightscout/NightscoutManager.swift

@@ -1476,8 +1476,14 @@ extension BaseNightscoutManager {
 }
 
 extension BaseNightscoutManager {
-    /// Injects TDD into the reason string
-    func injectTDD(into reason: String, tdd: Decimal?) -> String {
+    /// Injects TDD into the provided `reason` string if TDD is available.
+    ///
+    /// - Parameters:
+    ///   - reason: The raw reason string (e.g., "minPredBG=5.2, IOBpredBG=6.1").
+    ///   - tdd: The total daily dose of insulin.
+    /// - Returns: A modified reason string that includes "TDD: x U" appended
+    ///   after the last matched prediction term, or at the end if no match is found.
+        func injectTDD(into reason: String, tdd: Decimal?) -> String {
         guard let tdd = tdd else {
             return reason
         }