wake-alarm/phone_app
Krzysztof kuhy Rudnicki 03392e7ea5 Discover alarm device directories instead of reading a fixed phone path
The PC read one hardcoded path, wake-alarm-sync/devices/phone/alarm.json,
and never parsed the HLC. The phone's device id is migrating from the fixed
constant "phone" to a per-install uuid (a role constant collides as soon as
a second install takes the same role, and a reinstall inherits the previous
install's CRDT identity). A reader pinned to the old path would have stopped
seeing the alarm the moment the phone migrated, fallen through to the cache
and then to FALLBACK_ALARM_HOUR -- i.e. woken at the wrong time, silently.

So the PC half ships first, and this commit is that half plus the phone
change it makes safe:

- _fetch_firebase_alarm() lists SYNC_DEVICES_PREFIX, reads every device's
  alarm.json, and picks the newest by the hour field's HLC rather than by
  listing order. device_id breaks an exact tie so two devices stamped in the
  same millisecond don't alternate between ticks; a device whose payload
  doesn't parse is skipped rather than allowed to win with a bad value.
- SYNC_ALARM_PATH stays as a last-resort read for a backend that lists
  nothing, so an un-migrated install keeps working. The GitHub mirror still
  reads the single fixed path.
- The phone persists a uuid under SharedPreferences 'crdt.nodeId' (the key
  todo and home_inventory already use) and pushes under it. deviceId is now
  an instance field, injectable so tests don't touch real prefs.

Parsing and ranking moved to _alarm_payload.py: _sync.py was over the repo's
500-line cap, and the wire format deserves testing without network or disk --
a misparse here doesn't raise, it just resolves to the wrong wake-up time.

Verified against the live RTDB, not just mocks: seeded a uuid-named device
directory and confirmed the reader discovered it, read it and ranked it --
losing to the phone with an old stamp, winning with a new one (03:15 vs the
real 07:45). Test device deleted; --show returns 07:45 and the cache is
intact.

354 tests, 100% branch coverage. Phone app: 10 tests, analyzer clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZH89WEqAjuJT8WZdqc7AP
2026-08-09 17:06:43 +02:00
..
android Build and publish a signed APK on every push to main 2026-08-04 20:55:04 +02:00
assets/icon Bump gatelock pin to released v0.1.1, regenerate launcher icon 2026-07-21 21:18:02 +02:00
lib Discover alarm device directories instead of reading a fixed phone path 2026-08-09 17:06:43 +02:00
test Discover alarm device directories instead of reading a fixed phone path 2026-08-09 17:06:43 +02:00
.gitignore Add wake_alarm_sync phone-side Flutter companion app 2026-07-10 23:16:11 +02:00
.metadata Add wake_alarm_sync phone-side Flutter companion app 2026-07-10 23:16:11 +02:00
analysis_options.yaml Add wake_alarm_sync phone-side Flutter companion app 2026-07-10 23:16:11 +02:00
pubspec.lock Discover alarm device directories instead of reading a fixed phone path 2026-08-09 17:06:43 +02:00
pubspec.yaml Discover alarm device directories instead of reading a fixed phone path 2026-08-09 17:06:43 +02:00
README.md Add wake_alarm_sync phone-side Flutter companion app 2026-07-10 23:16:11 +02:00

wake_alarm_sync

A new Flutter project.

Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter development, view the online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.