Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions homeassistant/components/deconz/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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."""
Expand All @@ -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
4 changes: 4 additions & 0 deletions tests/components/deconz/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down