Skip to content

Commit 600ca4c

Browse files
authored
Format Rec. Bolus with the pump's bolus increment (#700)
* Format Loop's recommended bolus with InsulinMetric The Loop device status parser formatted Rec. Bolus with a hardcoded String(format: "%.2fU"), while the OpenAPS/Trio parser routed the value through InsulinMetric. The same recommendation rendered as "0.00U" on a Loop URL and "0" on a Trio URL. Use InsulinMetric on both paths. * Format Rec. Bolus with the pump's bolus increment Rec. Bolus was formatted two different ways: the Loop parser used a hardcoded String(format: "%.2fU"), while the OpenAPS/Trio parser went through InsulinMetric, which drops to one fraction digit below 10 U. The same recommendation rendered as "0.00U" on a Loop URL and "0" on a Trio URL. Both parsers now use InsulinFormatter, which derives its fraction digits from the pump's reported bolusIncrement, so the value is shown at the precision the pump can actually deliver. The unit suffix is dropped to match the other insulin rows in the info table. Clear the info row and deviceRecBolus when the device status carries no recommendation, so a stale value can't linger in the info table, the Rec. Bolus alarm condition, or the Live Activity.
1 parent 070f79a commit 600ca4c

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

LoopFollow/Controllers/Nightscout/DeviceStatusLoop.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ extension MainViewController {
101101
updatePredictionGraph()
102102
}
103103
if let recBolus = lastLoopRecord["recommendedBolus"] as? Double {
104-
let formattedRecBolus = String(format: "%.2fU", recBolus)
105-
infoManager.updateInfoData(type: .recBolus, value: formattedRecBolus)
104+
infoManager.updateInfoData(type: .recBolus, value: InsulinFormatter.shared.string(recBolus))
106105
Observable.shared.deviceRecBolus.value = recBolus
106+
} else {
107+
infoManager.clearInfoData(type: .recBolus)
108+
Observable.shared.deviceRecBolus.value = nil
107109
}
108110
if let loopStatus = lastLoopRecord["recommendedTempBasal"] as? [String: AnyObject] {
109111
if let tempBasalTime = formatter.date(from: (loopStatus["timestamp"] as! String))?.timeIntervalSince1970 {

LoopFollow/Controllers/Nightscout/DeviceStatusOpenAPS.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,11 @@ extension MainViewController {
114114
}
115115

116116
// Recommended Bolus
117-
if let rec = InsulinMetric(from: lastLoopRecord, key: "recommendedBolus") {
118-
infoManager.updateInfoData(type: .recBolus, value: rec)
119-
Observable.shared.deviceRecBolus.value = rec.value
117+
if let rec = lastLoopRecord["recommendedBolus"] as? Double {
118+
infoManager.updateInfoData(type: .recBolus, value: InsulinFormatter.shared.string(rec))
119+
Observable.shared.deviceRecBolus.value = rec
120120
} else {
121+
infoManager.clearInfoData(type: .recBolus)
121122
Observable.shared.deviceRecBolus.value = nil
122123
}
123124

0 commit comments

Comments
 (0)