فهرست منبع

Fixes for Nightscout uploads
* Cancelled bolus correctly uploads and updates initially uploaded dose
* Pump resume and pump suspend events upload as note event type and are drawn in chart

Deniz Cengiz 1 سال پیش
والد
کامیت
75685548ec

+ 3 - 4
FreeAPS/Sources/APS/Storage/PumpHistoryStorage.swift

@@ -71,6 +71,7 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
                                         // Update existing event with new smaller value
                                         existingEvent.bolus?.amount = amount as NSDecimalNumber
                                         existingEvent.bolus?.isSMB = dose.automatic ?? true
+                                        existingEvent.isUploadedToNS = false
 
                                         print("Updated existing event with smaller value: \(amount)")
                                     }
@@ -306,7 +307,6 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
                         targetBottom: nil,
                         id: event.id
                     )
-                // TODO: should we really upload pumpSuspend as announcement ?!
                 case PumpEvent.pumpSuspend.rawValue:
                     return NightscoutTreatment(
                         duration: nil,
@@ -314,7 +314,7 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
                         rawRate: nil,
                         absolute: nil,
                         rate: nil,
-                        eventType: .nsAnnouncement,
+                        eventType: .nsNote,
                         createdAt: event.timestamp,
                         enteredBy: NightscoutTreatment.local,
                         bolus: nil,
@@ -326,7 +326,6 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
                         targetTop: nil,
                         targetBottom: nil
                     )
-                // TODO: should we really upload pumpResume as announcement ?!
                 case PumpEvent.pumpResume.rawValue:
                     return NightscoutTreatment(
                         duration: nil,
@@ -334,7 +333,7 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
                         rawRate: nil,
                         absolute: nil,
                         rate: nil,
-                        eventType: .nsAnnouncement,
+                        eventType: .nsNote,
                         createdAt: event.timestamp,
                         enteredBy: NightscoutTreatment.local,
                         bolus: nil,

+ 6 - 1
FreeAPS/Sources/Services/Network/NightscoutManager.swift

@@ -1012,7 +1012,12 @@ extension BaseNightscoutManager {
     ///
     /// its done on a background thread and after that the UI gets updated on the main thread
     @objc private func contextDidSave(_ notification: Notification) {
-        guard let userInfo = notification.userInfo else { return }
+        guard let userInfo = notification.userInfo else {
+            print("No userInfo in notification")
+            return
+        }
+
+        print("Notification userInfo: \(userInfo)")
 
         Task { [weak self] in
             await self?.processUpdates(userInfo: userInfo)

+ 1 - 0
Model/Helper/PumpEvent+helper.swift

@@ -33,6 +33,7 @@ public extension PumpEventStored {
         case prime = "Prime"
         case journalCarbs = "JournalEntryMealMarker"
 
+        case nsNote = "Note"
         case nsTempBasal = "Temp Basal"
         case nsCarbCorrection = "Carb Correction"
         case nsTempTarget = "Temporary Target"