mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-22 17:42:18 +01:00
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
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
_fallback --dry-run --published FILE reads the phone's logs from a JSON list of [device_id, alarm.json] pairs instead of Firebase, morning and evening alike, so the bypass answers (live check C8) can be seen from the CLI without a backend. Refused (exit 2) without --dry-run or for a malformed file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
"""A planted stand-in for ``fetch_firebase_logs()``: ``--published FILE``.
|
|
|
|
Only for ``_fallback --dry-run``: the live check of the bypass ring needs
|
|
``bypass`` / ``dismissed`` events the PC can read, and there is no test
|
|
backend to put them in. The file is a JSON list of ``[device_id, alarm]``
|
|
pairs, the shape ``fetch_firebase_logs()`` returns. ``alarm`` is the
|
|
decrypted ``alarm.json`` -- an object (re-serialised here) or its raw text,
|
|
passed through as-is.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
_PAIR_LEN = 2
|
|
|
|
|
|
def _pair(entry: object) -> tuple[str, str]:
|
|
"""One ``[device_id, alarm]`` entry as ``(device_id, raw_json)``."""
|
|
if not isinstance(entry, list) or len(entry) != _PAIR_LEN:
|
|
msg = f"expected [device_id, alarm], got {entry!r}"
|
|
raise TypeError(msg)
|
|
device, alarm = entry
|
|
if not isinstance(device, str):
|
|
msg = f"device id must be a string, got {device!r}"
|
|
raise TypeError(msg)
|
|
if isinstance(alarm, str):
|
|
return device, alarm
|
|
if isinstance(alarm, dict):
|
|
return device, json.dumps(alarm)
|
|
msg = f"alarm for {device!r} must be an object or its JSON text"
|
|
raise TypeError(msg)
|
|
|
|
|
|
def load_published(path: str) -> list[tuple[str, str]]:
|
|
"""The planted logs; OSError/ValueError/TypeError when the file is unusable."""
|
|
raw = json.loads(Path(path).read_text(encoding="utf-8"))
|
|
if not isinstance(raw, list):
|
|
msg = "expected a JSON list of [device_id, alarm] pairs"
|
|
raise TypeError(msg)
|
|
return [_pair(entry) for entry in raw]
|