Skip to content

Add aggressive Nightscout polling after remote commands#566

Draft
bjorkert wants to merge 5 commits intodevfrom
feature/remote-command-polling
Draft

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

Conversation

@bjorkert
Copy link
Copy Markdown
Member

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
Member 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.
@bjorkert
Copy link
Copy Markdown
Member Author

We might want to put this on hold, I am looking into socket communication with Nightscout that will give LF almost real time updates instead of polling, with polling as fallback.

@bjorkert bjorkert marked this pull request as draft April 13, 2026 09:04
marionbarker pushed a commit that referenced this pull request May 3, 2026
* Refactor unit settings management and enhance metrics configuration

- Introduced UnitSettingsStore to centralize unit and metric settings management.
- Added new enums for glucose display units, time in range modes, glycemic metrics, and variability metrics.
- Updated StatsData to calculate and store coefficient of variation.
- Refactored Localizer to utilize UnitSettingsStore for unit conversions and formatting.
- Enhanced Nightscout and Dexcom settings views to support unit configuration and onboarding.
- Created UnitsConfigurationView for reusable unit and metric settings.
- Updated AggregatedStatsView and SimpleStatsViewModel to reflect new unit settings.
- Modified TIRView and its ViewModel to use UnitSettingsStore for thresholds and display.
- Removed legacy storage references for unit settings in favor of the new centralized approach.
- Added export functionality for new unit and metric settings in Nightscout settings.

* Add commit guidelines and best practices to README.md

* Fix navigation title for UnitsSettingsView to match consistency in SettingsMenuView

* Refactor absorption time handling in LoopAPNSCarbsView to use separate hour and minute states, enhancing clarity and usability

* Add polling of data after sucessful remote command

* Remove remote command polling (moved to separate PR #566)

* Replace deprecated NavigationLink(isActive:) with navigationDestination

* Remove carbs screen redesign (moved to separate PR)

* Remove README commit guidelines (moved to separate PR)

* Added custom range

* Remove list_prs.sh from repo

Accidentally committed utility script that belongs outside the project.

* Fix BGPicker not updating display when value changes or unit switches

Use @State for glucoseUnit, lowValue, and highValue so SwiftUI can
track changes and re-render. Add .id(glucoseUnit) on BGPickers to
force recreation when the unit changes, ensuring allValues and
formatting update correctly.

---------

Co-authored-by: Jonas Björkert <jonas@bjorkert.se>
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