Support lutron transition time and flash for lights (#109185)

* support transition time for lights

* bug fix and support for FLASH

* updated to flash() to match changes coming in pylutron

* bumped pylutron version in anticipation of next release

* Update manifest.json

* Update requirements_all.txt

* Update requirements_test_all.txt

* Update requirements_test_all.txt

* nits and code improves
This commit is contained in:
wilburCforce 2024-03-14 17:07:16 -05:00 committed by GitHub
parent 221893c1d7
commit 28ef898775
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

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