Просмотр исходного кода

Merge pull request #682 from MikePlante1/cage

Change .nsSiteChange trigger to .replaceComponent(...) instead of .prime
Deniz Cengiz недель назад: 2
Родитель
Сommit
b56036bca5

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

@@ -58,6 +58,7 @@ public extension PumpEventStored {
         case rewind = "Rewind"
         case rewind = "Rewind"
         case prime = "Prime"
         case prime = "Prime"
         case journalCarbs = "JournalEntryMealMarker"
         case journalCarbs = "JournalEntryMealMarker"
+        case siteChange = "SiteChange"
 
 
         case nsNote = "Note"
         case nsNote = "Note"
         case nsTempBasal = "Temp Basal"
         case nsTempBasal = "Temp Basal"

+ 16 - 1
Trio/Sources/APS/Storage/PumpHistoryStorage.swift

@@ -205,6 +205,21 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
                     newPumpEvent.isUploadedToTidepool = false
                     newPumpEvent.isUploadedToTidepool = false
                     newPumpEvent.note = event.title
                     newPumpEvent.note = event.title
 
 
+                case .replaceComponent(componentType: .infusionSet),
+                     .replaceComponent(componentType: .pump):
+                    guard existingEvents.isEmpty else {
+                        // Duplicate found, do not store the event
+                        debug(.coreData, "Duplicate event found with timestamp: \(event.date)")
+                        continue
+                    }
+                    let newPumpEvent = PumpEventStored(context: self.context)
+                    newPumpEvent.id = UUID().uuidString
+                    newPumpEvent.timestamp = event.date
+                    newPumpEvent.type = PumpEvent.siteChange.rawValue
+                    newPumpEvent.isUploadedToNS = false
+                    newPumpEvent.isUploadedToHealth = false
+                    newPumpEvent.isUploadedToTidepool = false
+
                 default:
                 default:
                     continue
                     continue
                 }
                 }
@@ -418,7 +433,7 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
                         targetTop: nil,
                         targetTop: nil,
                         targetBottom: nil
                         targetBottom: nil
                     )
                     )
-                case PumpEvent.prime.rawValue:
+                case PumpEvent.siteChange.rawValue:
                     return NightscoutTreatment(
                     return NightscoutTreatment(
                         duration: nil,
                         duration: nil,
                         rawDuration: nil,
                         rawDuration: nil,

+ 0 - 31
Trio/Sources/Services/Network/Nightscout/NightscoutManager.swift

@@ -582,10 +582,6 @@ final class BaseNightscoutManager: NightscoutManager, Injectable {
         } catch {
         } catch {
             debug(.nightscout, String(describing: error))
             debug(.nightscout, String(describing: error))
         }
         }
-
-        Task.detached {
-            await self.uploadPodAge()
-        }
     }
     }
 
 
     private func updateOrefDeterminationAsUploaded(_ determination: [Determination]) async {
     private func updateOrefDeterminationAsUploaded(_ determination: [Determination]) async {
@@ -610,33 +606,6 @@ final class BaseNightscoutManager: NightscoutManager, Injectable {
         }
         }
     }
     }
 
 
-    func uploadPodAge() async {
-        let uploadedPodAge = storage.retrieve(OpenAPS.Nightscout.uploadedPodAge, as: [NightscoutTreatment].self) ?? []
-        if let podAge = storage.retrieve(OpenAPS.Monitor.podAge, as: Date.self),
-           uploadedPodAge.last?.createdAt == nil || podAge != uploadedPodAge.last!.createdAt!
-        {
-            let siteTreatment = NightscoutTreatment(
-                duration: nil,
-                rawDuration: nil,
-                rawRate: nil,
-                absolute: nil,
-                rate: nil,
-                eventType: .nsSiteChange,
-                createdAt: podAge,
-                enteredBy: NightscoutTreatment.local,
-                bolus: nil,
-                insulin: nil,
-                notes: nil,
-                carbs: nil,
-                fat: nil,
-                protein: nil,
-                targetTop: nil,
-                targetBottom: nil
-            )
-            await uploadNonCoreDataTreatments([siteTreatment])
-        }
-    }
-
     func uploadProfiles() async throws {
     func uploadProfiles() async throws {
         if isUploadEnabled {
         if isUploadEnabled {
             do {
             do {