diff --git a/homeassistant/components/tplink/light.py b/homeassistant/components/tplink/light.py index 4bafb0472e9..9a67f8daf4b 100644 --- a/homeassistant/components/tplink/light.py +++ b/homeassistant/components/tplink/light.py @@ -318,15 +318,6 @@ class TPLinkSmartLightStrip(TPLinkSmartBulb): device: SmartLightStrip - def __init__( - self, - device: SmartLightStrip, - coordinator: TPLinkDataUpdateCoordinator, - ) -> None: - """Initialize the smart light strip.""" - super().__init__(device, coordinator) - self._last_custom_effect: dict[str, Any] = {} - @property def supported_features(self) -> int: """Flag supported features.""" @@ -351,6 +342,11 @@ class TPLinkSmartLightStrip(TPLinkSmartBulb): """Turn the light on.""" brightness, transition = self._async_extract_brightness_transition(**kwargs) if ATTR_COLOR_TEMP in kwargs: + if self.effect: + # If there is an effect in progress + # we have to set an HSV value to clear the effect + # before we can set a color temp + await self.device.set_hsv(0, 0, brightness) await self._async_set_color_temp( int(kwargs[ATTR_COLOR_TEMP]), brightness, transition ) @@ -358,20 +354,6 @@ class TPLinkSmartLightStrip(TPLinkSmartBulb): await self._async_set_hsv(kwargs[ATTR_HS_COLOR], brightness, transition) elif ATTR_EFFECT in kwargs: await self.device.set_effect(kwargs[ATTR_EFFECT]) - elif ( - self.device.is_off - and self.device.effect - and self.device.effect["enable"] == 0 - and self.device.effect["name"] - ): - if not self.device.effect["custom"]: - await self.device.set_effect(self.device.effect["name"]) - elif self._last_custom_effect: - await self.device.set_custom_effect(self._last_custom_effect) - # The device does not remember custom effects - # so we must set a default value or it can never turn back on - else: - await self.device.set_hsv(0, 0, 100, transition=transition) else: await self._async_turn_on_with_brightness(brightness, transition) @@ -412,7 +394,6 @@ class TPLinkSmartLightStrip(TPLinkSmartBulb): if transition_range: effect["transition_range"] = transition_range effect["transition"] = 0 - self._last_custom_effect = effect await self.device.set_custom_effect(effect) async def async_set_sequence_effect( @@ -434,5 +415,4 @@ class TPLinkSmartLightStrip(TPLinkSmartBulb): "spread": spread, "direction": direction, } - self._last_custom_effect = effect await self.device.set_custom_effect(effect) diff --git a/homeassistant/components/tplink/manifest.json b/homeassistant/components/tplink/manifest.json index 5ec5166aa1e..3b23f466296 100644 --- a/homeassistant/components/tplink/manifest.json +++ b/homeassistant/components/tplink/manifest.json @@ -3,7 +3,7 @@ "name": "TP-Link Kasa Smart", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/tplink", - "requirements": ["python-kasa==0.4.2"], + "requirements": ["python-kasa==0.4.3"], "codeowners": ["@rytilahti", "@thegardenmonkey"], "dependencies": ["network"], "quality_scale": "platinum", diff --git a/requirements_all.txt b/requirements_all.txt index 65b43070921..194190f886d 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1898,7 +1898,7 @@ python-join-api==0.0.9 python-juicenet==1.1.0 # homeassistant.components.tplink -python-kasa==0.4.2 +python-kasa==0.4.3 # homeassistant.components.lirc # python-lirc==1.2.3 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 8486ad98325..bfdb8193490 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1242,7 +1242,7 @@ python-izone==1.2.3 python-juicenet==1.1.0 # homeassistant.components.tplink -python-kasa==0.4.2 +python-kasa==0.4.3 # homeassistant.components.xiaomi_miio python-miio==0.5.11 diff --git a/tests/components/tplink/test_light.py b/tests/components/tplink/test_light.py index db2fdbebb41..9975aa1c660 100644 --- a/tests/components/tplink/test_light.py +++ b/tests/components/tplink/test_light.py @@ -412,6 +412,19 @@ async def test_smart_strip_effects(hass: HomeAssistant) -> None: assert state.attributes[ATTR_EFFECT] == "Effect1" assert state.attributes[ATTR_EFFECT_LIST] == ["Effect1", "Effect2"] + # Ensure setting color temp when an effect + # is in progress calls set_hsv to clear the effect + await hass.services.async_call( + LIGHT_DOMAIN, + "turn_on", + {ATTR_ENTITY_ID: entity_id, ATTR_COLOR_TEMP: 250}, + blocking=True, + ) + strip.set_hsv.assert_called_once_with(0, 0, None) + strip.set_color_temp.assert_called_once_with(4000, brightness=None, transition=None) + strip.set_hsv.reset_mock() + strip.set_color_temp.reset_mock() + await hass.services.async_call( LIGHT_DOMAIN, "turn_on", @@ -444,8 +457,8 @@ async def test_smart_strip_effects(hass: HomeAssistant) -> None: {ATTR_ENTITY_ID: entity_id}, blocking=True, ) - strip.set_effect.assert_called_once_with("Effect1") - strip.set_effect.reset_mock() + strip.turn_on.assert_called_once() + strip.turn_on.reset_mock() strip.is_off = False strip.is_on = True @@ -539,24 +552,8 @@ async def test_smart_strip_custom_random_effect(hass: HomeAssistant) -> None: {ATTR_ENTITY_ID: entity_id}, blocking=True, ) - strip.set_custom_effect.assert_called_once_with( - { - "custom": 1, - "id": "yMwcNpLxijmoKamskHCvvravpbnIqAIN", - "brightness": 100, - "name": "Custom", - "segments": [0], - "expansion_strategy": 1, - "enable": 1, - "duration": 0, - "transition": 0, - "type": "random", - "init_states": [[340, 20, 50]], - "random_seed": 100, - "backgrounds": [(340, 20, 50), (20, 50, 50), (0, 100, 50)], - } - ) - strip.set_custom_effect.reset_mock() + strip.turn_on.assert_called_once() + strip.turn_on.reset_mock() await hass.services.async_call( DOMAIN, @@ -632,8 +629,8 @@ async def test_smart_strip_custom_random_effect_at_start(hass: HomeAssistant) -> {ATTR_ENTITY_ID: entity_id}, blocking=True, ) - strip.set_hsv.assert_called_with(0, 0, 100, transition=None) - strip.set_hsv.reset_mock() + strip.turn_on.assert_called_once() + strip.turn_on.reset_mock() async def test_smart_strip_custom_sequence_effect(hass: HomeAssistant) -> None: