mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
Update brightness optimistically when turning on a dimmable light (#178505)
Signed-off-by: Stephan Peijnik-Steinwender <speijnik@gmail.com>
This commit is contained in:
@@ -211,3 +211,44 @@ async def test_light_setup_and_services(
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def test_dimmable_light_turn_on_updates_brightness_optimistically(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry, netatmo_auth: AsyncMock
|
||||
) -> None:
|
||||
"""Test that turning on a dimmable light with a brightness updates state immediately.
|
||||
|
||||
The Netatmo API doesn't push brightness changes back until the next poll,
|
||||
which can be several minutes away, so the new brightness must be reflected
|
||||
optimistically instead of waiting for that poll.
|
||||
"""
|
||||
with selected_platforms(["light"]):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
light_entity = "light.unknown_00_11_22_33_00_11_45_fe"
|
||||
|
||||
with patch("pyatmo.home.Home.async_set_state") as mock_set_state:
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
{ATTR_ENTITY_ID: light_entity, "brightness": 128},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
mock_set_state.assert_called_once_with(
|
||||
{
|
||||
"modules": [
|
||||
{
|
||||
"id": "00:11:22:33:00:11:45:fe",
|
||||
"brightness": round(128 / 2.55),
|
||||
"bridge": "12:34:56:80:60:40",
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
state = hass.states.get(light_entity)
|
||||
assert state.state == "on"
|
||||
assert state.attributes["brightness"] == 128
|
||||
|
||||
Reference in New Issue
Block a user