🔒️ Drop non-finite values before they reach the recorder #20
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/46-value-guard"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Closes MateoGreil/homeassistant-comwatt#46.
Second layer of defence against the "negative / aberrant values" problem. #14 already maps failed fetches to
UpdateFailed(entity unavailable for that cycle) instead of silently re-authing and publishing stale state. This PR adds a value-level guard: a_clean_numerichelper coerces every raw API reading tofloatand returnsNoneunless the result is finite. Applied to:auto_production_ratetoday; extends to every site metric added by #19 once it merges).power.energydelta — on a bad bucket we skip the accumulator update so the running total never absorbs a NaN / string / null.What this does NOT fix
Pre-existing bad statistic rows in your recorder database still need manual correction via Developer Tools → Statistics. This PR only prevents new occurrences.
Test plan
test_non_numeric_values_are_droppedfeedsNaN,Infand the string"not-a-number"through the three ingestion paths; coordinator surfacesNoneand_energy_statestays untouched.pytest tests/— 25 passed;ruff+mypyclean.e1c171eb6155b4348e89View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.