Skip to content

fix(output): cap the plan tooltip charge rate at the inverter limit - #5643

Merged
springfall2008 merged 4 commits into
mainfrom
fix/plan-tooltip-charge-rate-inverter-limit-5394
Oct 28, 2026
Merged

springfall2008 merged 4 commits into
mainfrom
fix/plan-tooltip-charge-rate-inverter-limit-5394

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

This is an automated draft PR generated from issue #5394 — a maintainer should review it before merging.

Fixes #5394

Summary

Output.get_charge_rate_kw() re-ran find_charge_rate() for the Chrg hover text, but it did not apply the inverter-limit clamp that the prediction applies afterwards (prediction.py, "Clamp at inverter limit" for hybrids and the non-hybrid total_inverted clamp). So when a battery is rated above its inverter, the tooltip showed battery_rate_max_charge rather than the rate the plan actually uses. The reporter's case: 14.40 kW shown, 10.56 kW planned.

The rate is now capped at inverter_limit × inverter_loss, which is where both prediction clamps leave the grid side of a charge. On a hybrid inverter the slot's DC-coupled PV is added on top, because the hybrid clamp only measures battery_draw + pv_dc. For the reporter's zero-PV overnight window (11.0 kW limit, 0.96 inverter loss) this gives 10.56 kW, which is their measured battery_power_best.

Testing

  • tools/triage_test.sh plan_why_reason: fails without the fix, passes with it. With output.py stashed, all three new cases fail with got 2.00. With the fix restored, the module passes.
  • New Test 4c in test_plan_why_reason.py uses a 2 kW battery behind a 1 kW inverter with 0.96 inverter loss. It covers three cases:
    • Hybrid, no PV: 0.96 kW.
    • Hybrid, 0.5 kW PV: 1.46 kW.
    • AC-coupled, 0.5 kW PV: 0.96 kW, because the PV cannot reach the battery on the DC side.
  • The existing Chrg and low-power cases are unchanged. The fixture's 1 kW limit equals its 1 kW battery rate, so the cap does not bind there.
  • ./run_pre_commit (from coverage/): all hooks passed, including the quick suite it runs.

Notes

  • Mirrors the clamp, does not share it. The prediction does this clamp inline, per step, inside the hot loop, so there is no function to reuse. The tooltip repeats the arithmetic, as it already does for find_charge_rate().
  • The PV-on-hybrid case was not checked against a real run. The 1.46 kW expectation comes from reading the hybrid clamp in prediction.py (where pv_dc = min(charge, pv) and the clamp acts on |draw + pv_dc| / inverter_loss), not from comparing with a prediction run. The zero-PV case matches the reporter's own numbers from their debug dump, as the triage comment verified.
  • Not covered: the battery_rate_max_charge_dc path. When battery_rate_max_charge_dc > battery_rate_max_charge on a hybrid, the prediction lets surplus PV raise the requested rate. The tooltip never modelled this, before or after this change, so it can under-report in that one case. I left it alone to keep this fix to the clamp.
  • Not covered: the discharge/export tooltip. In a later comment the reporter says the export tooltip has the same problem. The triage did not investigate that claim, and the export path also involves export_limit, so this PR does not change it.
  • Overlap with open draft PR Show the snail icon on low power charge slots in the plan #5353. Show the snail icon on low power charge slots in the plan #5353 changes get_charge_rate_kw() to return a tuple, so whichever merges second will need a small rebase. The two changes do not conflict in what they mean: Show the snail icon on low power charge slots in the plan #5353's snail checks the requested rate, and this PR caps only the rate that is displayed.
  • Blast radius (GitNexus impact): LOW. There is one caller, publish_html_plan, so only the hover text changes. Plan, prediction and execution are untouched.

🤖 Generated with Claude Code

…5394)

get_charge_rate_kw() re-ran find_charge_rate() but not the inverter-limit
clamp the prediction applies afterwards, so a battery rated above its
inverter showed battery_rate_max_charge in the Chrg hover text instead of
the rate actually planned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@springfall2008 springfall2008 self-assigned this Oct 19, 2026
@springfall2008 springfall2008 added BOT_REVIEW Trigger an autotriage BOT_CLEANUP Trigger: bot should address PR review feedback and CI failures, then commit and push labels Oct 19, 2026

@springfall2008 springfall2008 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Automated comment from the triage bot.

Reviewed at 813af58: 1 finding inline, none in the body. The fix itself is correct.

I re-derived the clamp algebra against prediction.py rather than trusting the description: when the generic "Clamp at inverter limit" block (prediction.py:1264-1296) binds during a charge it leaves the DC-side battery power at exactly pv_dc + inverter_limit × inverter_loss — the over_limit × inverter_loss correction cancels the loss divider from get_total_inverted() — in both the hybrid and AC-coupled branches, and with pv_dc = min(rate, pv_now) its binding condition (rate > pv_dc + limit × loss) is the same condition the tooltip's new min() tests. So min(rate, limit × loss + pv) mirrors the prediction exactly on every path this PR models, PV included; the reporter's numbers (11 kW × 0.96 = 10.56 kW, matching their measured battery_power_best) come out exact. Units line up too: pv_forecast_minute_step holds kWh per 5-minute step in Predbat's per-minute units, so dividing by PREDICT_STEP matches find_charge_rate()'s units, and the existing Test 1 assertion is untouched because the fixture's 1 kW inverter limit equals its 1 kW battery rate.

The two scope gaps the PR body already discloses — hybrid battery_rate_max_charge_dc > battery_rate_max_charge with PV lifting the combined rate (tooltip then under-reports) and the export tooltip's equivalent clamp gap — are real but correctly deferred; the reporter's comment on #5394 about export is the pointer for that follow-up.

@springfall2008 springfall2008 removed the BOT_REVIEW Trigger an autotriage label Oct 19, 2026
@springfall2008

Copy link
Copy Markdown
Owner Author

Automated reply from the triage bot (PR cleanup run).

Nothing pushed: the local quality gate failed in a test this PR doesn't touch.

What was addressed (locally, not pushed)

  • The inline finding on test_plan_why_reason.py Test 4c is correct. If publish_html_plan() raised inside the loop, the restore line after it was skipped, and the rest of the run would inherit a 1 kW inverter, 0.96 loss and 2 kW battery. The fix wraps the loop in try:/finally: with the saved-tuple restore as the finally body. This is the same pattern the module already uses for the car-hold block.
  • tools/triage_test.sh plan_why_reason passes with the change.

Why it was not pushed

./run_pre_commit fails in the quick suite, in octopus_url → day_night_rates:

ERROR: Expected 16 rate entries (8 days), got 15
ERROR: Expected 16 entries, got 15
✗ FAILED: day_night_rates

Every other hook and test passed. This PR changes only output.py and test_plan_why_reason.py, and neither is on the Octopus URL path. The bot's cleanup run on #5645 reproduced the same failure on main at 697c44ca earlier tonight, which is the commit this branch is based on (the merge from main was a no-op). I didn't re-run main myself in this session. The failure looks tied to the current date: the test builds an 8-day day/night rate window from the wall clock, and the window now crosses the 25 Oct BST→GMT change. This is suspected, not verified.

The cleanup rules don't allow pushing past a failing gate. The CI pre-commit check on 813af588 was green, so the next cleanup run can push the try/finally change once day_night_rates passes again, or a maintainer can apply the same two-line change by hand.

@springfall2008

Copy link
Copy Markdown
Owner Author

Automated cleanup failed to complete for this PR. Reason: The run exited cleanly but left 1 file(s) with uncommitted changes, so its fixes were never pushed. They are stashed in the bot's clone before the next flow runs. Failed at: triage_daemon.py:2161 in process_bot_cleanup_pr() (daemon 063549db). Not retrying automatically; remove BOT_FAILED and re-add BOT_CLEANUP to try again.

@springfall2008 springfall2008 added BOT_FAILED An automated triage/PR attempt failed; see the comment for details and removed BOT_CLEANUP Trigger: bot should address PR review feedback and CI failures, then commit and push labels Oct 19, 2026
@chalfontchubby chalfontchubby added BOT_CLEANUP Trigger: bot should address PR review feedback and CI failures, then commit and push and removed BOT_FAILED An automated triage/PR attempt failed; see the comment for details labels Oct 20, 2026
CI and others added 2 commits October 20, 2026 10:26
@springfall2008 springfall2008 removed the BOT_CLEANUP Trigger: bot should address PR review feedback and CI failures, then commit and push label Oct 20, 2026
@springfall2008

Copy link
Copy Markdown
Owner Author

This seems wrong, the description is about tool tips but it changes a live prediction of rates?

@chalfontchubby

Copy link
Copy Markdown
Collaborator

Posted by Claude on behalf of @chalfontchubby.

@springfall2008 it only changes the plan table's explanation text, not the prediction. get_charge_rate_kw() has a single caller, publish_html_plan(), where its value becomes rate_kw in the 'Charging up to X% at N kW at the import rate…' reason (output.py). The PR touches only that function and its test, and prediction.py is unchanged.

The function recomputes the rate the way the prediction works it out, for display, and the new lines copy the inverter-limit clamp prediction.py already applies. So the shown rate now matches what the plan uses: 10.56 kW rather than 14.40 kW in the #5394 report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BOT_PR_OPENED Bot PR flow opened a draft PR for this ticket

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plan tooltip shows battery_rate_max_charge instead of effective inverter-limited charge rate on hybrid inverter

2 participants