diff --git a/homeassistant/components/deconz/light.py b/homeassistant/components/deconz/light.py index bba868b9ea48..9080160c76fe 100644 --- a/homeassistant/components/deconz/light.py +++ b/homeassistant/components/deconz/light.py @@ -1,4 +1,7 @@ """Support for deCONZ lights.""" + +from pydeconz.light import Light + from homeassistant.components.light import ( ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, @@ -105,21 +108,22 @@ class DeconzBaseLight(DeconzDevice, LightEntity): super().__init__(device, gateway) self._features = 0 + self.update_features(self._device) - if self._device.brightness is not None: + def update_features(self, device): + """Calculate supported features of device.""" + if device.brightness is not None: self._features |= SUPPORT_BRIGHTNESS self._features |= SUPPORT_FLASH self._features |= SUPPORT_TRANSITION - if self._device.ct is not None: + if device.ct is not None: self._features |= SUPPORT_COLOR_TEMP - if self._device.xy is not None or ( - self._device.hue is not None and self._device.sat is not None - ): + if device.xy is not None or (device.hue is not None and device.sat is not None): self._features |= SUPPORT_COLOR - if self._device.effect is not None: + if device.effect is not None: self._features |= SUPPORT_EFFECT @property @@ -251,6 +255,11 @@ class DeconzGroup(DeconzBaseLight): super().__init__(device, gateway) + for light_id in device.lights: + light = gateway.api.lights[light_id] + if light.ZHATYPE == Light.ZHATYPE: + self.update_features(light) + @property def unique_id(self): """Return a unique identifier for this device.""" diff --git a/tests/components/deconz/test_light.py b/tests/components/deconz/test_light.py index 5935769d6e2b..20fb50247eeb 100644 --- a/tests/components/deconz/test_light.py +++ b/tests/components/deconz/test_light.py @@ -521,3 +521,62 @@ async def test_non_color_light_reports_color(hass): with pytest.raises(KeyError): assert hass.states.get("light.all").attributes[ATTR_COLOR_TEMP] assert hass.states.get("light.all").attributes[ATTR_HS_COLOR] + + +async def test_verify_group_supported_features(hass): + """Test that group supported features reflect what included lights support.""" + data = deepcopy(DECONZ_WEB_REQUEST) + data["groups"] = deepcopy( + { + "1": { + "id": "Group1", + "name": "group", + "type": "LightGroup", + "state": {"all_on": False, "any_on": True}, + "action": {}, + "scenes": [], + "lights": ["1", "2", "3"], + }, + } + ) + data["lights"] = deepcopy( + { + "1": { + "id": "light1", + "name": "Dimmable light", + "state": {"on": True, "bri": 255, "reachable": True}, + "type": "Light", + "uniqueid": "00:00:00:00:00:00:00:01-00", + }, + "2": { + "id": "light2", + "name": "Color light", + "state": { + "on": True, + "bri": 100, + "colormode": "xy", + "effect": "colorloop", + "xy": (500, 500), + "reachable": True, + }, + "type": "Extended color light", + "uniqueid": "00:00:00:00:00:00:00:02-00", + }, + "3": { + "ctmax": 454, + "ctmin": 155, + "id": "light3", + "name": "Tunable light", + "state": {"on": True, "colormode": "ct", "ct": 2500, "reachable": True}, + "type": "Tunable white light", + "uniqueid": "00:00:00:00:00:00:00:03-00", + }, + } + ) + await setup_deconz_integration(hass, get_state_response=data) + + assert len(hass.states.async_all()) == 4 + + group = hass.states.get("light.group") + assert group.state == STATE_ON + assert group.attributes[ATTR_SUPPORTED_FEATURES] == 63