Skip to content

fix(inverter): warn once, not every cycle, while battery_scaling keeps reading invalid - #5841

Merged
springfall2008 merged 1 commit into
mainfrom
fix/battery-scaling-warn-once
Oct 29, 2026
Merged

springfall2008 merged 1 commit into
mainfrom
fix/battery-scaling-warn-once

Conversation

@chalfontchubby

Copy link
Copy Markdown
Collaborator

Opened by Claude on behalf of @chalfontchubby.

Fixes #5368

Problem

When battery_scaling reads 0 or negative (in #5368, one Solis Cloud inverter reporting batteryHealthSoh 0), Predbat keeps the last valid value (the #4500 logic, unchanged), but logged a warning on every cycle for as long as the source stayed invalid.

Change

Inverter objects now persist across cycles, so a per-inverter flag (in the lifetime-state block) warns on the first invalid read, logs at Info after that, and warns again only after a valid read in between. Test: invalid, invalid, invalid, valid, invalid gives Warn, Info, Info, Warn. It fails on main.

Notes

A source that alternates invalid/valid every cycle would still warn each time. #5368's reading is steadily 0.

🤖 Generated with Claude Code

…s reading invalid

When battery_scaling reads 0 or negative (for #5368, a Solis Cloud inverter reporting
batteryHealthSoh 0), Predbat keeps the last valid value, but it logged a warning on every cycle
for as long as the source stayed invalid. Now that Inverter objects persist across cycles, warn
on the first invalid read and log at Info after that, warning again only after a valid read in
between. The retain-last-known-value logic is unchanged.

Fixes #5368

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the BOT_REVIEW Trigger an autotriage label Oct 29, 2026

@springfall2008 springfall2008 left a comment

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.

Automated comment from the triage bot.

Reviewed at 681d797: no issues found. The change is minimal and correct, and it does exactly what the triage on #5368 recommended ("a once-per-inverter warning ... while keeping the honest publish and the retain behaviour").

What I checked:

  • Flag semantics. battery_scaling_invalid_warned starts False in __init__, is set on the first invalid read (so the first log is Warn), is cleared only by a valid read (inverter.py:536), and survives across cycles. I verified Inverter objects really do persist across cycles — fetch_inverter_data only rebuilds them when the list is empty or the count changed (execute.py:1366-1384) — so the once-per-source-outage claim holds, and a rebuild (count change / restart) re-warns once, which is reasonable.
  • Log consumers. The Info: prefix is functional, not cosmetic: classify_log_line() (utils.py:853) buckets by substring, and the Info line contains no "warn"/"error" substring, so repeats move from the Warnings view to the Info view in the web log page and the agent get_log tool; the one Warn: line stays in Warnings. hass.py:215 also routes Info:-prefixed lines to the console the same way Warn: always was, so console/All views still show one line per cycle — the relabel removes the repeat from the Warnings view, not from the log; flagging that here so expectations are set.
  • Callers. refresh_config() has two direct sync callers (Inverter.__init__ and fetch_inverter_data, once per cycle when not quick); the value path is unchanged — battery_scaling still receives last_known on invalid reads and battery_scaling_last_known is still written on valid ones — so no caller impact beyond the log prefix.
  • Test. The added block in test_battery_scaling_invalid_value_clamped exercises exactly the Warn→Info→Warn sequence including the clearing by a valid read, and cannot pass on main (all four levels would be Warn), so the behaviour is covered. No new test module, so no TEST_REGISTRY change needed.

The PR honestly discloses the one remaining limitation (a source alternating invalid/valid every cycle still warns each time), and #5368's report is of a steadily-0 reading, so that limitation doesn't bite the reported case.

@springfall2008 springfall2008 removed the BOT_REVIEW Trigger an autotriage label Oct 29, 2026
@springfall2008
springfall2008 merged commit 64e6180 into main Oct 29, 2026
3 checks passed
@springfall2008
springfall2008 deleted the fix/battery-scaling-warn-once branch October 29, 2026 18:54
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.

Solis Cloud: battery_scaling read as 0.0 when one inverter reports batteryHealthSoh of 0

2 participants