From b3b470757980db546e2c1c131a53bd46039ed81b Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Thu, 23 Jun 2022 20:26:51 +0200 Subject: [PATCH] Fix deCONZ group state regression (#73907) --- homeassistant/components/deconz/gateway.py | 1 - homeassistant/components/deconz/light.py | 25 ++++++++++++++++++- homeassistant/components/deconz/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/deconz/gateway.py b/homeassistant/components/deconz/gateway.py index 5890e372e66..c94b2c6d86d 100644 --- a/homeassistant/components/deconz/gateway.py +++ b/homeassistant/components/deconz/gateway.py @@ -287,7 +287,6 @@ async def get_deconz_session( config[CONF_HOST], config[CONF_PORT], config[CONF_API_KEY], - legacy_add_device=False, ) try: async with async_timeout.timeout(10): diff --git a/homeassistant/components/deconz/light.py b/homeassistant/components/deconz/light.py index 53773369176..0cca007742a 100644 --- a/homeassistant/components/deconz/light.py +++ b/homeassistant/components/deconz/light.py @@ -105,7 +105,10 @@ async def async_setup_entry( @callback def async_add_group(_: EventType, group_id: str) -> None: - """Add group from deCONZ.""" + """Add group from deCONZ. + + Update group states based on its sum of related lights. + """ if ( not gateway.option_allow_deconz_groups or (group := gateway.api.groups[group_id]) @@ -113,6 +116,16 @@ async def async_setup_entry( ): return + first = True + for light_id in group.lights: + if ( + (light := gateway.api.lights.lights.get(light_id)) + and light.ZHATYPE == Light.ZHATYPE + and light.reachable + ): + group.update_color_state(light, update_all_attributes=first) + first = False + async_add_entities([DeconzGroup(group, gateway)]) config_entry.async_on_unload( @@ -289,6 +302,16 @@ class DeconzLight(DeconzBaseLight[Light]): """Return the coldest color_temp that this light supports.""" return self._device.min_color_temp or super().min_mireds + @callback + def async_update_callback(self) -> None: + """Light state will also reflect in relevant groups.""" + super().async_update_callback() + + if self._device.reachable and "attr" not in self._device.changed_keys: + for group in self.gateway.api.groups.values(): + if self._device.resource_id in group.lights: + group.update_color_state(self._device) + class DeconzGroup(DeconzBaseLight[Group]): """Representation of a deCONZ group.""" diff --git a/homeassistant/components/deconz/manifest.json b/homeassistant/components/deconz/manifest.json index ce10845a5b1..09dcc190a4f 100644 --- a/homeassistant/components/deconz/manifest.json +++ b/homeassistant/components/deconz/manifest.json @@ -3,7 +3,7 @@ "name": "deCONZ", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/deconz", - "requirements": ["pydeconz==94"], + "requirements": ["pydeconz==95"], "ssdp": [ { "manufacturer": "Royal Philips Electronics", diff --git a/requirements_all.txt b/requirements_all.txt index 8935161ae1e..705d5341cb1 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1441,7 +1441,7 @@ pydaikin==2.7.0 pydanfossair==0.1.0 # homeassistant.components.deconz -pydeconz==94 +pydeconz==95 # homeassistant.components.delijn pydelijn==1.0.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index d4f43b284c0..b22bce40639 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -968,7 +968,7 @@ pycoolmasternet-async==0.1.2 pydaikin==2.7.0 # homeassistant.components.deconz -pydeconz==94 +pydeconz==95 # homeassistant.components.dexcom pydexcom==0.2.3