Refactor to polling-first architecture with OBSERVE as accelerator

State freshness now comes from a tiered PollScheduler over the persistent
DTLS session; OBSERVE registrations are kept as an opportunistic
acceleration layer. Behaviour is identical online vs air-gapped except
for worst-case freshness latency.

Adds three modules:
- StateCache: single source of truth, source-tagged change events
- PollScheduler: hot/warm/cold + sweep tiers, write-defer past the
  fetchback-revert window, per-window RTT/slow-poll tracking
- KeepaliveTask: CoAP empty-CON ping with consecutive-fail detection
  driving MQTT availability

Bridge publishes per-appliance diagnostic entities (Push Active, Last
Update Source, Poll Max RTT, Slow Polls, Poll Errors, Stalest Resource
Age, Last OBSERVE Age) under HA's Diagnostic section. Tier cadences
are descriptor-declared, calibrated against measured per-firmware
ceilings (dryer ~14 req/s, oven ~8 req/s via probe_poll_rate_combined.py).

Drops HEARTBEAT_INTERVAL_S in favour of the descriptor-declared sweep
tier; PING_INTERVAL_S now consumed by KeepaliveTask inside the bridge
rather than driven from main.py.

README explains the push/poll split and what happens when the appliance
is blocked from internet.
This commit is contained in:
Jack Nagy
2026-06-03 18:38:04 +01:00
parent 8775f7a930
commit 709fdf444d
11 changed files with 866 additions and 324 deletions
+8 -7
View File
@@ -43,14 +43,15 @@ MQTT_PASS=
HA_DISCOVERY_PREFIX=homeassistant
# Bridge timers (seconds).
# HEALTH_INTERVAL_S — how often <prefix>/bridge/health republishes.
# HEARTBEAT_INTERVAL_S — periodic full /device/0 re-seed. Refreshes
# every resource (observed too) — useful for
# appliances like the oven that don't reliably
# push OBSERVE on /mode/vs/0 option changes. 0
# disables.
# HEALTH_INTERVAL_S — how often <prefix>/bridge/health republishes.
# PING_INTERVAL_S — CoAP empty-CON ping cadence (DTLS-layer
# liveness). Three consecutive failures publish
# availability=offline.
# State freshness itself comes from the in-bridge PollScheduler whose
# tier cadences are declared in the appliance descriptor — there is
# no top-level heartbeat env var to tune.
HEALTH_INTERVAL_S=60
HEARTBEAT_INTERVAL_S=600
PING_INTERVAL_S=25
# Container TZ.
TZ=Europe/London