mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-28 01:09:17 +01:00
Skip focus-owner when ranking the alarm
Some checks failed
md-naming / markdown naming convention (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,free-days-interop,dependency-freshness) (push) Has been cancelled
Tests / test (push) Has been cancelled
Tests / free-days-interop (push) Has been cancelled
repo-contract / repo contract (push) Has been cancelled
Some checks failed
md-naming / markdown naming convention (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,free-days-interop,dependency-freshness) (push) Has been cancelled
Tests / test (push) Has been cancelled
Tests / free-days-interop (push) Has been cancelled
repo-contract / repo contract (push) Has been cancelled
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
|
import logging
|
||||||
from typing import Any
|
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__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -188,6 +194,10 @@ def newest_alarm(
|
|||||||
"""
|
"""
|
||||||
ranked: list[tuple[str, str, tuple[int, int]]] = []
|
ranked: list[tuple[str, str, tuple[int, int]]] = []
|
||||||
for device_id, raw in published:
|
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)
|
parsed = parse_log(raw)
|
||||||
if parsed is None:
|
if parsed is None:
|
||||||
_logger.info("Ignoring unusable alarm published by %r", device_id)
|
_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:
|
def test_an_unparsable_prefix_is_undated(self) -> None:
|
||||||
"""Garbage before the Z must not raise out of a per-minute tick."""
|
"""Garbage before the Z must not raise out of a per-minute tick."""
|
||||||
assert hlc_instant("not-a-timestampZ-0000-device") is None
|
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