Skip focus-owner in the phone's last push

focus-owner publishes bypass:uninstalled when WakeAlarm is gone; its
write must not count as the phone uploading.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Krzysztof Rudnicki 2026-11-23 12:07:36 +01:00
parent 0059d44571
commit 4e946483f5
3 changed files with 18 additions and 2 deletions

View File

@ -76,6 +76,10 @@ SYNC_LEGACY_PREFIX: str = "wake-alarm-sync/devices"
# lists. Copied over from the plaintext prefix like everything else.
SYNC_ALARM_PATH: str = f"{SYNC_DEVICES_PREFIX}/phone/alarm.json"
# focus-owner's own device directory. It publishes ``bypass`` with cause
# ``uninstalled`` when WakeAlarm is gone, so it is never the phone's push.
FOCUS_OWNER_DEVICE_ID: str = "focus-owner"
# The file each device publishes its alarm as, inside its own directory.
SYNC_ALARM_FILENAME: str = "alarm.json"

View File

@ -25,6 +25,7 @@ from wake_alarm._constants import (
ESCAPE_HATCH_LAST_DAY,
ESCAPE_REASON_MIN_CHARS,
ESCAPES_FIELD,
FOCUS_OWNER_DEVICE_ID,
PHONE_EVENTS_FIELD,
RING_STARTED_FIELD,
STICK_STATE_FIELD,
@ -204,10 +205,13 @@ def newest_push(logs: list[tuple[str, dict[str, Any]]]) -> float | None:
Every phone write stamps the field it changed, so the largest instant is
when the phone last uploaded anything. A stamp that cannot be dated is
skipped: None means "cannot tell", never "old".
skipped: None means "cannot tell", never "old". focus-owner's writes are
not the phone's: it publishes exactly when WakeAlarm is uninstalled.
"""
stamps: list[float] = []
for _, log in logs:
for device_id, log in logs:
if device_id == FOCUS_OWNER_DEVICE_ID:
continue
record = log.get("alarm")
fields = record.get("fields") if isinstance(record, dict) else None
for name in fields if isinstance(fields, dict) else ():

View File

@ -102,3 +102,11 @@ def test_last_push_is_the_newest_dated_hlc_of_any_field_on_any_device() -> None:
def test_last_push_is_none_without_a_dated_stamp() -> None:
assert enforcement_view([("a", _log(alarm_hour=(7, "h")))]).last_push is None
assert enforcement_view([]).last_push is None
def test_last_push_ignores_focus_owner_writes() -> None:
"""focus-owner publishes ``bypass:uninstalled``; that is not a phone push."""
phone = _log(alarm_hour=(7, "2026-11-20T06:00:00.000Z-0000-p"))
owner = _log(phone_events=([], "2026-11-23T09:00:00.000Z-0000-f"))
view = enforcement_view([("p", phone), ("focus-owner", owner)])
assert view.last_push == datetime(2026, 11, 20, 6, 0, tzinfo=UTC).timestamp()