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

+24 -3
View File
@@ -40,7 +40,13 @@ from typing import Optional
from minimateplus.transport import BaseTransport
from .models import MicromateDeviceInfo, MicromateEventRef, MicromateSetup, MicromateState
from .models import (
MicromateDeviceInfo,
MicromateEventRef,
MicromateRunState,
MicromateSetup,
MicromateState,
)
from .protocol import MicromateProtocol, ProtocolError
from .setup_block import decode_setup
@@ -365,16 +371,31 @@ class MicromateClient:
# ── Events ────────────────────────────────────────────────────────────────
def serial(self) -> str:
def serial(self, *, refresh: bool = False) -> str:
"""The unit's serial, cached from `connect()` or read on demand.
Needed by anything that handles an event, because an event key is
ambiguous without it — see `MicromateEventRef`.
`refresh=True` forces a fresh `0x15` read. A change operation passes it
right before writing, so the identity check never runs against a serial
cached from an earlier call-up (a modem may have moved to another unit).
"""
if self._serial is None:
if refresh or self._serial is None:
self._serial = _cstring(_content(self._proto.read_serial()))
return self._serial
_RUN_STATES = {0x00: "idle", 0x02: "monitoring", 0x03: "calling_home"}
def read_run_state(self) -> MicromateRunState:
"""`SUB 0x49` -> the unit's run state, with the in-call-home value kept
(connect()'s `monitoring` bool flattens 0x03 into True)."""
c = _content(self._proto.read_state())
if not c:
raise ProtocolError("0x49 state reply has no content")
code = c[_STATE_FLAG]
return MicromateRunState(code, self._RUN_STATES.get(code, f"unknown(0x{code:02X})"))
def list_events(self, *, with_records: bool = True) -> list[MicromateEventRef]:
"""Walk the event chain. `0x93 → 1E`, then `0x93 → 1F` until the sentinel.