wake-alarm/wake_alarm/_ring_probe.py
Krzysztof kuhy Rudnicki cf0d243ffd Count a paused alarm as a bypass
The launcher "Wstrzymaj aplikację" paused WakeAlarm mid-ring on 11-20 and
11-22. WakeAlarm is now a device admin, and a pause, admin removal,
revoked notifications or full-screen intent, or a killed ring on a live
morning is a bypass: a miss on any weekday, the phone rings again, and
the PC rings at once until a newer dismiss or 30 min.

The PC rings also go to every connected monitor, since the speakers are
off at the knob overnight; a one-shot silent probe checks them at A-5.

DOCS-bypass.md has the layers, causes and measurements.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 11:49:44 +01:00

45 lines
1.8 KiB
Python

"""The silent monitor probe: once, at A - 5, on a morning with no session.
On 2026-11-22 the fallback rang 30 minutes into the analog speakers, which
kuhy switches off at the knob for the night, so nothing was heard. The ring
now plays to every connected monitor too (``scripts/pc/ring_alsa.sh``).
Whether a monitor really takes the stream with no graphical session can be
known only in that state, and kuhy asked for no test sound, so this starts
``wake-alarm-ring-probe.service`` once: digital silence into each monitor,
one ``ring_probe`` journal line per sink. The first real fallback morning's
``ring_sink`` lines are the follow-up check.
"""
from __future__ import annotations
from datetime import timedelta
from typing import TYPE_CHECKING
from wake_alarm._constants import LOG_STATE_DIR
from wake_alarm._events import emit
from wake_alarm._ring_player import _ok, graphical_session
if TYPE_CHECKING:
from datetime import datetime
PROBE_UNIT = "wake-alarm-ring-probe.service"
PROBE_DONE_FILE = LOG_STATE_DIR / "ring_probe_done"
PROBE_LEAD = timedelta(minutes=5)
def maybe_probe(now: datetime, alarm_at: datetime) -> str | None:
"""Start the probe if it is due; what happened, or None when not due."""
if PROBE_DONE_FILE.exists() or not alarm_at - PROBE_LEAD <= now < alarm_at:
return None
graphical, why = graphical_session()
if graphical:
# Not the state a fallback ring meets; try again tomorrow.
return "waiting_for_no_session"
started, out = _ok(["sudo", "-n", "systemctl", "start", PROBE_UNIT])
emit("ring_probe", "started" if started else "failed", session=why, output=out)
if not started:
return "failed"
PROBE_DONE_FILE.parent.mkdir(parents=True, exist_ok=True)
PROBE_DONE_FILE.write_text(now.isoformat(), encoding="utf-8")
return "started"