From 4231775e0492759897b1f1212d0ab58cc3a377ee Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 11 Dec 2018 17:05:49 +0100 Subject: [PATCH] Fail if new entity_id is in hass.states --- homeassistant/components/config/entity_registry.py | 2 +- homeassistant/helpers/entity_registry.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/config/entity_registry.py b/homeassistant/components/config/entity_registry.py index 1ede76d0fd8..15eed32a8cd 100644 --- a/homeassistant/components/config/entity_registry.py +++ b/homeassistant/components/config/entity_registry.py @@ -88,7 +88,7 @@ async def websocket_get_entity(hass, connection, msg): @async_response async def websocket_update_entity(hass, connection, msg): - """Handle get camera thumbnail websocket command. + """Handle update entity websocket command. Async friendly. """ diff --git a/homeassistant/helpers/entity_registry.py b/homeassistant/helpers/entity_registry.py index 57c8bcf0af8..fdd9f178321 100644 --- a/homeassistant/helpers/entity_registry.py +++ b/homeassistant/helpers/entity_registry.py @@ -171,7 +171,9 @@ class EntityRegistry: changes['device_id'] = device_id if new_entity_id is not _UNDEF and new_entity_id != old.entity_id: - if self.async_is_registered(new_entity_id): + if (self.async_is_registered(new_entity_id) or new_entity_id in + self.hass.states.async_entity_ids( + split_entity_id(entity_id)[0])): raise ValueError('Entity is already registered') if not valid_entity_id(new_entity_id):