mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
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:
parent
221893c1d7
commit
28ef898775
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user