✨ Realtime measurement streaming over STOMP/WebSocket ([stream] extra) #48
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/streaming-websocket"
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?
Summary
Adds a realtime measurement streaming client over STOMP-over-WebSocket, as an optional
comwatt-client[stream]extra. This is slice 1/2 of the streaming work (the remaining item from the client audit); a stacked follow-up PR adds auto-reconnect.New public API:
ComwattClient.stream_measurements(site: dict) -> Iterator[Measurement | CapacityChanged]— sync generator; openswss://frontage.energy.comwatt.com/wsreusing thecwt_sessioncookie, subscribes to the site'ssiteUidtopic, sends/app/streaming/start, and yields liveFLOW/STATEevents.Measurement(gateway_uid, capacity_id, measure_kind, value + parsedvalue_float/value_bool) andCapacityChanged(capacity_id, enable, raw).ComwattStreamingError.Design (per grilling sign-off)
pip install comwatt-client[stream](websocket-client); baseimport ComwattClientstill works without it (lazy import →ComwattStreamingErrorif missing).Load-bearing correctness (live-verified)
siteUidtopic; SENDstartbody uses the numericsiteId. Both are pinned by a test that parses the actual STOMP frames sent.Test plan
filterwarnings=error).mypy comwatt_clientclean (disallow_untyped_defs=true).websocketunavailable (lazy import verified).ComwattAuthError; missing site keys →ValueError; missing extra →ComwattStreamingError; handshake failure →ComwattStreamingError; DISCONNECT/close cleanup on exhaustion andGeneratorExit;Cookie:header format.## Realtime streaming (optional)section.Notes
0.4.0) is left to the usual release step once merged.Add an optional `comwatt-client[stream]` extra (websocket-client) that streams live measurements for a single site over STOMP-over-WebSocket: - `StreamingMixin.stream_measurements(site)` yields `Measurement` / `CapacityChanged` events from `wss://frontage.energy.comwatt.com/ws`. - Subscribes to the `siteUid` topic (`/topic/sites/{siteUid}/capacityChanged`) and starts the stream with the numeric `site[id]` (pins the two-id pitfall). - Lazy-imports websocket so the base package imports without the extra; raises `ComwattStreamingError` (with install hint) when the extra is missing. - Best-effort DISCONNECT + close on generator close/socket drop; no reconnect. - Exports `Measurement`, `CapacityChanged`, `ComwattStreamingError`. Tests fake the WS via monkeypatched `_open_websocket`; 103 existing tests unchanged, 8 new streaming tests, mypy clean.WIP: ✨ Realtime measurement streaming over STOMP/WebSocket ([stream] extra)to ✨ Realtime measurement streaming over STOMP/WebSocket ([stream] extra)