Add aggressive Nightscout polling after remote commands#566
Add aggressive Nightscout polling after remote commands#566
Conversation
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.
|
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? |
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.
Summary
remoteCommandSucceedednotification on successExtracted from #558 to keep that PR focused on units/metrics.