diff --git a/homeassistant/components/deconz/light.py b/homeassistant/components/deconz/light.py index f7ae45781acc85..fff0f1681a0b75 100644 --- a/homeassistant/components/deconz/light.py +++ b/homeassistant/components/deconz/light.py @@ -21,7 +21,9 @@ SUPPORT_TRANSITION, LightEntity, ) +from homeassistant.const import ATTR_ENTITY_ID from homeassistant.core import callback +from homeassistant.helpers import entity_registry from homeassistant.helpers.dispatcher import async_dispatcher_connect import homeassistant.util.color as color_util @@ -251,16 +253,40 @@ def __init__(self, device, gateway): super().__init__(device, gateway) + self._device_ids = [] + self._entity_ids = [] + for light_id in device.lights: light = gateway.api.lights[light_id] if light.ZHATYPE == Light.ZHATYPE: self.update_features(light) + self._device_ids.append(light.uniqueid) + + async def async_added_to_hass(self): + """Run when entity about to be added to hass. + + Perform initialization that can only be done in the event loop. + """ + await super().async_added_to_hass() + + # Resolve device unique IDs to entity IDs + self._entity_ids = [] + ent_reg = entity_registry.async_get(self.hass) + for device_id in self._device_ids: + entity_id = ent_reg.async_get_entity_id(DOMAIN, DECONZ_DOMAIN, device_id) + if entity_id: + self._entity_ids.append(entity_id) @property def unique_id(self): """Return a unique identifier for this device.""" return self._unique_id + @property + def icon(self): + """Return the light group icon.""" + return "mdi:lightbulb-group" + @property def device_info(self): """Return a device description for device registry.""" @@ -279,5 +305,6 @@ def extra_state_attributes(self): """Return the device state attributes.""" attributes = dict(super().extra_state_attributes) attributes["all_on"] = self._device.all_on + attributes[ATTR_ENTITY_ID] = self._entity_ids return attributes diff --git a/tests/components/deconz/test_light.py b/tests/components/deconz/test_light.py index 84c7a9b1078696..9074070524daa1 100644 --- a/tests/components/deconz/test_light.py +++ b/tests/components/deconz/test_light.py @@ -143,6 +143,10 @@ async def test_lights_and_groups(hass, aioclient_mock, mock_deconz_websocket): assert hass.states.get("light.light_group").state == STATE_ON assert hass.states.get("light.light_group").attributes["all_on"] is False + assert hass.states.get("light.light_group").attributes["entity_id"] == [ + "light.rgb_light", + "light.tunable_white_light", + ] empty_group = hass.states.get("light.empty_group") assert empty_group is None