Skip to content

Conversation

@jbouwh
Copy link
Contributor

@jbouwh jbouwh commented Sep 4, 2025

Proposed change

When a user changes the entity_id of enabled entity, that has not been loaded yet, the old restored state not cleaned up. This can cause issues with integrations like MQTT that can have entities in the entity registry that are not loaded (yet). After the entity has been renamed (e.g. via the UI or via discovery, the change cannot be reverted, because the old restored state is still loaded after renaming). This PR cleans up the old entity state in case the old entity had a restored state during a rename of the entity_id and sets an unavailable state to the entity with the new ID.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@jbouwh jbouwh requested a review from a team as a code owner September 4, 2025 15:29
@jbouwh jbouwh marked this pull request as draft September 4, 2025 16:45
Copy link
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

Well spotted @jbouwh 👍 👍

The solution needs some tweaks though

@jbouwh jbouwh changed the title Fix update of the entity ID does not clean up the old state Fix update of the entity ID does not clean up an old restored state Sep 4, 2025
@jbouwh jbouwh marked this pull request as ready for review September 5, 2025 10:05
@home-assistant
Copy link

home-assistant bot commented Sep 5, 2025

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant bot marked this pull request as draft September 5, 2025 10:18
@jbouwh jbouwh marked this pull request as ready for review September 5, 2025 11:20
@home-assistant home-assistant bot requested a review from emontnemery September 5, 2025 11:20
Co-authored-by: Erik Montnemery <erik@montnemery.com>
Copy link
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

LGTM! I'd like a second opinion before merging though.

@emontnemery emontnemery added the second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. label Sep 5, 2025
@emontnemery emontnemery added this to the 2025.9.1 milestone Sep 5, 2025
@jbouwh jbouwh modified the milestones: 2025.9.1, 2025.9.2 Sep 5, 2025
@jbouwh
Copy link
Contributor Author

jbouwh commented Sep 5, 2025

CI test failure seems not related

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Makes sense.

@MartinHjelmare MartinHjelmare removed the second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. label Sep 8, 2025
@jbouwh
Copy link
Contributor Author

jbouwh commented Sep 8, 2025

Thanks!

@jbouwh jbouwh merged commit 1536375 into dev Sep 8, 2025
48 checks passed
@jbouwh jbouwh deleted the fix-entity_registry-update-entity_id branch September 8, 2025 10:48
oswinmurzello pushed a commit to oswinmurzello/core that referenced this pull request Sep 8, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Sep 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants