Skip to content

Add Future Carbs Alert#571

Merged
marionbarker merged 6 commits intodevfrom
feature/future-carbs-alert
Mar 29, 2026
Merged

Add Future Carbs Alert#571
marionbarker merged 6 commits intodevfrom
feature/future-carbs-alert

Conversation

@bjorkert
Copy link
Copy Markdown
Contributor

@bjorkert bjorkert commented Mar 22, 2026

Summary

  • Add a new alarm type that fires once when a future-dated carb entry's scheduled time arrives, reminding the user to start eating
  • Fix Nightscout treatment download query excluding future-dated entries
  • Default the alarm to acknowledge mode since it self-silences when the carb is no longer in the future
  • Add 10 unit tests for FutureCarbsCondition covering tracking, firing, deletion, lookahead bounds, min grams, stale cleanup, multi-carb behavior, and duplicate prevention

Notify when a future-dated carb entry's scheduled time arrives, serving
as a reminder to start eating in pre-bolus scenarios. Tracks future carb
entries across alarm ticks using persistent storage, with configurable
max lookahead window (default 45 min) to filter out fat/protein entries
and minimum carb threshold (default 5g).
10 test cases covering tracking, firing, deletion, lookahead bounds,
min grams filter, past carbs, stale cleanup, multi-carb per-tick
behavior, and duplicate prevention. Also fix Tests target missing
FRAMEWORK_SEARCH_PATHS for CocoaPods dependencies and add missing
latestPumpBattery field in withBattery test helper.
Trio sets created_at to the scheduled future time, but the Nightscout
query had an upper bound of "now", excluding any future-dated entries.
Extend the query window by predictionToLoad minutes so treatments
within the graph lookahead are fetched. Also add addingMinutes
parameter to getDateTimeString for precise minute-level offsets.
@bjorkert bjorkert self-assigned this Mar 22, 2026
Replace the prediction-based lookahead with a fixed 6-hour window and
rename currentTimeString to endTimeString for clarity.
@marionbarker
Copy link
Copy Markdown
Collaborator

Test

I did a quick test and it worked. I have not had time for code review.

@marionbarker
Copy link
Copy Markdown
Collaborator

Code review

Looks good

Test

Previous test I entered carbs 15 minutes ahead and set the alarm. I got an alert which I acknowledged.

This time, modify max look ahead to 10 minutes.
Add future carbs that are 15 minutes in the future; which means I should not be alerted

  • ✅ I see the 10 g on the LoopFollow display in the future
  • ❌ wait 15 minutes - I should not be alerted because it is outside the window but I was alerted
  • ❌ repeated the test and it happened again

(One entry was direct on the phone. One was from a remote carb entry set 15 min in the future.)

Carbs originally outside the lookahead window could drift into it over
time and fire incorrectly. Now all future carbs are tracked from first
observation, and only fire if their original distance (carbDate minus
observedAt) was within the max lookahead. Stale cleanup also preserves
entries whose carb still exists to prevent re-observation with a fresh
timestamp.
@bjorkert
Copy link
Copy Markdown
Contributor Author

Thanks for testing and catching this, code updated to avoid this issue.

@marionbarker
Copy link
Copy Markdown
Collaborator

Test

Updated to commit 21e65f8.

Repeat test of future carbs of 10 g in 15 min.
The alarm is set to ignore future carbs > 10 minutes in the future.

Wait 15 minutes plus a few.

✅ I can see the future carbs in the LoopFollow plot
✅ No alert was given (as desired).

More testing soon.

@marionbarker
Copy link
Copy Markdown
Collaborator

Test

✅ successful test
❓ The future carb warning seems to be lacking in details of how many carbs. But maybe that's as designed.

Still using to commit 21e65f8.

Set ignore future carbs > 15 minutes in future
Set ignore carb amounts < 3 g (alert for 3 g or above)

  • Do not expect an alert: Add future carbs for 10 min in the future, 2 g
    • Time entered: 20:14
    • Carb in future time: 20:24
    • ✅ No alert by 20:26
  • Expect an alert: Add future carbs for 10 min in the future, 3 g
    • Time entered: 20:27
    • Carb in future time: 20:37
    • ✅ alert at 8:38 - see screenshot below
  • Do not expect an alert: Add future carbs for 20 min in the future, 7 g
    • Time entered: 20:28
    • Carb in future time: 20:48
    • ✅ No alert by 20:50

Screenshot

IMG_8882

@bjorkert
Copy link
Copy Markdown
Contributor Author

Thanks for the thorough testing!

Regarding the carb amount not showing in the notification. All alarms share the same notification format: the title is the alarm name (which can be customized by the user), and the subtitle always shows the current BG, direction, and delta. Adding treatment-specific details would be a new pattern. We can revisit this if there's enough demand, but I suggest we keep it consistent for now.

@marionbarker marionbarker merged commit 97d30e9 into dev Mar 29, 2026
@marionbarker marionbarker deleted the feature/future-carbs-alert branch March 29, 2026 14:18
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.

Feature request: notification for arrival of carbs entered as future carbs

2 participants