Update brightness optimistically when turning on a dimmable light (#178505)

Signed-off-by: Stephan Peijnik-Steinwender <speijnik@gmail.com>
This commit is contained in:
Stephan Peijnik-Steinwender
2026-08-20 03:45:57 -04:00
committed by GitHub
parent 05a77490f0
commit 36c35882a9
2 changed files with 42 additions and 0 deletions
@@ -183,6 +183,7 @@ class NetatmoLight(NetatmoReachabilityEntity, LightEntity):
await self.device.async_set_brightness(
round(kwargs[ATTR_BRIGHTNESS] / 2.55)
)
self._attr_brightness = kwargs[ATTR_BRIGHTNESS]
else:
await self.device.async_on()
+41
View File
@@ -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