🐛 fix: skip corrupt persisted energy state instead of failing setup #113
No reviewers
Labels
No labels
v1.0 · bloquant
v1.0 · majeur
v1.0 · mineur
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
mat/homeassistant-comwatt!113
Loading…
Reference in a new issue
No description provided.
Delete branch "issue-56-storage-load"
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?
Follow-up to the fix attempt on GitHub issue MateoGreil/homeassistant-comwatt#56.
Why
Two independent bugs chain on affected accounts:
"12.34"), so the v0.8.x site-energy folding (value < 0) crashes withTypeError: '<' not supported between instances of 'str' and 'int'. Fixed client-side by thefix-string-series-valuesbranch of python-comwatt-client (normalize samples to float — to be released as 0.4.2)..storage/comwatt.energy_statecontains a__sites__entry mapped to JSONnull. No released version can write that shape (the save only writes dicts; stock v0.8.x failed its fetch before saving), so the file was corrupted externally — but the loader trusted the stored shape blindly, turning one malformed entry into a permanent, unrecoverable setup failure (a reinstall does not clear.storage).What
async_load_energy_statebecomes defensive:totals/folded_bucketsare tolerated_parse_bucket_tsinstead ofdatetime.fromisoformat, so unparseable values restore asNoneinstead of raisingThis also removes the need for the "delete .storage file" workaround — with this fix the corrupt entry is simply ignored and intact entries keep their continuity.
Tests
3 regression tests added (corrupt site entry, corrupt device entry, garbage timestamps); full suite 132 passed, ruff + mypy clean.