Skip to content

Commit

Permalink
Prefer effect over other light settings for tplink (home-assistant#85642
Browse files Browse the repository at this point in the history
)
  • Loading branch information
rytilahti authored Feb 14, 2023
1 parent c54500c commit 5335dfb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 6 additions & 3 deletions homeassistant/components/tplink/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,12 @@ def effect(self) -> str | None:
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
Expand All @@ -348,8 +353,6 @@ async def async_turn_on(self, **kwargs: Any) -> None:
)
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)

Expand Down
13 changes: 13 additions & 0 deletions tests/components/tplink/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5335dfb

Please sign in to comment.