From b8ae883f1813240ec58f0b3e9a2e03d22af0abdd Mon Sep 17 00:00:00 2001 From: TheJulianJES Date: Mon, 25 Jul 2022 14:13:01 +0200 Subject: [PATCH] Set min transition time for Sengled lights in ZHA groups (#75644) * Set min transition time for Sengled lights in ZHA groups * Change test to expect correct min transition time for group with Sengled light * Fix turn_off with transition 0 for Sengled lights --- homeassistant/components/zha/light.py | 13 +++++++++---- tests/components/zha/test_light.py | 10 +++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/zha/light.py b/homeassistant/components/zha/light.py index 6c26e17188b..190e0b2319d 100644 --- a/homeassistant/components/zha/light.py +++ b/homeassistant/components/zha/light.py @@ -74,6 +74,7 @@ STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.LIGHT) GROUP_MATCH = functools.partial(ZHA_ENTITIES.group_match, Platform.LIGHT) PARALLEL_UPDATES = 0 SIGNAL_LIGHT_GROUP_STATE_CHANGED = "zha_light_group_state_changed" +DEFAULT_MIN_TRANSITION_MANUFACTURERS = {"Sengled"} COLOR_MODES_GROUP_LIGHT = {ColorMode.COLOR_TEMP, ColorMode.XY} SUPPORT_GROUP_LIGHT = ( @@ -379,7 +380,7 @@ class BaseLight(LogMixin, light.LightEntity): # is not none looks odd here but it will override built in bulb transition times if we pass 0 in here if transition is not None and supports_level: result = await self._level_channel.move_to_level_with_on_off( - 0, transition * 10 + 0, transition * 10 or self._DEFAULT_MIN_TRANSITION_TIME ) else: result = await self._on_off_channel.off() @@ -670,10 +671,10 @@ class ForceOnLight(Light): @STRICT_MATCH( channel_names=CHANNEL_ON_OFF, aux_channels={CHANNEL_COLOR, CHANNEL_LEVEL}, - manufacturers={"Sengled"}, + manufacturers=DEFAULT_MIN_TRANSITION_MANUFACTURERS, ) -class SengledLight(Light): - """Representation of a Sengled light which does not react to move_to_color_temp with 0 as a transition.""" +class MinTransitionLight(Light): + """Representation of a light which does not react to any "move to" calls with 0 as a transition.""" _DEFAULT_MIN_TRANSITION_TIME = 1 @@ -688,6 +689,10 @@ class LightGroup(BaseLight, ZhaGroupEntity): """Initialize a light group.""" super().__init__(entity_ids, unique_id, group_id, zha_device, **kwargs) group = self.zha_device.gateway.get_group(self._group_id) + self._DEFAULT_MIN_TRANSITION_TIME = any( # pylint: disable=invalid-name + member.device.manufacturer in DEFAULT_MIN_TRANSITION_MANUFACTURERS + for member in group.members + ) self._on_off_channel = group.endpoint[OnOff.cluster_id] self._level_channel = group.endpoint[LevelControl.cluster_id] self._color_channel = group.endpoint[Color.cluster_id] diff --git a/tests/components/zha/test_light.py b/tests/components/zha/test_light.py index c5b02f1a02f..94f0c96c38d 100644 --- a/tests/components/zha/test_light.py +++ b/tests/components/zha/test_light.py @@ -1184,7 +1184,7 @@ async def async_test_off_from_hass(hass, cluster, entity_id): async def async_test_level_on_off_from_hass( - hass, on_off_cluster, level_cluster, entity_id + hass, on_off_cluster, level_cluster, entity_id, expected_default_transition: int = 0 ): """Test on off functionality from hass.""" @@ -1259,7 +1259,7 @@ async def async_test_level_on_off_from_hass( 4, level_cluster.commands_by_name["move_to_level_with_on_off"].schema, 10, - 0, + expected_default_transition, expect_reply=True, manufacturer=None, tries=1, @@ -1417,7 +1417,11 @@ async def test_zha_group_light_entity( # test turning the lights on and off from the HA await async_test_level_on_off_from_hass( - hass, group_cluster_on_off, group_cluster_level, group_entity_id + hass, + group_cluster_on_off, + group_cluster_level, + group_entity_id, + expected_default_transition=1, # a Sengled light is in that group and needs a minimum 0.1s transition ) # test getting a brightness change from the network