Skip to content

Commit 7681fb0

Browse files
authored
Fix light groups not restoring off_brightness (#78)
* Fix light groups not restoring `off_brightness` * Modify test
1 parent a880209 commit 7681fb0

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

tests/test_light.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,8 @@ async def test_zha_group_light_entity(
823823
# test that the lights were created and are off
824824
assert bool(entity.state["on"]) is False
825825

826-
# Group entities do not support state restoration
826+
# Group entities do not support state restoration,
827+
# except for off_brightness and off_with_transition
827828
entity.restore_external_state_attributes(
828829
state=True,
829830
off_with_transition=False,
@@ -837,6 +838,8 @@ async def test_zha_group_light_entity(
837838
)
838839

839840
assert bool(entity.state["on"]) is False
841+
assert bool(entity.state["off_with_transition"]) is False
842+
assert entity.state["off_brightness"] == 12
840843

841844
# test turning the lights on and off from the client
842845
await async_test_on_off_from_client(zha_gateway, group_cluster_on_off, entity)

zha/application/platforms/light/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1401,4 +1401,9 @@ def restore_external_state_attributes(
14011401
effect: str | None,
14021402
) -> None:
14031403
"""Restore extra state attributes."""
1404-
# Groups do not restore external state attributes
1404+
# Group state is calculated from the members,
1405+
# except for off_with_transition and off_brightness
1406+
if off_with_transition is not None:
1407+
self._off_with_transition = off_with_transition
1408+
if off_brightness is not None:
1409+
self._off_brightness = off_brightness

0 commit comments

Comments
 (0)