WIP: Real-time power via the stream: sum FLOW polyphase instances (streaming 3/5) #58

Closed
mat wants to merge 1 commit from feat/stream-power into feat/stream-switches
Owner

Slice 3 of 5 (stacked on #57). Routes FLOW measurements to live power entities in real time (~15s, vs the 2-min poll).

What

  • New _apply_power_updates pure helper in stream.py: routes FLOW measurements via capacity_map, sums polyphase instances per device (per-batch accumulator → true sum, not partial overwrites), writes to coordinator.data["devices"][id]["power"].
  • POWER_SENSOR_NATURES = ("CLAMP", "POWER_SENSOR") — skips switches and non-power natures.
  • _process_batch extended to apply BOTH switch + power updates, notify via async_update_listeners() if either changed (preserves the 2-min poll timer — no regression to power/energy polling).
  • _apply_switch_updates untouched. UPDATE_INTERVAL unchanged (2 min). Energy still polls (Slice 4).

Why sum

A multi-instance device (e.g. 3-phase solar inverter) pushes all its instances in the same ~15s burst. Summing within one batch yields the device's true instantaneous power (spike confirmed: 629+622+604=1855 W).

Tests

6 new tests (T1-T6). T6 is a real end-to-end: multi-instance solar device → start manager → queue 3 FLOW instances → assert power == 1855 through the real consumer. 57/57 passing, ruff + mypy clean.

Stacking

Base: feat/stream-switches (PR #57). Rebase once #57 merges.

Slice 3 of 5 (stacked on #57). Routes FLOW measurements to live power entities in real time (~15s, vs the 2-min poll). ## What - New `_apply_power_updates` pure helper in `stream.py`: routes FLOW measurements via `capacity_map`, sums polyphase instances per device (per-batch accumulator → true sum, not partial overwrites), writes to `coordinator.data["devices"][id]["power"]`. - `POWER_SENSOR_NATURES = ("CLAMP", "POWER_SENSOR")` — skips switches and non-power natures. - `_process_batch` extended to apply BOTH switch + power updates, notify via `async_update_listeners()` if either changed (preserves the 2-min poll timer — no regression to power/energy polling). - `_apply_switch_updates` untouched. `UPDATE_INTERVAL` unchanged (2 min). Energy still polls (Slice 4). ## Why sum A multi-instance device (e.g. 3-phase solar inverter) pushes all its instances in the same ~15s burst. Summing within one batch yields the device's true instantaneous power (spike confirmed: 629+622+604=1855 W). ## Tests 6 new tests (T1-T6). T6 is a real end-to-end: multi-instance solar device → start manager → queue 3 FLOW instances → assert power == 1855 through the real consumer. 57/57 passing, ruff + mypy clean. ## Stacking Base: `feat/stream-switches` (PR #57). Rebase once #57 merges.
Real-time power via the stream: sum FLOW polyphase instances (streaming 3/5)
All checks were successful
Validate / lint-ruff (pull_request) Successful in 7s
Validate / test-pytest (pull_request) Successful in 3m1s
Validate / type-check-mypy (pull_request) Successful in 3m9s
Validate / lint-ruff (push) Successful in 7s
Validate / test-pytest (push) Successful in 3m2s
Validate / type-check-mypy (push) Successful in 3m9s
dd274fbfb4
Author
Owner

Landed in main via the linear stack fast-forward (commit 9d016f7). This slice is part of the streaming feature merged as #56…#62 — closing (its commits are already in main).

Landed in `main` via the linear stack fast-forward (commit `9d016f7`). This slice is part of the streaming feature merged as #56…#62 — closing (its commits are already in `main`).
mat closed this pull request 2026-07-14 17:12:45 +00:00
All checks were successful
Validate / lint-ruff (pull_request) Successful in 7s
Validate / test-pytest (pull_request) Successful in 3m1s
Validate / type-check-mypy (pull_request) Successful in 3m9s
Validate / lint-ruff (push) Successful in 7s
Validate / test-pytest (push) Successful in 3m2s
Validate / type-check-mypy (push) Successful in 3m9s

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mat/homeassistant-comwatt!58
No description provided.