feat: Implement poll() method for efficient device communication and update monitoring status retrieval

This commit is contained in:
2026-04-08 16:33:21 -04:00
parent c8c57e950c
commit 16e072698b
2 changed files with 42 additions and 11 deletions
+26
View File
@@ -727,6 +727,24 @@ class MiniMateClient:
notes=notes,
)
def poll(self) -> None:
"""
Perform just the POLL startup handshake — no config reads.
Opens the connection if not already open. Used by the monitoring
endpoints which need to communicate with the device quickly without
spending 10-15 seconds reading compliance config and event index.
The POLL establishes the DLE-framed session with the device.
After poll(), the protocol is ready for any command (read_monitor_status,
start_monitoring, stop_monitoring, etc.).
"""
if not self.is_open:
self.open()
proto = self._require_proto()
log.debug("poll: startup handshake")
proto.startup()
# ── Monitoring ────────────────────────────────────────────────────────────
def get_monitor_status(self) -> MonitorStatus:
@@ -1748,6 +1766,14 @@ def _decode_monitor_status(data: bytes) -> MonitorStatus:
"""
# The data section starts at offset 11 (after the S3 section header).
section = data[11:] if len(data) > 11 else data
# Log the raw payload at WARNING level so we can see it in the server logs
# and confirm the field offsets and is_monitoring detection are correct.
log.warning(
"_decode_monitor_status: total data=%d bytes section=%d bytes hex=%s",
len(data), len(section), section.hex(),
)
# Mode: idle payload is 44 bytes; monitoring is shorter (12 bytes observed)
is_monitoring = len(section) < 20