|
|
@@ -66,6 +66,7 @@ extension MainViewController {
|
|
|
// NS Device Status Response Processor
|
|
|
func updateDeviceStatusDisplay(jsonDeviceStatus: [[String: AnyObject]]) {
|
|
|
let previousIOBText = Observable.shared.iobText.value
|
|
|
+ let previousDeviceWasLoop = Storage.shared.device.value == "Loop"
|
|
|
infoManager.clearInfoData(types: [.iob, .cob, .battery, .pump, .pumpBattery, .target, .isf, .carbRatio, .updated, .recBolus, .tdd])
|
|
|
|
|
|
// For Loop, clear the current override here - For Trio, it is handled using treatments
|
|
|
@@ -155,6 +156,17 @@ extension MainViewController {
|
|
|
|
|
|
// Loop - handle new data
|
|
|
if let lastLoopRecord = lastDeviceStatus?["loop"] as! [String: AnyObject]? {
|
|
|
+ // Some pumps report no `pump.clock`; without it alertLastLoopTime stays 0
|
|
|
+ // and the forecast anchors to epoch 0. Fall back to the loop cycle timestamp.
|
|
|
+ if (lastDeviceStatus?["pump"] as? [String: AnyObject])?["clock"] == nil,
|
|
|
+ let loopTimestampString = lastLoopRecord["timestamp"] as? String,
|
|
|
+ let loopTimestamp = formatter.date(from: loopTimestampString)?.timeIntervalSince1970,
|
|
|
+ loopTimestamp > (Observable.shared.alertLastLoopTime.value ?? 0)
|
|
|
+ {
|
|
|
+ Observable.shared.alertLastLoopTime.value = loopTimestamp
|
|
|
+ Storage.shared.lastLoopTime.value = loopTimestamp
|
|
|
+ }
|
|
|
+
|
|
|
DeviceStatusLoop(formatter: formatter, lastLoopRecord: lastLoopRecord)
|
|
|
|
|
|
var oText = ""
|
|
|
@@ -188,6 +200,17 @@ extension MainViewController {
|
|
|
DeviceStatusOpenAPS(formatter: formatter, lastDeviceStatus: lastDeviceStatus, lastLoopRecord: lastLoopRecord)
|
|
|
}
|
|
|
|
|
|
+ // If the active looping system flipped (Loop ⇄ Trio/OpenAPS), drop the previous
|
|
|
+ // system's forecast so it doesn't linger next to the one just drawn above.
|
|
|
+ let currentDeviceIsLoop = Storage.shared.device.value == "Loop"
|
|
|
+ if currentDeviceIsLoop != previousDeviceWasLoop {
|
|
|
+ if currentDeviceIsLoop {
|
|
|
+ clearOpenAPSPredictionGraph()
|
|
|
+ } else {
|
|
|
+ clearLoopPredictionGraph()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// Start the timer based on the timestamp
|
|
|
let now = dateTimeUtils.getNowTimeIntervalUTC()
|
|
|
let secondsAgo = now - (Observable.shared.alertLastLoopTime.value ?? 0)
|