Repository navigation
fix(inverter): warn once, not every cycle, while battery_scaling keeps reading invalid - #5841
Merged
Merged
Conversation
…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>
springfall2008
left a comment
Owner
There was a problem hiding this comment.
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_warnedstartsFalsein__init__, is set on the first invalid read (so the first log isWarn), 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_dataonly 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 agentget_logtool; the oneWarn:line stays in Warnings.hass.py:215also routesInfo:-prefixed lines to the console the same wayWarn: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__andfetch_inverter_data, once per cycle when notquick); the value path is unchanged —battery_scalingstill receiveslast_knownon invalid reads andbattery_scaling_last_knownis still written on valid ones — so no caller impact beyond the log prefix. - Test. The added block in
test_battery_scaling_invalid_value_clampedexercises exactly the Warn→Info→Warn sequence including the clearing by a valid read, and cannot pass on main (all four levels would beWarn), so the behaviour is covered. No new test module, so noTEST_REGISTRYchange 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Opened by Claude on behalf of @chalfontchubby.
Fixes #5368
Problem
When
battery_scalingreads 0 or negative (in #5368, one Solis Cloud inverter reportingbatteryHealthSoh0), 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