Skip to content

Charging Overhead: session-only sensor + lifetime average sensor + consistent use in energy estimation#52

Draft
Copilot wants to merge 4 commits into
developfrom
copilot/simplify-charging-sensor
Draft

Charging Overhead: session-only sensor + lifetime average sensor + consistent use in energy estimation#52
Copilot wants to merge 4 commits into
developfrom
copilot/simplify-charging-sensor

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 9, 2026

  • _build_data_dict: always use charging_overhead_avg_pct for _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_estimate docstring: update stale comment that said no efficiency factor was needed in low-power
  • _evaluate_force_charge docstring: update capacity source description
  • Test helper _evaluate_low_power: add using_configured_capacity + overhead_avg_pct params
  • Added TestLowPowerOverheadCorrection (5 tests) for low-power overhead correction
  • Renamed module-level _compute_overhead_pct_compute_overhead_avg_pct to match coordinator naming; removed exact duplicate
  • Removed dead store_wall_wh/store_battery_wh params from TestOverheadConsistency._compute_overhead_pct and its 3 call sites
  • All 738 tests pass

🔒 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.

…ead Average sensor

Co-authored-by: Patrick1610 <6585375+Patrick1610@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor charging sensor for overhead reduction Split Charging Overhead into session-only sensor + lifetime average sensor Mar 9, 2026
…in low-power precise mode

Co-authored-by: Patrick1610 <6585375+Patrick1610@users.noreply.github.com>
Copilot AI changed the title Split Charging Overhead into session-only sensor + lifetime average sensor Charging Overhead: session-only sensor + lifetime average sensor + consistent use in energy estimation Mar 9, 2026
@Patrick1610 Patrick1610 requested a review from Copilot March 9, 2026 09:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_pct to session-only data, introduces _compute_overhead_avg_pct for 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 new ChargingOverheadAvgSensor entity (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; adds TestLowPowerOverheadCorrection covering 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.

Comment thread tests/test_coordinator.py
Comment on lines 6158 to 6165
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:
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Do as advised

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already done in commit 68982d6store_wall_wh and store_battery_wh were removed from TestOverheadConsistency._compute_overhead_pct and all three call sites were updated to drop those arguments.

Comment thread tests/test_coordinator.py Outdated
…_pct, remove duplicate, drop dead params

Co-authored-by: Patrick1610 <6585375+Patrick1610@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants