فهرست منبع

Prefer structured ISF/CR from device status over reason string (#677)

Ignore a placeholder 0 in the structured ISF field so the info row
falls back to the profile value instead of showing a 0 enacted ISF.
Read the carb ratio from the structured CR field when present, keeping
the reason-string regex only as a fallback for uploaders that don't
expose it.
Jonas Björkert 3 هفته پیش
والد
کامیت
2acd81be16
1فایلهای تغییر یافته به همراه9 افزوده شده و 2 حذف شده
  1. 9 2
      LoopFollow/Controllers/Nightscout/DeviceStatusOpenAPS.swift

+ 9 - 2
LoopFollow/Controllers/Nightscout/DeviceStatusOpenAPS.swift

@@ -32,7 +32,9 @@ extension MainViewController {
             // ISF
             let profileISF = profileManager.currentISF()
             var enactedISF: HKQuantity?
-            if let enactedISFValue = enactedOrSuggested["ISF"] as? Double {
+            // Some uploaders (e.g. Trio Swift oref with dynamic ISF) report a
+            // placeholder 0 in the structured ISF field; treat that as missing.
+            if let enactedISFValue = enactedOrSuggested["ISF"] as? Double, enactedISFValue != 0 {
                 enactedISF = HKQuantity(unit: .milligramsPerDeciliter, doubleValue: enactedISFValue)
             }
             if let profileISF = profileISF, let enactedISF = enactedISF, profileISF != enactedISF {
@@ -44,9 +46,14 @@ extension MainViewController {
             }
 
             // Carb Ratio (CR)
+            // Prefer the structured CR field; fall back to parsing it out of the
+            // reason string for uploaders that don't expose it (a CR of 0 is never
+            // valid, so it's treated as missing).
             let profileCR = profileManager.currentCarbRatio()
             var enactedCR: Double?
-            if let reasonString = enactedOrSuggested["reason"] as? String {
+            if let structuredCR = enactedOrSuggested["CR"] as? Double, structuredCR != 0 {
+                enactedCR = structuredCR
+            } else if let reasonString = enactedOrSuggested["reason"] as? String {
                 let pattern = "CR: (\\d+(?:\\.\\d+)?)"
                 if let regex = try? NSRegularExpression(pattern: pattern) {
                     let nsString = reasonString as NSString