From 643811885244579311c095d2173c6185b1db900a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Bj=C3=B6rkert?= Date: Sat, 20 Jun 2026 14:55:37 +0200 Subject: [PATCH] Prefer structured ISF/CR from device status over reason string 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. --- .../Controllers/Nightscout/DeviceStatusOpenAPS.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/LoopFollow/Controllers/Nightscout/DeviceStatusOpenAPS.swift b/LoopFollow/Controllers/Nightscout/DeviceStatusOpenAPS.swift index ca8338a47..25031e413 100644 --- a/LoopFollow/Controllers/Nightscout/DeviceStatusOpenAPS.swift +++ b/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