Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/test_cluster_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1242,8 +1242,8 @@ async def test_zha_send_event_from_quirk(zha_gateway: Gateway):
on_off_ch.cluster_command(1, OnOff.ServerCommandDefs.on.id, [])

assert on_off_ch.emit_zha_event.call_count == 2
# attribute_updated is emitted first, then the cluster command is forwarded
assert on_off_ch.emit_zha_event.mock_calls == [
call("on", []),
call(
"attribute_updated",
{
Expand All @@ -1253,6 +1253,7 @@ async def test_zha_send_event_from_quirk(zha_gateway: Gateway):
"value": t.Bool.true,
},
),
call("on", []),
]
on_off_ch.emit_zha_event.reset_mock()

Expand Down
7 changes: 4 additions & 3 deletions zha/zigbee/cluster_handlers/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,11 +552,9 @@ def on_off(self) -> bool | None:

def cluster_command(self, tsn, command_id, args):
"""Handle commands received to this cluster."""
# for emitting ZHA event
super().cluster_command(tsn, command_id, args)

cmd = parse_and_log_command(self, tsn, command_id, args)

# Process cluster commands, so attribute_updated events fire first
if cmd in (
OnOff.ServerCommandDefs.off.name,
OnOff.ServerCommandDefs.off_with_effect.name,
Expand Down Expand Up @@ -588,6 +586,9 @@ def cluster_command(self, tsn, command_id, args):
OnOff.AttributeDefs.on_off.id, not bool(self.on_off)
)

# Emit ZHA event with cluster command
super().cluster_command(tsn, command_id, args)

def set_to_off(self, *_):
"""Set the state to off."""
self._off_listener = None
Expand Down
Loading