Move check to websocket

pull/19194/head
Erik 2018-12-11 20:20:57 +01:00
parent 1f8156e26c
commit c7492b0feb
2 changed files with 7 additions and 4 deletions

View File

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

View File

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