diff --git a/homeassistant/components/lutron/light.py b/homeassistant/components/lutron/light.py index 103bcb1e39d..f4088d687cd 100644 --- a/homeassistant/components/lutron/light.py +++ b/homeassistant/components/lutron/light.py @@ -9,7 +9,14 @@ from typing import Any from pylutron import Output from homeassistant.components.automation import automations_with_entity -from homeassistant.components.light import ATTR_BRIGHTNESS, ColorMode, LightEntity +from homeassistant.components.light import ( + ATTR_BRIGHTNESS, + ATTR_FLASH, + ATTR_TRANSITION, + ColorMode, + LightEntity, + LightEntityFeature, +) from homeassistant.components.script import scripts_with_entity from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform @@ -101,6 +108,7 @@ class LutronLight(LutronDevice, LightEntity): _attr_color_mode = ColorMode.BRIGHTNESS _attr_supported_color_modes = {ColorMode.BRIGHTNESS} + _attr_supported_features = LightEntityFeature.TRANSITION | LightEntityFeature.FLASH _lutron_device: Output _prev_brightness: int | None = None _attr_name = None @@ -123,14 +131,20 @@ class LutronLight(LutronDevice, LightEntity): severity=IssueSeverity.WARNING, translation_key="deprecated_light_fan_on", ) - if ATTR_BRIGHTNESS in kwargs and self._lutron_device.is_dimmable: - brightness = kwargs[ATTR_BRIGHTNESS] - elif self._prev_brightness == 0: - brightness = 255 / 2 + if flash := kwargs.get(ATTR_FLASH): + self._lutron_device.flash(0.5 if flash == "short" else 1.5) else: - brightness = self._prev_brightness - self._prev_brightness = brightness - self._lutron_device.level = to_lutron_level(brightness) + if ATTR_BRIGHTNESS in kwargs and self._lutron_device.is_dimmable: + brightness = kwargs[ATTR_BRIGHTNESS] + elif self._prev_brightness == 0: + brightness = 255 / 2 + else: + brightness = self._prev_brightness + self._prev_brightness = brightness + args = {"new_level": brightness} + if ATTR_TRANSITION in kwargs: + args["fade_time_seconds"] = kwargs[ATTR_TRANSITION] + self._lutron_device.set_level(**args) def turn_off(self, **kwargs: Any) -> None: """Turn the light off.""" @@ -145,7 +159,10 @@ class LutronLight(LutronDevice, LightEntity): severity=IssueSeverity.WARNING, translation_key="deprecated_light_fan_off", ) - self._lutron_device.level = 0 + args = {"new_level": 0} + if ATTR_TRANSITION in kwargs: + args["fade_time_seconds"] = kwargs[ATTR_TRANSITION] + self._lutron_device.set_level(**args) @property def extra_state_attributes(self) -> Mapping[str, Any] | None: