From 7a7c2ad416f716c59112ee91032461c770c52dfa Mon Sep 17 00:00:00 2001 From: emontnemery Date: Fri, 14 Dec 2018 10:33:37 +0100 Subject: [PATCH] Fix race in entity_platform.async_add_entities (#19222) --- homeassistant/helpers/entity_platform.py | 3 ++- homeassistant/helpers/entity_registry.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/homeassistant/helpers/entity_platform.py b/homeassistant/helpers/entity_platform.py index ece0fbd071a..9c76d244138 100644 --- a/homeassistant/helpers/entity_platform.py +++ b/homeassistant/helpers/entity_platform.py @@ -297,7 +297,8 @@ class EntityPlatform: self.domain, self.platform_name, entity.unique_id, suggested_object_id=suggested_object_id, config_entry_id=config_entry_id, - device_id=device_id) + device_id=device_id, + known_object_ids=self.entities.keys()) if entry.disabled: self.logger.info( diff --git a/homeassistant/helpers/entity_registry.py b/homeassistant/helpers/entity_registry.py index 57c8bcf0af8..8216681496b 100644 --- a/homeassistant/helpers/entity_registry.py +++ b/homeassistant/helpers/entity_registry.py @@ -117,7 +117,7 @@ class EntityRegistry: @callback def async_get_or_create(self, domain, platform, unique_id, *, suggested_object_id=None, config_entry_id=None, - device_id=None): + device_id=None, known_object_ids=None): """Get entity. Create if it doesn't exist.""" entity_id = self.async_get_entity_id(domain, platform, unique_id) if entity_id: @@ -126,7 +126,8 @@ class EntityRegistry: device_id=device_id) entity_id = self.async_generate_entity_id( - domain, suggested_object_id or '{}_{}'.format(platform, unique_id)) + domain, suggested_object_id or '{}_{}'.format(platform, unique_id), + known_object_ids) entity = RegistryEntry( entity_id=entity_id,