fix: update event count retrieval logic in AchSession and MiniMateClient

This commit is contained in:
2026-04-13 18:46:23 -04:00
parent e5ea17388a
commit 27db663579
2 changed files with 38 additions and 28 deletions
+15 -2
View File
@@ -181,8 +181,21 @@ class MiniMateClient:
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)
# NOTE: _decode_event_count reads data[10:12] from the SUB 08 payload,
# which was believed to be the stored event count. Empirically it turns
# out to be a monotonically-increasing "total events ever recorded" counter
# that does NOT decrement when events are erased — confirmed 2026-04-13:
# device reported 6 via SUB 08 while list_event_keys() returned 0 (empty).
# We preserve the raw read here for the index data but do NOT use this
# count for logic; ach_server uses list_event_keys() as the authoritative
# source instead.
_raw_idx_count = _decode_event_count(idx_raw)
log.info(
"connect: SUB 08 index count=%d (lifetime counter, not current storage)",
_raw_idx_count,
)
# Leave device_info.event_count as None — callers should use
# list_event_keys() to get the actual current event count.
except ProtocolError as exc:
log.warning("connect: event index read failed: %s — continuing", exc)