Преглед изворни кода

Clear stored predBGs when clearing the OpenAPS forecast (#724)

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.
Jonas Björkert пре 5 дана
родитељ
комит
f128d24c70
1 измењених фајлова са 5 додато и 1 уклоњено
  1. 5 1
      LoopFollow/Charts/BGChartStubs.swift

+ 5 - 1
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 = []