Skip to content

fix(hass): don't misdetect an existing install as new on a transient predbat.status read failure - #4409

Merged
springfall2008 merged 3 commits into
mainfrom
fix/new-install-misdetection
Aug 1, 2026
Merged

fix(hass): don't misdetect an existing install as new on a transient predbat.status read failure#4409
springfall2008 merged 3 commits into
mainfrom
fix/new-install-misdetection

Conversation

@chalfontchubby

Copy link
Copy Markdown
Collaborator

Summary

Test plan

  • New apps/predbat/tests/test_new_install_detection.py: covers a genuinely fresh install (no file, still detected as new), an existing install with predbat_config.json present (not misdetected even with predbat.status unavailable), DB-primary mode correctly skipping the file-based signal, and a real predbat.status read still being authoritative.
  • Full quick test suite passes.
  • Pre-commit clean.

…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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 via predbat_config.json presence (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.

Comment thread apps/predbat/userinterface.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants