Skip to content

Add unique_id to switch & button entities (UI-manageable, hideable)#212

Open
lebdim wants to merge 2 commits into
ualex73:masterfrom
lebdim:feature/entity-unique-id
Open

Add unique_id to switch & button entities (UI-manageable, hideable)#212
lebdim wants to merge 2 commits into
ualex73:masterfrom
lebdim:feature/entity-unique-id

Conversation

@lebdim

@lebdim lebdim commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Docker container switch and button entities currently have no unique_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_id to both DockerContainerSwitch and DockerContainerButton:

{instance}_{container}_switch      # switch
{instance}_{container}_restart     # button

Why the entity_id setter is also needed

Both classes override entity_id with a read-only property. Once an entity has a unique_id, Home Assistant's entity platform registers it and then assigns entity.entity_id = entry.entity_id, which raises AttributeError on a read-only property and leaves the entity unavailable. Adding an entity_id setter fixes this.

Because the registry derives suggested_object_id from the entity's existing entity_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_id setter on DockerContainerSwitch
  • button.py: _attr_unique_id + entity_id setter on DockerContainerButton

Testing

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.

@lebdim

lebdim commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@ualex73 please check this too

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.

1 participant