Repository navigation
fix(config): exempt control placeholders named with a custom prefix from the "cannot be modified" check - #5845
Merged
Conversation
…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>
springfall2008
left a comment
Owner
There was a problem hiding this comment.
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) assensor.{self.base.prefix}_{inverter_type}_{id}_{entity_name}— the same shape as the reporter'ssensor.predbatsolcast_SolaxCloud_0_inverter_modein #5242 (SolaxCloudis anINVERTER_DEFkey,config.py:2491), so exemptingsensor.<prefix>_addresses the reported case, and keeps the literalsensor.predbat_for configs copied from a default-prefix install. No other hard-codedsensor.predbat_validation remains in non-test code —components.pyalready 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 oldstartswith('sensor.predbat_')(no'_'after'predbat') and logs the 'cannot be modified' error, so the newexpect_cleanassertion fails without the fix; with it, the entity is exempted and then validated normally against its'Eco'string state (arg_errorsis reset per validate run and the placeholder still has to pass the ordinary state checks). Thesensor.predbatsolcast2_charge_ratecase 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/restoresdummy_itemsvia_run, and restoresself.prefixin afinally. - No new crash path.
self.prefixis set inreset()(predbat.py:373) whichinitialize()calls before anyvalidate_config()call site; a null/emptyprefixonly produces'sensor.None_', which never matches and cannot throw. - The body's Note on a colliding prefix (e.g.
prefix: solaxexemptingsensor.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_SCHEMAimpact (bug fix to a check that isn't itself documented, no new setting).
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.
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-codedsensor.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_modeon SolaX Cloud), apps.yaml reported a false "cannot be modified" error.Change
Accept
sensor.<prefix>_as well as the existingsensor.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'ssensor.solax_*entities from this check. It's an unlikely setup.🤖 Generated with Claude Code