Skip to content

Add aggressive Nightscout polling after remote commands#566

Open
bjorkert wants to merge 4 commits intodevfrom
feature/remote-command-polling
Open

Add aggressive Nightscout polling after remote commands#566
bjorkert wants to merge 4 commits intodevfrom
feature/remote-command-polling

Conversation

@bjorkert
Copy link
Copy Markdown
Contributor

Summary

  • After a remote command (bolus, carbs, override, temp target) succeeds, poll Nightscout every 3s for up to 30s so the result appears on the main screen quickly
  • Polling stops early once fresh data matching the command type is detected
  • All remote command paths (Loop APNS, TRC, Trio Nightscout) post a remoteCommandSucceeded notification on success

Extracted from #558 to keep that PR focused on units/metrics.

After a remote command (bolus, carbs, override, temp target) succeeds,
poll Nightscout every 3 seconds for up to 30 seconds to quickly reflect
the command on the main screen. Polling stops early when fresh data
matching the command type is detected.
@bjorkert
Copy link
Copy Markdown
Contributor Author

Instead of starting to poll when the command is sent, I think we should start when we get confirmation that Loop/Trio received and acted on it, there can be a delay between those two points. We should in that case post remoteCommandSucceeded from userNotificationCenter(_:willPresent:).

This also naturally limits polling to when the app is in the foreground — if the user has already left the app, polling isn't needed.

This would also let us remove all the individual NotificationCenter.default.post(name: .remoteCommandSucceeded) calls from the remote command views, simplifying the code.

The only incoming notifications are confirmation and failure notifications, we can improve this in the future, classifying them somehow, but even if we start poll on a fail we would show the gray dot faster.

Should we do evaluateRemoteCommandPollingCompletion in devicestatus? All commands are treatments, should not that be enough?

codebymini and others added 3 commits March 29, 2026 21:06
Replace the parallel Timer with a .remoteCommandPoll TaskScheduler task
so the aggressive post-remote-command polling runs through the same
scheduler as every other recurring fetch. The tick reschedules
.deviceStatus and .treatments to fire immediately, then reschedules
itself for the next interval. Parked at .distantFuture when the window
closes (timeout or fresh data detected).

Drop .fetchBG from the polled set: no remote command produces a BG
entry, and the completion signature doesn't look at bgData, so the
fetch was dead weight during the window.
Resolve conflict in AppDelegate.swift: keep the
logRemoteCommandNotificationDetails helper from this branch
which supersedes the inline command_status/command_type logging
added to dev.
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.

2 participants