Improve error handling (#32182)

This commit is contained in:
Erik Montnemery 2020-02-25 19:44:24 +01:00 committed by GitHub
parent 2365e2e8cf
commit 2d6b80470f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 2 deletions

View file

@ -1272,13 +1272,23 @@ async def websocket_remove_device(hass, connection, msg):
dev_registry = await get_dev_reg(hass)
device = dev_registry.async_get(device_id)
if not device:
connection.send_error(
msg["id"], websocket_api.const.ERR_NOT_FOUND, "Device not found"
)
return
for config_entry in device.config_entries:
config_entry = hass.config_entries.async_get_entry(config_entry)
# Only delete the device if it belongs to an MQTT device entry
if config_entry.domain == DOMAIN:
dev_registry.async_remove_device(device_id)
connection.send_message(websocket_api.result_message(msg["id"]))
break
return
connection.send_error(
msg["id"], websocket_api.const.ERR_NOT_FOUND, "Non MQTT device"
)
@websocket_api.async_response