fix(hass): don't misdetect an existing install as new on a transient predbat.status read failure - #4409
Merged
Merged
Conversation
…predbat.status read failure HA's state store can briefly come back empty right after an abrupt restart, and load_user_config() treated a single failed predbat.status read as proof of a fresh install, silently resetting live config (mode, and anything else reset_inverter-flagged) back to defaults. Use predbat_config.json's presence as a second, persistent signal that this is a real install before falling back to "new install". This is Bug B from #4397/#4396 (Bug A, the restart trigger, already fixed by #4401), also seen independently as #3259 and #3306.
… the workspace dictionary CI caught what the local pre-commit run missed - it only scans staged files, and the new test file wasn't staged yet when it was run locally.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a Home Assistant restart edge case where a transient predbat.status read failure could cause load_user_config() to misclassify an existing installation as “new”, leading to silent resets of defaulted config items (notably mode).
Changes:
- Extracted new-install detection into
UserInterface.is_new_install()and added a persistent signal viapredbat_config.jsonpresence (when not in DB-primary mode). - Added a focused regression test covering fresh installs, existing installs with missing status, DB-primary behavior, and authoritative status reads.
- Updated cspell custom dictionary with “misdetect*” words used in the new test/logic.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/predbat/userinterface.py | Adds is_new_install() and updates load_user_config() to avoid misdetecting existing installs on transient HA status read failures. |
| apps/predbat/unit_test.py | Registers the new new-install detection test in the unit test runner. |
| apps/predbat/tests/test_new_install_detection.py | Adds regression coverage for the misdetection scenario and related edge cases. |
| .cspell/custom-dictionary-workspace.txt | Adds new words introduced by the PR to the spell-check dictionary. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced Aug 3, 2026
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.
Summary
predbat.statusread (e.g. right after an abrupt restart, before HA's own state store has fully warmed back up) was enough forload_user_config()to treat an existing install as brand new, silently resetting live config (mode, and anything elsereset_inverter/reset_inverter_force-flagged) back to defaults.is_new_install()and added a second, persistent signal: ifpredbat_config.jsonexists on disk (skipped in DB-primary mode, which doesn't use that file), don't treat the install as new even if the live/historypredbat.statusread comes back empty.Test plan
apps/predbat/tests/test_new_install_detection.py: covers a genuinely fresh install (no file, still detected as new), an existing install withpredbat_config.jsonpresent (not misdetected even withpredbat.statusunavailable), DB-primary mode correctly skipping the file-based signal, and a realpredbat.statusread still being authoritative.