Fail if new entity_id is in hass.states

This commit is contained in:
Erik 2018-12-11 17:05:49 +01:00 committed by Paulus Schoutsen
parent 14d90b5484
commit 4231775e04
2 changed files with 4 additions and 2 deletions

View file

@ -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.
"""

View file

@ -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):