feat(micromate): read the unit's run state and refresh its serial on demand

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
serversdownandClaude Haiku 5.5 committed 2026-10-23 16:20:12 -04:00
1 parent 9ed9578d12
commit 7ff527df07
3 files changed
+69 -3

No files matched your search

+37
View File
@@ -574,3 +574,40 @@ def test_read_unsolicited_sends_nothing_and_returns_what_arrived():
mm, t = client([b"\r\nRADIO RING\r\n"])
assert mm.read_unsolicited() == b"\r\nRADIO RING\r\n"
assert t.written == []
# ── run state (0x49) and a fresh serial ───────────────────────────────────────
import json as _json # noqa: E402
from pathlib import Path # noqa: E402
_WRITES = Path(__file__).parent / "fixtures" / "micromate-writes"
def _captured_0x49():
ex = _json.loads((_WRITES / "monitor-start-stop.json").read_text())["exchanges"]
return [bytes.fromhex(e["response_data"]) for e in ex if e["sub"] == 0x49]
def test_run_state_names_thors_captured_states():
datas = _captured_0x49()
names = []
for d in datas:
mm, _t = client([frame(0xB6, d)])
names.append(mm.read_run_state().name)
assert "idle" in names and "monitoring" in names
@pytest.mark.parametrize("code,name", [(0x00, "idle"), (0x02, "monitoring"),
(0x03, "calling_home"), (0x07, "unknown(0x07)")])
def test_run_state_names_every_value(code, name):
data = bytes(11) + bytes([code]) + bytes(4)
mm, _t = client([frame(0xB6, data)])
st = mm.read_run_state()
assert (st.code, st.name) == (code, name)
def test_serial_refresh_reads_the_unit_again():
mm, t = client([frame(0xEA, bytes(11) + b"UM20147\x00\x00\x00")])
mm._serial = "UM99999" # a stale cached serial
assert mm.serial(refresh=True) == "UM20147"
assert len(t.written) == 1