refactor(coordinator): ♻️ declare entity_active gates on the descriptions - #817
Merged
Merged
Conversation
…ions - move the Smart Grid (P1030), mixing-circuit cooling (P0042/P0130/P0780) and room thermostat (P0033) gates out of coordinator.entity_active into entity_active_key + entity_active_formula on their descriptions - add an `in a,b,c` formula operator, each item compared as `==`, so a raw code and its decoded name can share one list - a declared gate also requires the entity's own register to be returned (#738), generalising the check that was Smart Grid only - drop _room_thermostat_present and the P1030 branch of _special_visibility; entity_active keeps only firmware, device and solar gates - behaviour: room thermostat entities are no longer created when P0033 is absent; mixing-circuit cooling targets now also pass the device check and need their own register - tests exercise the real predefined descriptions; guards forbid parameters as visibility gates and check declared gates survive decoded names Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- fail when a numeric gate threshold sits on a register that decodes to a name: "none" != 0 compares as strings and is True, so the entities would return on every install (P0033 is the likely candidate) - fail when a declared formula does not parse, which falls through to True - fail when entity_active_key sits on a description without a register of its own, which could then never exist - update comments that still called the room-thermostat entities V0122-gated Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
🔍 What this fixes
#816 added
entity_active_key: a description can declare "this entity only exists if register X says so", andentity_active_formulachecks that register instead of the entity's own. Three older gates still lived incoordinator.entity_activeas per-register special cases:Every new niche feature added another branch there, and the gate sat far from the entity it governs. This PR moves all three onto their descriptions. Only the gates that cannot be written as a single register comparison stay in the coordinator: firmware, device, and solar (a heuristic over several registers).
✨ Changes
coordinator.pyentity_active, along with_room_thermostat_present()and the P1030 branch of_special_visibility. The coordinator shrinks by about 40 lines.in a,b,c. Each item is compared exactly as==would compare it, so a raw code and its decoded name can share one list.entity_active_keyis set, the entity's own register must also be returned. This was Smart Grid-only before (fix(coordinator): 🐛 entity_active creates entities for registers the controller does not expose #738); every declared gate now gets it.Declarations in
number_entities_predefined.py/sensor_entities_predefined.py:entity_active_key=P1030,"!= off"entity_active_key=P0042/P0130/P0780,"in 3,4,cooling,heating_cooling"entity_active_key=P0033,"!= 0"The MK gate lists the names as well as the codes, so it keeps working if the type register later gets a selection datatype (When cooling is active status flips between cooling and no_request #773). For Smart Grid, P1030 is always decoded by
SmartGridMode, so off reads"off". Thesmart_grid_enabledhelper is unchanged.Behaviour: the room thermostat entities are no longer created on a controller that does not report parameter 33, and the mixing-circuit cooling targets are no longer created when their own register is missing (such an entity used to stay on unknown). No unit in the diagnostics corpus is affected.
🧪 Tests
TestDeclaredActiveGates), so dropping a declaration now fails a test. There are also new tests for theinoperator.test_predefined_entities.py:LuxParametermay be used as avisibilitygate; existence belongs inentity_active_key"none" != 0compares as strings and is True, and the entities return on every install. Verified to fail when P0033 is given a selection datatype.entity_active_keymust not sit on a description without a register of its ownFull run: 1404 passed, 1 skipped, coverage 100%.
ruff check,ruff format --check,basedpyright(0 errors) andcodespellare clean.🤖 Generated with Claude Code