Charging Overhead: session-only sensor + lifetime average sensor + consistent use in energy estimation#52
Charging Overhead: session-only sensor + lifetime average sensor + consistent use in energy estimation#52Copilot wants to merge 4 commits into
Conversation
…ead Average sensor Co-authored-by: Patrick1610 <6585375+Patrick1610@users.noreply.github.com>
…in low-power precise mode Co-authored-by: Patrick1610 <6585375+Patrick1610@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes the Charging Overhead sensor inaccuracy by splitting it into two distinct sensors and consolidating how overhead is used in energy estimation. The root cause was the old sensor blending live session data with lifetime store totals, causing stale historical values to dominate.
Changes:
coordinator.py: Refactors_compute_overhead_pctto session-only data, introduces_compute_overhead_avg_pctfor lifetime store-based average, and adds an overhead inflation step in the low-power precise mode when using a manually configured (battery-side) capacity.sensor.py: Adds the newChargingOverheadAvgSensorentity (lifetime average, updated once per session at cable disconnect).tests/test_coordinator.py: Updates helper functions and test classes to match the session-only simplification; addsTestLowPowerOverheadCorrectioncovering the new low-power overhead path.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
custom_components/adaptive_charge/coordinator.py |
Splits _compute_overhead_pct into session-only + _compute_overhead_avg_pct (lifetime); adds overhead correction in low-power precise mode; switches _compute_energy_needed_full_kwh to always use the lifetime average |
custom_components/adaptive_charge/sensor.py |
Registers new ChargingOverheadAvgSensor; updates existing ChargingOverheadSensor docstrings |
tests/test_coordinator.py |
Removes store-parameter coupling from live-overhead helpers; adds TestLowPowerOverheadCorrection; updates behaviour assertions for session-only (None on disconnect/below-threshold) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| def _compute_overhead_pct( | ||
| self, | ||
| store_wall_wh: float, | ||
| store_battery_wh: float, | ||
| session_battery_delta: float | None, | ||
| session_wall_snapshot_wh: float, | ||
| cable_prev: bool, | ||
| ) -> float | None: |
There was a problem hiding this comment.
The _compute_overhead_pct method in TestOverheadConsistency (line 6158–6177) accepts store_wall_wh and store_battery_wh parameters that are never read inside the function body after this refactoring. The new session-only implementation ignores lifetime store data entirely, so these parameters are dead weight. They should be removed from the method signature, and the three call sites (lines 6180, 6192, 6203) should be updated to drop those arguments.
There was a problem hiding this comment.
Already done in commit 68982d6 — store_wall_wh and store_battery_wh were removed from TestOverheadConsistency._compute_overhead_pct and all three call sites were updated to drop those arguments.
…_pct, remove duplicate, drop dead params Co-authored-by: Patrick1610 <6585375+Patrick1610@users.noreply.github.com>
_build_data_dict: always usecharging_overhead_avg_pctfor_compute_energy_needed_full_kwh(remove session-primary/avg-fallback)_evaluate_force_charge: apply lifetime avg overhead when using configured (battery-side) capacity in low-power precise mode to convert battery kWh → wall kWh_update_capacity_estimatedocstring: update stale comment that said no efficiency factor was needed in low-power_evaluate_force_chargedocstring: update capacity source description_evaluate_low_power: addusing_configured_capacity+overhead_avg_pctparamsTestLowPowerOverheadCorrection(5 tests) for low-power overhead correction_compute_overhead_pct→_compute_overhead_avg_pctto match coordinator naming; removed exact duplicatestore_wall_wh/store_battery_whparams fromTestOverheadConsistency._compute_overhead_pctand its 3 call sites🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.