mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Workaround brightness transition delay from off in older yeelight models (#58774)
This commit is contained in:
parent
f94bbf351d
commit
faecc90b38
@ -35,6 +35,20 @@ _LOGGER = logging.getLogger(__name__)
|
||||
STATE_CHANGE_TIME = 0.40 # seconds
|
||||
POWER_STATE_CHANGE_TIME = 1 # seconds
|
||||
|
||||
#
|
||||
# These models do not transition correctly when turning on, and
|
||||
# yeelight is no longer updating the firmware on older devices
|
||||
#
|
||||
# https://github.com/home-assistant/core/issues/58315
|
||||
#
|
||||
# The problem can be worked around by always setting the brightness
|
||||
# even when the bulb is reporting the brightness is already at the
|
||||
# desired level.
|
||||
#
|
||||
MODELS_WITH_DELAYED_ON_TRANSITION = {
|
||||
"color", # YLDP02YL
|
||||
}
|
||||
|
||||
DOMAIN = "yeelight"
|
||||
DATA_YEELIGHT = DOMAIN
|
||||
DATA_UPDATED = "yeelight_{}_data_updated"
|
||||
|
@ -63,6 +63,7 @@ from . import (
|
||||
DATA_DEVICE,
|
||||
DATA_UPDATED,
|
||||
DOMAIN,
|
||||
MODELS_WITH_DELAYED_ON_TRANSITION,
|
||||
POWER_STATE_CHANGE_TIME,
|
||||
YEELIGHT_FLOW_TRANSITION_SCHEMA,
|
||||
YeelightEntity,
|
||||
@ -614,7 +615,10 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
|
||||
"""Set bulb brightness."""
|
||||
if not brightness:
|
||||
return
|
||||
if math.floor(self.brightness) == math.floor(brightness):
|
||||
if (
|
||||
math.floor(self.brightness) == math.floor(brightness)
|
||||
and self._bulb.model not in MODELS_WITH_DELAYED_ON_TRANSITION
|
||||
):
|
||||
_LOGGER.debug("brightness already set to: %s", brightness)
|
||||
# Already set, and since we get pushed updates
|
||||
# we avoid setting it again to ensure we do not
|
||||
|
@ -641,6 +641,25 @@ async def test_state_already_set_avoid_ratelimit(hass: HomeAssistant):
|
||||
mocked_bulb.async_set_rgb.reset_mock()
|
||||
mocked_bulb.last_properties["flowing"] = "0"
|
||||
|
||||
mocked_bulb.model = "color" # color model needs a workaround (see MODELS_WITH_DELAYED_ON_TRANSITION)
|
||||
await hass.services.async_call(
|
||||
"light",
|
||||
SERVICE_TURN_ON,
|
||||
{
|
||||
ATTR_ENTITY_ID: ENTITY_LIGHT,
|
||||
ATTR_BRIGHTNESS_PCT: PROPERTIES["bright"],
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert mocked_bulb.async_set_hsv.mock_calls == []
|
||||
assert mocked_bulb.async_set_rgb.mock_calls == []
|
||||
assert mocked_bulb.async_set_color_temp.mock_calls == []
|
||||
assert mocked_bulb.async_set_brightness.mock_calls == [
|
||||
call(pytest.approx(50.1, 0.1), duration=350, light_type=ANY)
|
||||
]
|
||||
mocked_bulb.async_set_brightness.reset_mock()
|
||||
|
||||
mocked_bulb.model = "colora" # colora does not need a workaround
|
||||
await hass.services.async_call(
|
||||
"light",
|
||||
SERVICE_TURN_ON,
|
||||
@ -683,6 +702,7 @@ async def test_state_already_set_avoid_ratelimit(hass: HomeAssistant):
|
||||
assert mocked_bulb.async_set_brightness.mock_calls == []
|
||||
|
||||
mocked_bulb.last_properties["flowing"] = "1"
|
||||
|
||||
await hass.services.async_call(
|
||||
"light",
|
||||
SERVICE_TURN_ON,
|
||||
|
Loading…
x
Reference in New Issue
Block a user