Improve check for duplicated entity_id (#19194)

* Fail if new entity_id is in hass.states

* Move check to websocket

* Review comments
This commit is contained in:
Paulus Schoutsen 2018-12-13 20:57:33 +01:00 committed by GitHub
commit eada1a184c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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.
"""
@ -106,6 +106,10 @@ async def websocket_update_entity(hass, connection, msg):
if 'new_entity_id' in msg:
changes['new_entity_id'] = msg['new_entity_id']
if hass.states.get(msg['new_entity_id']) is not None:
connection.send_message(websocket_api.error_message(
msg['id'], 'invalid_info', 'Entity is already registered'))
return
try:
if changes: