feat: Implement poll() method for efficient device communication and update monitoring status retrieval
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user