Add unique_id to switch & button entities (UI-manageable, hideable)#212
Open
lebdim wants to merge 2 commits into
Open
Add unique_id to switch & button entities (UI-manageable, hideable)#212lebdim wants to merge 2 commits into
lebdim wants to merge 2 commits into
Conversation
Contributor
Author
|
@ualex73 please check this too |
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.
Summary
Docker container
switchandbuttonentities currently have nounique_id, so they never get an entity-registry entry. As a result they can't be hidden, renamed, assigned to an area, or exposed/hidden from the Wear OS and Android Auto companion apps (both filter on the entity registry). On installs with many containers this clutters those apps with restart buttons and on/off switches that can't be curated.This adds a stable
unique_idto bothDockerContainerSwitchandDockerContainerButton:Why the
entity_idsetter is also neededBoth classes override
entity_idwith a read-only property. Once an entity has aunique_id, Home Assistant's entity platform registers it and then assignsentity.entity_id = entry.entity_id, which raisesAttributeErroron a read-only property and leaves the entity unavailable. Adding anentity_idsetter fixes this.Because the registry derives
suggested_object_idfrom the entity's existingentity_id, existing entity_ids are preserved — no dashboards/automations break on upgrade (verified on a live install: 26 switches + 27 buttons re-registered with identical entity_ids, 0 renamed).Changes
switch.py:_attr_unique_id+entity_idsetter onDockerContainerSwitchbutton.py:_attr_unique_id+entity_idsetter onDockerContainerButtonTesting
Live install (HA 2026.7): after restart all switch/button entities register with a unique_id, are available with correct state, gain UI management (rename/area/hide/expose), and keep their original entity_ids. Sensors (already unique-id-less) are untouched.