mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-23 16:06:31 +01:00
Skip focus-owner when ranking the alarm
Some checks are pending
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,free-days-interop,dependency-freshness) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / free-days-interop (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Some checks are pending
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,free-days-interop,dependency-freshness) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / free-days-interop (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Its log holds only bypass events; parsing it warned on every fetch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
10625bd29f
commit
af503f465f
@ -21,7 +21,13 @@ import json
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from wake_alarm._constants import MAX_HOUR, MAX_MINUTE, MIN_HOUR, MIN_MINUTE
|
||||
from wake_alarm._constants import (
|
||||
FOCUS_OWNER_DEVICE_ID,
|
||||
MAX_HOUR,
|
||||
MAX_MINUTE,
|
||||
MIN_HOUR,
|
||||
MIN_MINUTE,
|
||||
)
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@ -188,6 +194,10 @@ def newest_alarm(
|
||||
"""
|
||||
ranked: list[tuple[str, str, tuple[int, int]]] = []
|
||||
for device_id, raw in published:
|
||||
# focus-owner publishes only its bypass events, never an alarm; parsing
|
||||
# it would log a WARNING on every live fetch.
|
||||
if device_id == FOCUS_OWNER_DEVICE_ID:
|
||||
continue
|
||||
parsed = parse_log(raw)
|
||||
if parsed is None:
|
||||
_logger.info("Ignoring unusable alarm published by %r", device_id)
|
||||
|
||||
@ -215,3 +215,19 @@ class TestHlcInstant:
|
||||
def test_an_unparsable_prefix_is_undated(self) -> None:
|
||||
"""Garbage before the Z must not raise out of a per-minute tick."""
|
||||
assert hlc_instant("not-a-timestampZ-0000-device") is None
|
||||
|
||||
|
||||
def test_newest_alarm_skips_focus_owner_without_a_warning(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""focus-owner's log never carries an alarm; reading it is not a fault."""
|
||||
hlc = "2026-11-23T06:00:00.000Z-0000-p"
|
||||
phone = json.dumps(
|
||||
{"alarm": {"fields": {"alarm_hour": [7, hlc], "alarm_minute": [30, hlc]}}}
|
||||
)
|
||||
owner = json.dumps({"alarm": {"fields": {"phone_events": [[], hlc]}}})
|
||||
with caplog.at_level("INFO"):
|
||||
result = newest_alarm([("focus-owner", owner), ("p", phone)])
|
||||
assert result is not None
|
||||
assert result[:2] == (7, 30)
|
||||
assert not [r for r in caplog.records if r.levelname == "WARNING"]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user