1
mirror of https://github.com/home-assistant/core synced 2024-07-24 16:42:06 +02:00

Base deCONZ group supported features on the sum of all its lights (#45440)

This commit is contained in:
Robert Svensson 2021-01-22 23:39:34 +01:00 committed by GitHub
parent 57fa7f926a
commit 22a6e55e70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 6 deletions

View File

@ -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."""

View File

@ -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