WIP: ✨ StreamManager + real-time switches via WebSocket (streaming 2/5) #57
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/stream-switches"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Slice 2 of 5 (stacked on #56). Adds a per-site WebSocket stream that pushes switch STATE updates in real time (~15s, vs the 2-min poll).
What
custom_components/comwatt/stream.py:ComwattStreamManagerruns the blockingstream_measurementsgenerator in an executor thread per site, pushes messages to anasyncio.Queuevialoop.call_soon_threadsafe, drained by a consumer task that batches bursts and applies STATE switch updates tocoordinator.data["switches"]._apply_switch_updates: module-level pure function — routes STATE measurements viacoordinator.capacity_map(slice 1), skips FLOW/QUANTITY/CapacityChanged and non-switch natures, mutatesswitches_data, returns whether anything changed._process_batchnotifies entities viaasync_update_listeners()(NOTasync_set_updated_data— that would reset the 2-min poll timer and regress power/energy).try/exceptguard so a bad batch can't silently kill it.reconnect=Falseat the client), teardown viaasyncio.Eventstop flag. DedicatedComwattClient(never shares the coordinator'srequests.Session).async_setup_entry(start) /async_unload_entry(stop, idempotent).manifest.json:iot_classcloud_polling → cloud_push, +websocket-client==1.9.0.UPDATE_INTERVALunchanged (2 min) — power/energy still poll until slices 3/4.Tests
7 new tests (T1-T6 + consumer-error-survival). 51/51 passing, ruff + mypy clean. T6 is a real end-to-end: sets up a switch device, starts the manager via
async_setup_entry, manually queues a STATE measurement, asserts the switch flips through the real consumer, then teardown cleans up.Stacking
Base:
feat/capacity-map(PR #56). Rebase tomainonce #56 merges.Landed in
mainvia the linear stack fast-forward (commit9d016f7). This slice is part of the streaming feature merged as #56…#62 — closing (its commits are already inmain).Pull request closed