Skip to content

fix(sensor): subtract EV #2 power from house consumption#541

Open
woopstar wants to merge 2 commits into
mainfrom
fix/323-ev-second-power-consumption
Open

fix(sensor): subtract EV #2 power from house consumption#541
woopstar wants to merge 2 commits into
mainfrom
fix/323-ev-second-power-consumption

Conversation

@woopstar
Copy link
Copy Markdown
Owner

@woopstar woopstar commented Jun 1, 2026

The HSEMHouseConsumptionPowerSensor only subtracted EV #1 charger power from house consumption when house_power_includes_ev_charger_power was enabled. EV #2 (configured via hsem_ev_second_charger_power) was never read, tracked, or included in the calculation — causing the house baseline and its derived energy averages (1d/3d/7d/14d) to be inflated whenever the second EV was charging.

Changes

Threaded full EV #2 support through the entire sensor pipeline:

  • __init__ — added _hsem_ev_second_charger_power and _hsem_ev_second_charger_power_state
  • _update_settings — reads hsem_ev_second_charger_power from config
  • extra_state_attributes — exposes second EV entity + state
  • _async_track_entities — registers state-change listener for EV Add: _hsem_battery_maximum_charging_power #2
  • _async_fetch_sensor_states — fetches live power from EV Add: _hsem_battery_maximum_charging_power #2
  • _async_handle_update — sums both EV powers before subtracting from house consumption
  • _unrecorded_attributes — added new attribute keys

Also fixed three MagicMock(spec=...) tests in test_exception_handling.py that broke because the spec mock didn't have the new _hsem_ev_second_charger_power attribute set.

The coordinator (state_collector.py) and planner (coordinator_builder.py) already handled both EVs correctly; this was the last gap in the EV load separation pipeline.

Fixes #323

The house consumption power sensor only subtracted EV #1 from
house consumption when house_power_includes_ev_charger_power was
enabled. EV #2 power was never read, tracked, or included in the
calculation, causing the house baseline to be inflated whenever
the second EV was charging.

Add full EV #2 support through the entire sensor pipeline:
init, settings, state attributes, entity tracking, state fetching,
and the consumption calculation itself.

Fixes #323
@github-actions github-actions Bot added the bug Something isn't working label Jun 1, 2026
The three _async_fetch_sensor_states tests used MagicMock(spec=...)
but did not set _hsem_ev_second_charger_power, causing AttributeError
when the spec mock enforced attribute access on the new field.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P2-11] Add EV load separation

1 participant