Fail if new entity_id is in hass.states

This commit is contained in:
Erik 2018-12-11 17:05:49 +01:00
parent 3e7b908a61
commit 1f8156e26c
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):