diff --git a/homeassistant/components/config/entity_registry.py b/homeassistant/components/config/entity_registry.py index 15eed32a8cd..13a968dd101 100644 --- a/homeassistant/components/config/entity_registry.py +++ b/homeassistant/components/config/entity_registry.py @@ -1,7 +1,7 @@ """HTTP views to interact with the entity registry.""" import voluptuous as vol -from homeassistant.core import callback +from homeassistant.core import callback, split_entity_id from homeassistant.helpers.entity_registry import async_get_registry from homeassistant.components import websocket_api from homeassistant.components.websocket_api.const import ERR_NOT_FOUND @@ -106,6 +106,11 @@ async def websocket_update_entity(hass, connection, msg): if 'new_entity_id' in msg: changes['new_entity_id'] = msg['new_entity_id'] + if (msg['new_entity_id'] in hass.states.async_entity_ids( + split_entity_id(msg['new_entity_id'])[0])): + connection.send_message(websocket_api.error_message( + msg['id'], ERR_NOT_FOUND, 'Entity is already registered')) + return try: if changes: diff --git a/homeassistant/helpers/entity_registry.py b/homeassistant/helpers/entity_registry.py index fdd9f178321..57c8bcf0af8 100644 --- a/homeassistant/helpers/entity_registry.py +++ b/homeassistant/helpers/entity_registry.py @@ -171,9 +171,7 @@ 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) or new_entity_id in - self.hass.states.async_entity_ids( - split_entity_id(entity_id)[0])): + if self.async_is_registered(new_entity_id): raise ValueError('Entity is already registered') if not valid_entity_id(new_entity_id):