From b39846fb6b2675a10363d34d3663fcb957d39f38 Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Fri, 1 Mar 2019 08:11:24 -0500 Subject: [PATCH] add friendly name to devices in the device registry (#21499) switch to name_by_user review comments add device reg info to zha device api --- homeassistant/components/zha/api.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/homeassistant/components/zha/api.py b/homeassistant/components/zha/api.py index df6b6591bac..5895e4c14f8 100644 --- a/homeassistant/components/zha/api.py +++ b/homeassistant/components/zha/api.py @@ -11,6 +11,7 @@ import voluptuous as vol from homeassistant.components import websocket_api import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.device_registry import async_get_registry from .core.const import ( DOMAIN, ATTR_CLUSTER_ID, ATTR_CLUSTER_TYPE, ATTR_ATTRIBUTE, ATTR_VALUE, ATTR_MANUFACTURER, ATTR_COMMAND, ATTR_COMMAND_TYPE, ATTR_ARGS, IN, OUT, @@ -80,9 +81,14 @@ SERVICE_SCHEMAS = { async def websocket_get_devices(hass, connection, msg): """Get ZHA devices.""" zha_gateway = hass.data[DATA_ZHA][DATA_ZHA_GATEWAY] + ha_device_registry = await async_get_registry(hass) devices = [ { **device.device_info, + 'user_given_name': ha_device_registry.async_get_device( + {(DOMAIN, str(device.ieee))}, set()).name_by_user, + 'device_reg_id': ha_device_registry.async_get_device( + {(DOMAIN, str(device.ieee))}, set()).id, 'entities': [{ 'entity_id': entity_ref.reference_id, NAME: entity_ref.device_info[NAME]