fix(solis): initialise capacity_voltage_warned so publish_entities stops crashing - #4555
Merged
Merged
Conversation
…ops crashing #4502 added a once-per-inverter warning for the estimated battery capacity voltage, guarded by self.capacity_voltage_warned, but only initialised that set in MockSolisAPI - never in SolisAPI.initialize(). Any install without solis_nominal_voltage set in apps.yaml (i.e. almost all of them) therefore takes the fallback branch on the first publish_entities() run and raises "'SolisAPI' object has no attribute 'capacity_voltage_warned'", aborting the update cycle so no plan is ever produced. MockSolisAPI replaces __init__ wholesale, which is why the whole test suite passed against a component that could not survive a single real poll. Add a parity guard that constructs the real component and asserts it sets every attribute the mock stubs, so this class of divergence fails in CI rather than on a live inverter. Drop storage_modes from the mock while doing so - it is referenced nowhere in solis.py. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a production crash in the Solis integration where publish_entities() could raise AttributeError due to an uninitialised capacity_voltage_warned attribute, aborting the entire Predbat update cycle for most Solis installs. It also adds a regression test to prevent future mock/real component attribute divergence from slipping through Solis unit tests.
Changes:
- Initialise
SolisAPI.capacity_voltage_warnedinSolisAPI.initialize()to preventpublish_entities()from crashing on first run. - Add a Solis test that asserts
SolisAPI.initialize()sets all instance attributes thatMockSolisAPIstubs (with an explicit test-only allowlist). - Remove an unused mock-only attribute (
storage_modes) and bump Predbat version tov8.48.5.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
apps/predbat/solis.py |
Initialises capacity_voltage_warned during component setup so the once-per-inverter warning logic can’t throw AttributeError. |
apps/predbat/tests/test_solis.py |
Adds an attribute-parity regression test and removes an unused mock attribute to reduce mock/real drift. |
apps/predbat/predbat.py |
Bumps THIS_VERSION from v8.48.4 to v8.48.5. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Problem
Solis users are seeing:
The update cycle aborts, so no plan is produced at all — Predbat keeps trying to calculate and never gets anywhere.
Root cause
#4502 added a once-per-inverter warning for an estimated battery capacity voltage, guarded by
self.capacity_voltage_warned(solis.py:2314-2315). That set was initialised inMockSolisAPI.__init__but never inSolisAPI.initialize().The guard sits on the fallback branch taken when
get_capacity_voltage()returnsNone— i.e. wheneversolis_nominal_voltageis not set inapps.yaml, which is the case for essentially every existing install. So the firstpublish_entities()run raisesAttributeErrorand takes the cycle down with it.Why the tests didn't catch it
MockSolisAPIoverrides__init__wholesale rather than calling the real one, so it happily stubbed the attribute the production path was missing. Every Solis test passed against a component that could not survive a single real poll.Fix
solis.py: initialiseself.capacity_voltage_warned = set()alongside the other tracking state ininitialize().test_solis.py: addtest_initialize_attribute_parity_with_mock(), which builds the real component via the existing_init_solis_component()helper and asserts it sets every attributeMockSolisAPIstubs (minus an explicit test-harness allowlist). This fails CI for the whole class of mock/real divergence, not just this one attribute.test_solis.py: dropstorage_modesfrom the mock — it is referenced nowhere insolis.py, so it only existed to be excluded from the new check.v8.48.4→v8.48.5.Verification
The new test was confirmed to fail before the fix for exactly the right reason:
After the fix:
./run_all --test solis— passes./run_all --quick— all tests pass, 20/20 random scenarios match baseline across 320 compared fields./run_pre_commit— all hooks pass🤖 Generated with Claude Code