Skip to content

fix(solis): initialise capacity_voltage_warned so publish_entities stops crashing - #4555

Merged
springfall2008 merged 1 commit into
mainfrom
fix/solis-capacity-voltage-warned
Aug 17, 2026
Merged

fix(solis): initialise capacity_voltage_warned so publish_entities stops crashing#4555
springfall2008 merged 1 commit into
mainfrom
fix/solis-capacity-voltage-warned

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

Problem

Solis users are seeing:

Error: SolisAPI: 'SolisAPI' object has no attribute 'capacity_voltage_warned'

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 in MockSolisAPI.__init__ but never in SolisAPI.initialize().

The guard sits on the fallback branch taken when get_capacity_voltage() returns None — i.e. whenever solis_nominal_voltage is not set in apps.yaml, which is the case for essentially every existing install. So the first publish_entities() run raises AttributeError and takes the cycle down with it.

Why the tests didn't catch it

MockSolisAPI overrides __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: initialise self.capacity_voltage_warned = set() alongside the other tracking state in initialize().
  • test_solis.py: add test_initialize_attribute_parity_with_mock(), which builds the real component via the existing _init_solis_component() helper and asserts it sets every attribute MockSolisAPI stubs (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: drop storage_modes from the mock — it is referenced nowhere in solis.py, so it only existed to be excluded from the new check.
  • Version bump v8.48.4v8.48.5.

Verification

The new test was confirmed to fail before the fix for exactly the right reason:

ERROR: SolisAPI.initialize() does not set attributes stubbed by MockSolisAPI: ['capacity_voltage_warned', ...]

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

…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>
Copilot AI lite review requested due to automatic review settings August 17, 2026 07:20

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

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_warned in SolisAPI.initialize() to prevent publish_entities() from crashing on first run.
  • Add a Solis test that asserts SolisAPI.initialize() sets all instance attributes that MockSolisAPI stubs (with an explicit test-only allowlist).
  • Remove an unused mock-only attribute (storage_modes) and bump Predbat version to v8.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.

@springfall2008
springfall2008 merged commit 2c2feea into main Aug 17, 2026
3 checks passed
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.

2 participants