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

Merge branch 'core-data-sync-trio' of github.com:dnzxy/Trio-dev into editTreatmentEntries

Deniz Cengiz 1 год назад
Родитель
Сommit
a479719618

+ 71 - 2
FreeAPS/Sources/Models/BloodGlucose.swift

@@ -2,7 +2,7 @@ import Foundation
 import HealthKit
 import LoopKit
 
-struct BloodGlucose: JSON, Identifiable, Hashable {
+struct BloodGlucose: JSON, Identifiable, Hashable, Codable {
     enum Direction: String, JSON {
         case tripleUp = "TripleUp"
         case doubleUp = "DoubleUp"
@@ -59,6 +59,76 @@ struct BloodGlucose: JSON, Identifiable, Hashable {
         }
     }
 
+    enum CodingKeys: String, CodingKey {
+        case _id
+        case sgv
+        case direction
+        case date
+        case dateString
+        case unfiltered
+        case filtered
+        case noise
+        case glucose
+        case type
+        case activationDate
+        case sessionStartDate
+        case transmitterID
+    }
+
+    init(from decoder: Decoder) throws {
+        let container = try decoder.container(keyedBy: CodingKeys.self)
+        _id = try container.decode(String.self, forKey: ._id)
+
+        do {
+            sgv = try container.decode(Int.self, forKey: .sgv)
+        } catch {
+            // The nightscout API returns a double instead of an int
+            sgv = Int(try container.decode(Double.self, forKey: .sgv))
+        }
+
+        direction = try container.decodeIfPresent(Direction.self, forKey: .direction)
+        date = try container.decode(Decimal.self, forKey: .date)
+        dateString = try container.decode(Date.self, forKey: .dateString)
+        unfiltered = try container.decodeIfPresent(Decimal.self, forKey: .unfiltered)
+        filtered = try container.decodeIfPresent(Decimal.self, forKey: .filtered)
+        noise = try container.decodeIfPresent(Int.self, forKey: .noise)
+        glucose = try container.decodeIfPresent(Int.self, forKey: .glucose)
+        type = try container.decodeIfPresent(String.self, forKey: .type)
+        activationDate = try container.decodeIfPresent(Date.self, forKey: .activationDate)
+        sessionStartDate = try container.decodeIfPresent(Date.self, forKey: .sessionStartDate)
+        transmitterID = try container.decodeIfPresent(String.self, forKey: .transmitterID)
+    }
+
+    init(
+        _id: String = UUID().uuidString,
+        sgv: Int? = nil,
+        direction: Direction? = nil,
+        date: Decimal,
+        dateString: Date,
+        unfiltered: Decimal? = nil,
+        filtered: Decimal? = nil,
+        noise: Int? = nil,
+        glucose: Int? = nil,
+        type: String? = nil,
+        activationDate: Date? = nil,
+        sessionStartDate: Date? = nil,
+        transmitterID: String? = nil
+    ) {
+        self._id = _id
+        self.sgv = sgv
+        self.direction = direction
+        self.date = date
+        self.dateString = dateString
+        self.unfiltered = unfiltered
+        self.filtered = filtered
+        self.noise = noise
+        self.glucose = glucose
+        self.type = type
+        self.activationDate = activationDate
+        self.sessionStartDate = sessionStartDate
+        self.transmitterID = transmitterID
+    }
+
     var _id: String?
     var id: String {
         _id ?? UUID().uuidString
@@ -76,7 +146,6 @@ struct BloodGlucose: JSON, Identifiable, Hashable {
     var activationDate: Date? = nil
     var sessionStartDate: Date? = nil
     var transmitterID: String? = nil
-
     var isStateValid: Bool { sgv ?? 0 >= 39 && noise ?? 1 != 4 }
 
     static func == (lhs: BloodGlucose, rhs: BloodGlucose) -> Bool {

+ 9 - 5
FreeAPS/Sources/Modules/Adjustments/AdjustmentsStateModel+Extensions/AdjustmentsStateModel+Overrides.swift

@@ -187,11 +187,15 @@ extension Adjustments.StateModel {
     /// Then unpack it on the view context and update the State variables which can be used on in the View for some Logic
     /// This also needs to be called when we cancel an Override via the Home View to update the State of the Button for this case
     func updateLatestOverrideConfiguration() {
-        Task {
-            let id = await overrideStorage.loadLatestOverrideConfigurations(fetchLimit: 1)
-            async let updateState: () = updateLatestOverrideConfigurationOfState(from: id)
-            async let setOverride: () = setCurrentOverride(from: id)
-            _ = await (updateState, setOverride)
+        Task { [weak self] in
+            guard let self = self else { return }
+            
+            let id = await self.overrideStorage.loadLatestOverrideConfigurations(fetchLimit: 1)
+            
+            // execute sequentially instead of concurrently
+            await self.updateLatestOverrideConfigurationOfState(from: id)
+            await self.setCurrentOverride(from: id)
+            
         }
     }
 

+ 5 - 2
FreeAPS/Sources/Modules/Home/HomeStateModel+Setup/GlucoseTargetSetup.swift

@@ -20,7 +20,7 @@ extension Home.StateModel {
 
         // Ensure there are targets to process
         guard !rawTargets.targets.isEmpty else {
-            print("Warning: No targets to process in rawTargets.")
+            debugPrint("\(DebuggingIdentifiers.failed) Warning: No targets to process in rawTargets.")
             return []
         }
 
@@ -37,7 +37,7 @@ extension Home.StateModel {
 
             // Validate target index to ensure safety
             guard targetIndex < targets.count else {
-                print("Error: Invalid target index \(targetIndex).")
+                debugPrint("\(DebuggingIdentifiers.failed) Error: Invalid target index \(targetIndex).")
                 continue
             }
 
@@ -78,6 +78,9 @@ extension Home.StateModel {
             )
         }
 
+        //TODO: - remove this after bug is fixed
+        debugPrint("\(DebuggingIdentifiers.inProgress) printing target profiles: \(targetProfiles)")
+        
         return targetProfiles
     }
 }

+ 7 - 1
FreeAPS/Sources/Modules/NightscoutConfig/NightscoutConfigStateModel.swift

@@ -20,6 +20,7 @@ extension NightscoutConfig {
         @Published var url = ""
         @Published var secret = ""
         @Published var message = ""
+        @Published var isValidURL: Bool = false
         @Published var connecting = false
         @Published var backfilling = false
         @Published var isUploadEnabled = false // Allow uploads
@@ -88,12 +89,17 @@ extension NightscoutConfig {
                 let fixedURL = url.dropLast()
                 url = String(fixedURL)
             }
-            guard let url = URL(string: url) else {
+            
+            guard let url = URL(string: url), self.url.hasPrefix("https://") else {
                 message = "Invalid URL"
+                isValidURL = false
                 return
             }
+            
             connecting = true
+            isValidURL = true
             message = ""
+            
             provider.checkConnection(url: url, secret: secret.isEmpty ? nil : secret)
                 .receive(on: DispatchQueue.main)
                 .sink { completion in

+ 12 - 6
FreeAPS/Sources/Modules/NightscoutConfig/View/NightscoutConnectView.swift

@@ -19,17 +19,23 @@ struct NightscoutConnectView: View {
             Section(
                 header: Text("Connect to Nightscout"),
                 content: {
-                    TextField("URL", text: $state.url)
-                        .disableAutocorrection(true)
-                        .textContentType(.URL)
-                        .autocapitalization(.none)
-                        .keyboardType(.URL)
+                    HStack {
+                        TextField("URL", text: $state.url)
+                            .disableAutocorrection(true)
+                            .textContentType(.URL)
+                            .autocapitalization(.none)
+                            .keyboardType(.URL)
+                        if state.message.isNotEmpty && !state.isValidURL {
+                            Image(systemName: "exclamationmark.triangle.fill")
+                                .foregroundStyle(.orange)
+                        }
+                    }
                     SecureField("API secret", text: $state.secret)
                         .disableAutocorrection(true)
                         .autocapitalization(.none)
                         .textContentType(.password)
                         .keyboardType(.asciiCapable)
-                    if !state.message.isEmpty {
+                    if state.message.isNotEmpty {
                         Text(state.message)
                     }
                     if state.connecting {

+ 17 - 15
FreeAPS/Sources/Modules/PumpConfig/View/PumpConfigRootView.swift

@@ -115,21 +115,23 @@ extension PumpConfig {
                 } message: { Text("Select Pump Model") }
             }
             .sheet(isPresented: $state.setupPump) {
-                if let pumpManager = state.provider.apsManager.pumpManager {
-                    PumpSettingsView(
-                        pumpManager: pumpManager,
-                        bluetoothManager: state.provider.apsManager.bluetoothManager!,
-                        completionDelegate: state,
-                        setupDelegate: state
-                    )
-                } else {
-                    PumpSetupView(
-                        pumpType: state.setupPumpType,
-                        pumpInitialSettings: state.initialSettings,
-                        bluetoothManager: state.provider.apsManager.bluetoothManager!,
-                        completionDelegate: state,
-                        setupDelegate: state
-                    )
+                NavigationView {
+                    if let pumpManager = state.provider.apsManager.pumpManager {
+                        PumpSettingsView(
+                            pumpManager: pumpManager,
+                            bluetoothManager: state.provider.apsManager.bluetoothManager!,
+                            completionDelegate: state,
+                            setupDelegate: state
+                        )
+                    } else {
+                        PumpSetupView(
+                            pumpType: state.setupPumpType,
+                            pumpInitialSettings: state.initialSettings,
+                            bluetoothManager: state.provider.apsManager.bluetoothManager!,
+                            completionDelegate: state,
+                            setupDelegate: state
+                        )
+                    }
                 }
             }
         }

+ 6 - 1
FreeAPS/Sources/Modules/PumpConfig/View/PumpSetupView.swift

@@ -87,7 +87,12 @@ extension PumpConfig {
             case let .createdAndOnboarded(pumpManagerUI):
                 debug(.default, "Pump manager  created and onboarded")
                 setupDelegate?.pumpManagerOnboarding(didCreatePumpManager: pumpManagerUI)
-                return UIViewController()
+                var vc = pumpManagerUI.settingsViewController(
+                    bluetoothProvider: bluetoothManager,
+                    pumpManagerOnboardingDelegate: setupDelegate
+                )
+                vc.completionDelegate = completionDelegate
+                return vc
             }
         }
 

+ 1 - 1
FreeAPS/Sources/Modules/UserInterfaceSettings/View/UserInterfaceSettingsRootView.swift

@@ -413,7 +413,7 @@ extension UserInterfaceSettings {
                                                 VStack(alignment: .leading, spacing: 5) {
                                                     Text("Total Insulin in Scope:").bold()
                                                     Text(
-                                                        "Displays the total insulin administered since midnight, both basal and bolus."
+                                                        "Displays the total amount of insulin given as a bolus (manual or SMB) and through temporary basal rates above zero during the selected timeframe of the main chart."
                                                     )
                                                 }
                                             }

+ 1 - 1
OmniBLE

@@ -1 +1 @@
-Subproject commit fee22b34644a6c349db92b55ce835114c377e4d7
+Subproject commit 1fa2874419225c8c7af0d9afbd9faf823cda34e5

+ 1 - 1
OmniKit

@@ -1 +1 @@
-Subproject commit 0857ad8d71d4d588ff7f5470e78fe8d6b5055924
+Subproject commit 48a35efa52f42e0b72fe2e984f60d4482a11a75f