Allow changing entity ID (#15637)
* Allow changing entity ID * Add support to websocket command * Address comments * Error handling
This commit is contained in:
1 parent
fbeaa57604
commit
d9cf8fcfe8
7 files changed
+206
-22
No files matched your search
@@ -20,6 +20,7 @@ SCHEMA_WS_UPDATE = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({
|
||||
vol.Required('entity_id'): cv.entity_id,
|
||||
# If passed in, we update value. Passing None will remove old value.
|
||||
vol.Optional('name'): vol.Any(str, None),
|
||||
vol.Optional('new_entity_id'): str,
|
||||
})
|
||||
|
||||
|
||||
@@ -74,13 +75,28 @@ def websocket_update_entity(hass, connection, msg):
|
||||
msg['id'], websocket_api.ERR_NOT_FOUND, 'Entity not found'))
|
||||
return
|
||||
|
||||
entry = registry.async_update_entity(
|
||||
msg['entity_id'], name=msg['name'])
|
||||
connection.send_message_outside(websocket_api.result_message(
|
||||
msg['id'], _entry_dict(entry)
|
||||
))
|
||||
changes = {}
|
||||
|
||||
hass.async_add_job(update_entity())
|
||||
if 'name' in msg:
|
||||
changes['name'] = msg['name']
|
||||
|
||||
if 'new_entity_id' in msg:
|
||||
changes['new_entity_id'] = msg['new_entity_id']
|
||||
|
||||
try:
|
||||
if changes:
|
||||
entry = registry.async_update_entity(
|
||||
msg['entity_id'], **changes)
|
||||
except ValueError as err:
|
||||
connection.send_message_outside(websocket_api.error_message(
|
||||
msg['id'], 'invalid_info', str(err)
|
||||
))
|
||||
else:
|
||||
connection.send_message_outside(websocket_api.result_message(
|
||||
msg['id'], _entry_dict(entry)
|
||||
))
|
||||
|
||||
hass.async_create_task(update_entity())
|
||||
|
||||
|
||||
@callback
|
||||
|
||||
Reference in new issue
Block a user