1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Update config entry id in entity registry (#15531)

This commit is contained in:
Paulus Schoutsen
2018-07-19 08:37:13 +02:00
committed by GitHub
parent 2a76a0852f
commit 8b04d48ffd
2 changed files with 28 additions and 1 deletions

View File

@@ -109,6 +109,12 @@ class EntityRegistry:
"""Get entity. Create if it doesn't exist."""
entity_id = self.async_get_entity_id(domain, platform, unique_id)
if entity_id:
entry = self.entities[entity_id]
if entry.config_entry_id == config_entry_id:
return entry
self._async_update_entity(
entity_id, config_entry_id=config_entry_id)
return self.entities[entity_id]
entity_id = self.async_generate_entity_id(
@@ -129,6 +135,12 @@ class EntityRegistry:
@callback
def async_update_entity(self, entity_id, *, name=_UNDEF):
"""Update properties of an entity."""
return self._async_update_entity(entity_id, name=name)
@callback
def _async_update_entity(self, entity_id, *, name=_UNDEF,
config_entry_id=_UNDEF):
"""Private facing update properties method."""
old = self.entities[entity_id]
changes = {}
@@ -136,6 +148,10 @@ class EntityRegistry:
if name is not _UNDEF and name != old.name:
changes['name'] = name
if (config_entry_id is not _UNDEF and
config_entry_id != old.config_entry_id):
changes['config_entry_id'] = config_entry_id
if not changes:
return old