Skip to content

Only clear the forecast when the data source changes#707

Merged
marionbarker merged 3 commits into
devfrom
fix/forecast-clear-on-device-switch
Jul 17, 2026
Merged

Only clear the forecast when the data source changes#707
marionbarker merged 3 commits into
devfrom
fix/forecast-clear-on-device-switch

Conversation

@bjorkert

@bjorkert bjorkert commented Jul 16, 2026

Copy link
Copy Markdown
Member

The refresh handler cleared the Loop and Trio forecasts on every refresh, including every websocket disconnect. On Loop that made the forecast vanish and only reappear on the next loop cycle, so on some instances it looked like it never came back.

The clearing now only happens when the active system actually changes. When a device status flips between Loop and Trio the previous system's forecast is dropped, and when Nightscout is turned off so there is no device status source, such as Dexcom only, both forecasts are cleared. Normal refreshes and websocket reconnects no longer touch the forecast.

Also rebuilds the Loop forecast whenever it is empty, not only when the loop cycle advances, so it is restored on the next device-status poll regardless of cycle timing.

For pumps that report no pump.clock, the loop time now falls back to the loop cycle timestamp. Without it the loop time stayed 0, so the forecast anchored to epoch 0 and stretched the graph across decades.

The refresh handler used to wipe the Loop and Trio forecasts on every refresh, including every websocket disconnect, which made the Loop forecast disappear and only come back on the next loop cycle. Move the clearing so it only happens when the active system actually changes: when a device status flips between Loop and Trio, and when Nightscout is turned off so there is no device status source at all, such as Dexcom only.
codebymini
codebymini previously approved these changes Jul 17, 2026

@codebymini codebymini left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
Approve by code review and test.

The forecast was only rebuilt when the loop cycle advanced (previousLastLoopTime < lastLoopTime), so any time the prediction was cleared within the same cycle it stayed blank until the next loop cycle. Also rebuild when predictionData is empty, so the forecast is restored on the next device-status poll regardless of cycle timing.
A pump that omits pump.clock (e.g. some Omnipod configurations) left alertLastLoopTime at 0, so the Loop forecast anchored to epoch 0 and stretched the graph across decades. Use the loop cycle timestamp as the loop time when no pump clock is present, so the forecast anchors correctly and refreshes each cycle.

@marionbarker marionbarker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve from code review and test with Loop URL from next-dev and Trio URL

Thanks

@marionbarker
marionbarker merged commit 290e020 into dev Jul 17, 2026
1 of 2 checks passed
@marionbarker
marionbarker deleted the fix/forecast-clear-on-device-switch branch July 17, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants