Conversation
There was a problem hiding this comment.
Pull request overview
Updates Predbat to avoid crashing when inverter entity values (notably reserve-related) can’t be parsed as floats during write-and-poll verification, and bumps the application version accordingly.
Changes:
- Bump
THIS_VERSIONtov8.33.11. - Add float-conversion exception handling when re-reading and comparing inverter values in
write_and_poll_value().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
apps/predbat/predbat.py |
Version bump to reflect the change release. |
apps/predbat/inverter.py |
Harden numeric comparison in write_and_poll_value() by handling non-numeric current_state values. |
| try: | ||
| current_state = float(current_state) | ||
| except (ValueError, TypeError): | ||
| current_state = 0.0 | ||
| matched = abs(current_state - new_value) <= fuzzy |
There was a problem hiding this comment.
On conversion failure, current_state is forced to 0.0 and then used for the fuzzy comparison. This can incorrectly mark the value as already matched (e.g., when new_value is 0 or fuzzy is large), causing the method to stop retrying even though the real state was non-numeric (e.g., unknown). Consider treating conversion failure as matched = False (and optionally logging the unexpected state) so the write/poll loop doesn’t silently succeed on bad sensor values.
No description provided.