Fix crash in find_battery_size when SOC history contains 'unavailable' states#3948
Merged
Merged
Conversation
Copilot
AI
changed the title
[WIP] Fix error with SOC - could not convert string to float
Fix crash in find_battery_size when SOC history contains 'unavailable' states
May 21, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a crash in Inverter.find_battery_size() when soc_kw history includes non-numeric Home Assistant states (e.g., "unavailable"/"unknown"), which can occur in GivEnergy dual AIO Gateway setups and previously caused Predbat to get stuck re-evaluating.
Changes:
- Make
find_battery_size()robust to non-numericsoc_kwhistory entries by skipping values that can’t be parsed as floats. - Add a regression test covering
soc_kwhistory containing"unavailable"/"unknown"entries and asserting estimation still succeeds within tolerance.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/predbat/inverter.py | Avoids crashing battery-size estimation when soc_kw history contains non-numeric states by filtering invalid entries before computing soc_max. |
| apps/predbat/tests/test_find_battery_size.py | Adds a regression test that injects "unavailable"/"unknown" states into soc_kw history and validates estimation remains stable. |
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.
GivEnergy dual AIO setups expose a Gateway entity whose
soc_kwhistory contains'unavailable'state entries (the Gateway has no batteries directly attached). The auto battery-degradation logic introduced in recent releases calledfloat(state["state"])in a bare generator expression with no error handling, crashingInverter.__init__on every cycle and leaving Predbat permanently stuck in "re-evaluating".Changes
apps/predbat/inverter.py—find_battery_size: Replace the one-linermax(float(...) for state in ...)generator with an explicit loop that skips non-numeric entries viatry/except (ValueError, TypeError). Consistent with the identical pattern used a few lines below forbuilt_listconstruction.apps/predbat/tests/test_find_battery_size.py: Addtest_find_battery_size_soc_kw_unavailable— injects'unavailable'and'unknown'entries (~20% of history) into thesoc_kwhistory and asserts no exception is raised and the size estimate remains within 30% tolerance.