Skip to content

fix(sleep): don't show 'awaiting confirmation' for a persisted alarm#120

Merged
abdulsaheel merged 1 commit into
OpenStrap:mainfrom
dannymcc:fix/sleep-alarm-false-pending
Jul 21, 2026
Merged

fix(sleep): don't show 'awaiting confirmation' for a persisted alarm#120
abdulsaheel merged 1 commit into
OpenStrap:mainfrom
dannymcc:fix/sleep-alarm-false-pending

Conversation

@dannymcc

@dannymcc dannymcc commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Problem

On the Sleep tab, the caption under Set band alarm read "Alarm sent, waiting for the strap to confirm." on a fresh open, even when the user never tapped the button this session.

Root cause

The caption fell through to the pending/awaiting text whenever a persisted alarmEpoch existed. That epoch is restored from SharedPreferences on launch (an alarm set in a previous session), but the strap-confirmation state machine (AlarmConfirmation) is session-scoped and records no SET on a cold open. So the fallthrough fired the "awaiting confirmation" caption with no user action.

Fix

Route the caption purely through the session-scoped confirmation flags (alarmConfirmed / alarmPending / alarmUnconfirmed) rather than the persisted epoch. On a fresh launch all three are false, so the caption is idle (nothing shown). The persisted epoch is deliberately no longer an input.

  • Extracts a pure, public alarmStatusCaption({confirmed, pending, unconfirmed}) so the "only speak after an in-session SET" rule is unit-testable.
  • Narrows the context.select tuple to (alarmConfirmed, alarmPending, alarmUnconfirmed) — exactly the fields the caption reads. The grace timer's notifyListeners() flips alarmPending true→false, changing the tuple, so the pending→unconfirmed transition still triggers a rebuild.
  • Adds test/sleep_alarm_caption_test.dart covering the mapping and driving the real AlarmConfirmation transitions (fresh session → no caption; SET → pending → unconfirmed; event 56 → confirmed; disable → idle).

Scope

UI caption only. Does not touch the BLE alarm delivery path (tracked separately as #119).

Closes #118

Summary by CodeRabbit

  • Bug Fixes

    • Improved Sleep Coach alarm status messaging to reflect the current session state.
    • Prevented alarm captions from appearing when no in-session alarm confirmation exists, even if an older alarm record is present.
    • Ensured captions update correctly for pending, confirmed, unconfirmed, and disabled alarm states.
  • Tests

    • Added regression coverage for alarm caption timing, precedence, and clearing behavior.

The Sleep page's alarm caption fell through to 'Alarm sent, waiting for the
strap to confirm.' whenever a persisted alarm epoch existed, so a fresh open
showed the pending status even though the user never tapped 'Set band alarm'
this session.

The strap-confirmation state machine is session-scoped and records no SET on a
fresh launch, so route the caption purely through its confirmed/pending/
unconfirmed flags rather than the persisted epoch. With no in-session send, all
three are false and the caption is idle (nothing shown).

Extract the mapping to a pure, public alarmStatusCaption() and cover it with
regression tests driven by the real AlarmConfirmation transitions.
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2ef0cb79-7ddb-4907-b405-0b6fa5a342ac

📥 Commits

Reviewing files that changed from the base of the PR and between e90a4a3 and dc46697.

📒 Files selected for processing (2)
  • lib/ui/insights/coach_cards.dart
  • test/sleep_alarm_caption_test.dart

📝 Walkthrough

Walkthrough

The Sleep Coach alarm caption now uses session-scoped alarm flags rather than a persisted alarm epoch. Tests cover idle, pending, unconfirmed, confirmed, disabled, and precedence states.

Changes

Alarm caption flow

Layer / File(s) Summary
Session alarm caption state and UI wiring
lib/ui/insights/coach_cards.dart
Adds alarmStatusCaption and updates the Sleep Coach card to derive captions and rebuild from the three session alarm flags.
Caption mapping regression coverage
test/sleep_alarm_caption_test.dart
Tests caption behavior for each alarm state and verifies precedence across overlapping flags.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is specific and matches the main fix: suppressing the alarm confirmation caption for persisted alarms.
Linked Issues check ✅ Passed The caption now depends on session-scoped alarm flags, so a persisted alarm no longer shows the waiting message on fresh open.
Out of Scope Changes check ✅ Passed The changes stay focused on Sleep caption logic and tests, with no unrelated feature work evident.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@abdulsaheel
abdulsaheel merged commit f264eb9 into OpenStrap:main Jul 21, 2026
1 check passed
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.

Sleep page shows "Alarm sent, waiting for the strap to confirm" when no alarm was set

2 participants