Prefer effect over other light settings for tplink (#85642)

This commit is contained in:
Teemu R 2023-02-14 17:29:11 +01:00 committed by GitHub
parent c54500cb1f
commit 5335dfbc67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -337,7 +337,12 @@ class TPLinkSmartLightStrip(TPLinkSmartBulb):
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the light on."""
brightness, transition = self._async_extract_brightness_transition(**kwargs)
if ATTR_COLOR_TEMP in kwargs:
if ATTR_EFFECT in kwargs:
await self.device.set_effect(kwargs[ATTR_EFFECT])
# We need to set the brightness separately until upstream allows defining it for set_effect.
if brightness is not None:
await self._async_turn_on_with_brightness(brightness, transition)
elif 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
@ -348,8 +353,6 @@ class TPLinkSmartLightStrip(TPLinkSmartBulb):
)
elif ATTR_HS_COLOR in kwargs:
await self._async_set_hsv(kwargs[ATTR_HS_COLOR], brightness, transition)
elif ATTR_EFFECT in kwargs:
await self.device.set_effect(kwargs[ATTR_EFFECT])
else:
await self._async_turn_on_with_brightness(brightness, transition)

View File

@ -434,6 +434,19 @@ async def test_smart_strip_effects(hass: HomeAssistant) -> None:
strip.set_effect.assert_called_once_with("Effect2")
strip.set_effect.reset_mock()
# Setting an effect with brightness calls set_brightness implicitly
await hass.services.async_call(
LIGHT_DOMAIN,
"turn_on",
{ATTR_ENTITY_ID: entity_id, ATTR_EFFECT: "Effect2", ATTR_BRIGHTNESS: 255},
blocking=True,
)
strip.set_effect.assert_called_once_with("Effect2")
strip.set_effect.reset_mock()
strip.set_brightness.assert_called_with(100, transition=None)
strip.set_brightness.reset_mock()
strip.effect = {"name": "Effect1", "enable": 0, "custom": 0}
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done()