Skip to content

fix(config): exempt control placeholders named with a custom prefix from the "cannot be modified" check - #5845

Merged
springfall2008 merged 1 commit into
mainfrom
fix/validate-placeholder-custom-prefix
Nov 1, 2026
Merged

springfall2008 merged 1 commit into
mainfrom
fix/validate-placeholder-custom-prefix

Conversation

@chalfontchubby

Copy link
Copy Markdown
Collaborator

Opened by Claude on behalf of @chalfontchubby.

Fixes #5242

Problem

validate_config() lets a modifiable setting point at a sensor only if it is one of Predbat's own control placeholders, but recognised them by a hard-coded sensor.predbat_, while placeholders are named with the instance's prefix (sensor.<prefix>_<inverter_type>_<id>_<name>). With a custom prefix (in #5242, sensor.predbatsolcast_..._inverter_mode on SolaX Cloud), apps.yaml reported a false "cannot be modified" error.

Change

Accept sensor.<prefix>_ as well as the existing sensor.predbat_, so a config copied from a default-prefix instance keeps validating. Tests: a real-shaped custom-prefix placeholder passes (fails on main), and a look-alike prefix still errors.

Note

A custom prefix that happens to equal an integration's own naming (e.g. prefix: solax) would now exempt that integration's sensor.solax_* entities from this check. It's an unlikely setup.

🤖 Generated with Claude Code

…rom the "cannot be modified" check

validate_config() lets a modifiable setting point at a sensor only when it is one of Predbat's own
control placeholders, but it recognised them only by a hard-coded "sensor.predbat_", while the
placeholders are named with the instance's prefix. With a custom prefix (in #5242,
sensor.predbatsolcast_..._inverter_mode on SolaX Cloud) apps.yaml reported a false error.
Accept "sensor.<prefix>_" as well as the existing "sensor.predbat_", so a config copied from a
default-prefix instance keeps validating.

Fixes #5242

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the BOT_REVIEW Trigger an autotriage label Oct 29, 2026

@springfall2008 springfall2008 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Automated comment from the triage bot.

Reviewed at head commit 728824f: no findings. The change matches how the placeholders are actually named, and the test fails on main as claimed.

What I checked:

  • Root cause confirmed. The dummy placeholders this check is meant to exempt are created in inverter.py:1662 (create_entity) as sensor.{self.base.prefix}_{inverter_type}_{id}_{entity_name} — the same shape as the reporter's sensor.predbatsolcast_SolaxCloud_0_inverter_mode in #5242 (SolaxCloud is an INVERTER_DEF key, config.py:2491), so exempting sensor.<prefix>_ addresses the reported case, and keeps the literal sensor.predbat_ for configs copied from a default-prefix install. No other hard-coded sensor.predbat_ validation remains in non-test code — components.py already swaps the real prefix in _entity_matches_filter (components.py:1036, the #4939 fix), so this is the same mechanism fixed at the same altitude.
  • Red/green verified statically. On main, the positive case (inverter_mode: sensor.predbatsolcast_solax_cloud_0_inverter_mode) falls through the old startswith('sensor.predbat_') (no '_' after 'predbat') and logs the 'cannot be modified' error, so the new expect_clean assertion fails without the fix; with it, the entity is exempted and then validated normally against its 'Eco' string state (arg_errors is reset per validate run and the placeholder still has to pass the ordinary state checks). The sensor.predbatsolcast2_charge_rate case keeps a look-alike neighbour failing, i.e. the match is a whole name part, not a bare prefix.
  • Test hygiene. Block sits inside the registered test_validate_config (unit_test.py:742), saves/restores dummy_items via _run, and restores self.prefix in a finally.
  • No new crash path. self.prefix is set in reset() (predbat.py:373) which initialize() calls before any validate_config() call site; a null/empty prefix only produces 'sensor.None_', which never matches and cannot throw.
  • The body's Note on a colliding prefix (e.g. prefix: solax exempting sensor.solax_* from this check) is a fair and disclosed trade-off, consistent with what components.py already does for event routing.
  • CI is green at this head; no docs or CONFIG_ITEMS/APPS_SCHEMA impact (bug fix to a check that isn't itself documented, no new setting).

@springfall2008 springfall2008 removed the BOT_REVIEW Trigger an autotriage label Oct 29, 2026
@springfall2008
springfall2008 merged commit 63a6796 into main Nov 1, 2026
3 checks passed
@springfall2008
springfall2008 deleted the fix/validate-placeholder-custom-prefix branch November 1, 2026 16:28
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.

SolaX Cloud Direct-Inverter_mode validation error (read-only sensor)

2 participants