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
+16 -11
View File
@@ -626,15 +626,20 @@ def device_monitor_status(
"""
Read monitoring status from the device.
Returns is_monitoring bool, battery voltage, and memory usage (total + free bytes).
Battery and memory are only present when the unit is idle (not monitoring).
Uses poll() (POLL handshake only — no config/compliance reads) so the
request completes in ~2 seconds instead of ~15. The full connect() was
causing false "idle" readings because the compliance+event sequence was
interacting with the device state before the 0x1C read.
Returns is_monitoring bool, battery voltage, and memory usage (total + free
bytes). Battery and memory are only present when the unit is idle.
"""
with _build_client(port=port, baud=baud, host=host, tcp_port=tcp_port) as client:
try:
client.connect()
client.poll()
except Exception as exc:
log.warning("monitor status connect retry: %s", exc)
client.connect()
log.warning("monitor status poll retry: %s", exc)
client.poll()
status = client.get_monitor_status()
result: dict = {"is_monitoring": status.is_monitoring}
@@ -663,10 +668,10 @@ def device_monitor_start(
"""
with _build_client(port=port, baud=baud, host=host, tcp_port=tcp_port) as client:
try:
client.connect()
client.poll()
except Exception as exc:
log.warning("start monitoring connect retry: %s", exc)
client.connect()
log.warning("start monitoring poll retry: %s", exc)
client.poll()
client.start_monitoring()
return {"status": "started"}
@@ -685,10 +690,10 @@ def device_monitor_stop(
"""
with _build_client(port=port, baud=baud, host=host, tcp_port=tcp_port) as client:
try:
client.connect()
client.poll()
except Exception as exc:
log.warning("stop monitoring connect retry: %s", exc)
client.connect()
log.warning("stop monitoring poll retry: %s", exc)
client.poll()
client.stop_monitoring()
return {"status": "stopped"}