WIP: 🐛 Fix device_id key type mismatch that broke ALL stream routing (streaming, critical) #62
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/device-id-key-type"
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?
Critical fix found by a live test deploy on real hardware (HAOS, real Comwatt account). Stacked on #61.
The bug
_fold_capacity_mapstoredstr(device_id)incapacity_map, butcoordinator.data["devices"]/["switches"]and_energy_stateare keyed by the RAWdevice["id"](INT, from the real API). So streamed measurements routed viacapacity_mapproduced str keys ('23593') that never matched the int-keyed dicts → the WebSocket stream silently updated NOTHING (power, energy, switch). Only the polling path (consistent int keys) worked, which is why power showed values but energy never rose from the stream.Why unit tests missed it
Tests used STRING device ids everywhere, self-consistently —
str(129443) == "129443"matched the string-keyed test data by accident. The real API uses int ids on bothget_devicesandget_connected_objects, so the accidental match never happens in production.Fix (2 lines)
_fold_capacity_map:str(device_id)→device_id(raw, matchesleaf["id"]).dict[str, tuple[str, str, bool]]→dict[str, tuple[Any, str, bool]].Tests
test_stream_updates_device_with_integer_id: intdevice_id=23600end-to-end (async_setup → stream push → assertdata["devices"][23600]["power"] == 161.0). RED before (asserts None==161), GREEN after.SWITCH_DEVICE_ID, two consumer end-to-end tests. Pure-function routing tests left as-is (self-consistent).Live verification
Deployed to a real HAOS box: after this fix, streamed power/energy/switch update in real time and HA values match the Comwatt live stream exactly (solaire 1802 W, injection 925 W, soutirage 932 W, clim 696 W… all identical), energy accumulates via ∫W·dt (solaire +7.3 Wh in 15 s @ 1786 W = correct).
Note
Root cause is in #56 (
_fold_capacity_map); the one-line fix could be squashed down into #56 when finalizing the stack. Kept as a dedicated PR here for visibility of the bug + regression test.