From 6eecd0c1d1483789b6d462eea13f9666ab8549bb Mon Sep 17 00:00:00 2001 From: Brian Harrison Date: Thu, 2 Apr 2026 02:00:37 -0400 Subject: [PATCH] client/models/server: wire event_count from SUB 08 event index into connect() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DeviceInfo.event_count: Optional[int] = None (new field in models.py) - connect() now calls proto.read_event_index() after compliance config and stores the decoded count in device_info.event_count - _serialise_device_info() exposes event_count in /device/info and /device/events JSON responses event_count is decoded from uint32 BE at offset +3 of the 88-byte F7 payload (🔶 inferred — needs live device confirmation against a multi-event device). Any ProtocolError from the index read is caught and logged; event_count stays None rather than failing the whole connect(). Co-Authored-By: Claude Sonnet 4.6 --- minimateplus/client.py | 11 ++++++++++- minimateplus/models.py | 3 +++ sfm/server.py | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/minimateplus/client.py b/minimateplus/client.py index 9941bee..de61826 100644 --- a/minimateplus/client.py +++ b/minimateplus/client.py @@ -121,9 +121,10 @@ class MiniMateClient: 2. SUB 15 — serial number 3. SUB 01 — full config block (firmware, model strings) 4. SUB 1A — compliance config (record time, trigger/alarm levels, project strings) + 5. SUB 08 — event index (stored event count) Returns: - Populated DeviceInfo with compliance_config cached. + Populated DeviceInfo with compliance_config and event_count cached. Raises: ProtocolError: on any communication failure. @@ -151,6 +152,14 @@ class MiniMateClient: except ProtocolError as exc: log.warning("connect: compliance config read failed: %s — continuing", exc) + log.info("connect: reading event index (SUB 08)") + try: + idx_raw = proto.read_event_index() + device_info.event_count = _decode_event_count(idx_raw) + log.info("connect: device has %d stored event(s)", device_info.event_count) + except ProtocolError as exc: + log.warning("connect: event index read failed: %s — continuing", exc) + log.info("connect: %s", device_info) return device_info diff --git a/minimateplus/models.py b/minimateplus/models.py index 036310a..182a424 100644 --- a/minimateplus/models.py +++ b/minimateplus/models.py @@ -183,6 +183,9 @@ class DeviceInfo: # ── From SUB 1A (COMPLIANCE_CONFIG_RESPONSE) ────────────────────────────── compliance_config: Optional["ComplianceConfig"] = None # E5 response, read in connect() + # ── From SUB 08 (EVENT_INDEX_RESPONSE) ──────────────────────────────────── + event_count: Optional[int] = None # stored event count from F7 response 🔶 + def __str__(self) -> str: fw = self.firmware_version or f"?.{self.firmware_minor}" mdl = self.model or "MiniMate Plus" diff --git a/sfm/server.py b/sfm/server.py index 47ab414..09a43d0 100644 --- a/sfm/server.py +++ b/sfm/server.py @@ -145,6 +145,7 @@ def _serialise_device_info(info: DeviceInfo) -> dict: "dsp_version": info.dsp_version, "manufacturer": info.manufacturer, "model": info.model, + "event_count": info.event_count, "compliance_config": _serialise_compliance_config(info.compliance_config), }