fix(sfm): wake a MiniMate before the read-back reconnect reads its serial (#9 review)

The reconnect in ce441a0 opened a fresh connection and sent a bare 0x15 (the
identity check) before any SESSION_RESET + POLL.  It exists for a unit that has
just started -- sensor check, then monitoring -- and a monitoring MiniMate
ignores a bare request until woken (measured 2026-04-08), so the identity read
would have timed out and the start reported unconfirmed anyway.  Now: open,
wake (the same retried wake the read-back uses), read the serial, read 0x1C --
the order the status read and the legacy write routes use.  Still one
reconnect, TCP only, nothing re-sent.

The fake gains bare_requests_ignored (off unless a test asks): a fresh
connection's reads time out, with the real client's TimeoutError, until woken.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
serversdownandClaude Opus 5.5 committed 2026-10-29 23:56:44 -04:00
1 parent 1626e521ae
commit dbd8a91661
3 files changed
+41 -4

No files matched your search

+23 -3
View File
@@ -18,6 +18,9 @@ SETUP_FIXTURE = Path(__file__).parent / "fixtures" / "micromate-setup" / "um2014
THOR_IDF = Path(__file__).parent / "fixtures" / "thor-idf"
from minimateplus.protocol import TimeoutError as mmp_TimeoutError # noqa: E402
class _Base:
def __init__(self, fail=None, open_error=None):
self.fail = list(fail or [])
@@ -75,9 +78,14 @@ def default_s3_events():
class FakeMiniMateClient(_Base):
def __init__(self, serial="BE18193", *, monitoring=False, compliance="default", events=None,
monitor_states=None, write_error=None, serial_reported=None, wake_errors=None, **kw):
monitor_states=None, write_error=None, serial_reported=None, wake_errors=None,
bare_requests_ignored=False, **kw):
super().__init__(**kw)
self.serial = serial
# As a monitoring MiniMate (measured 2026-04-08): on a fresh connection a
# read before SESSION_RESET + POLL goes unanswered. Off unless a test asks.
self.bare_requests_ignored = bare_requests_ignored
self._woken = False
# read_serial()'s answer (connect() keeps answering `serial`), and errors
# raised by wake() once a write has gone out -- the read-back's wakes.
self.serial_reported = serial if serial_reported is None else serial_reported
@@ -98,8 +106,18 @@ class FakeMiniMateClient(_Base):
self.download_requests: list = [] # (key4, expected_timestamp) per download
self.last_download = None
def open(self):
super().open()
self._woken = False
def _bare_read(self, name):
self._step(name)
if self.bare_requests_ignored and not self._woken:
raise mmp_TimeoutError(f"{name}: no reply (the unit was not woken)")
def connect(self) -> DeviceInfo:
self._step("connect")
self._woken = True # connect() starts with the startup handshake
return DeviceInfo(
serial=self.serial, firmware_minor=17, firmware_version="S338.17",
dsp_version="10.72", manufacturer="Instantel", model="MiniMate Plus",
@@ -108,18 +126,20 @@ class FakeMiniMateClient(_Base):
def poll(self) -> None:
self._step("poll")
self._woken = True
def wake(self, **kw) -> None:
self._step("wake")
if self.writes and self.wake_errors:
raise self.wake_errors.pop(0)
self._woken = True
def read_serial(self) -> str:
self._step("read_serial")
self._bare_read("read_serial")
return self.serial_reported
def get_monitor_status(self) -> MonitorStatus:
self._step("get_monitor_status")
self._bare_read("get_monitor_status")
state = self.monitor_states.pop(0) if len(self.monitor_states) > 1 else self.monitor_states[0]
# A bool is a measured state; an int (or None: a short section) is the raw 0x1C flag byte.
flag = (0x10 if state else 0x00) if isinstance(state, bool) else state