From 8f99351a2a16fa7875429c6639ddf8225b65ef56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Bj=C3=B6rkert?= Date: Fri, 24 Jul 2026 22:39:46 +0200 Subject: [PATCH] Clear stored predBGs when clearing the OpenAPS forecast Switching from a Trio site to a Loop site left the old Trio forecast on the chart. The flip detection in updateDeviceStatusDisplay cleared the drawn lines and the cone, but the device observer fires right after and calls updateOpenAPSPredictionDisplay, which redrew the forecast from the stored predBGs. Those are only cleared when an openaps record without predBGs arrives, which never happens on a Loop site, so the stale lines stayed until the app was restarted. Clearing the stored predBGs together with the drawn data stops the forecast from coming back. The Loop to Trio direction was already working. --- LoopFollow/Charts/BGChartStubs.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/LoopFollow/Charts/BGChartStubs.swift b/LoopFollow/Charts/BGChartStubs.swift index fef4823c0..ba8714a82 100644 --- a/LoopFollow/Charts/BGChartStubs.swift +++ b/LoopFollow/Charts/BGChartStubs.swift @@ -87,9 +87,13 @@ extension MainViewController { } // Removes the Trio/OpenAPS forecast (ZT/IOB/COB/UAM lines and the cone). Used when the active system switches away from Trio/OpenAPS. + // Also drops the stored predBGs: the device observer calls updateOpenAPSPredictionDisplay after this runs, + // and would otherwise redraw the cleared forecast from them. func clearOpenAPSPredictionGraph() { let hasLineData = !ztPredictionData.isEmpty || !iobPredictionData.isEmpty || !cobPredictionData.isEmpty || !uamPredictionData.isEmpty - guard hasLineData || !chartModel.cone.isEmpty else { return } + guard hasLineData || !chartModel.cone.isEmpty || openAPSPredBGs != nil else { return } + openAPSPredBGs = nil + openAPSPredUpdatedTime = nil ztPredictionData = [] iobPredictionData = [] cobPredictionData = []