mirror of
https://github.com/home-assistant/core.git
synced 2025-07-07 21:37:07 +00:00
Fix ZHA definition error on received command (#90602)
* Fix use of deprecated command schema access * Add a unit test
This commit is contained in:
parent
c63f8e714e
commit
f56ccf90d9
@ -58,15 +58,19 @@ class AttrReportConfig(TypedDict, total=True):
|
|||||||
|
|
||||||
def parse_and_log_command(channel, tsn, command_id, args):
|
def parse_and_log_command(channel, tsn, command_id, args):
|
||||||
"""Parse and log a zigbee cluster command."""
|
"""Parse and log a zigbee cluster command."""
|
||||||
cmd = channel.cluster.server_commands.get(command_id, [command_id])[0]
|
try:
|
||||||
|
name = channel.cluster.server_commands[command_id].name
|
||||||
|
except KeyError:
|
||||||
|
name = f"0x{command_id:02X}"
|
||||||
|
|
||||||
channel.debug(
|
channel.debug(
|
||||||
"received '%s' command with %s args on cluster_id '%s' tsn '%s'",
|
"received '%s' command with %s args on cluster_id '%s' tsn '%s'",
|
||||||
cmd,
|
name,
|
||||||
args,
|
args,
|
||||||
channel.cluster.cluster_id,
|
channel.cluster.cluster_id,
|
||||||
tsn,
|
tsn,
|
||||||
)
|
)
|
||||||
return cmd
|
return name
|
||||||
|
|
||||||
|
|
||||||
def decorate_command(channel, command):
|
def decorate_command(channel, command):
|
||||||
|
19
tests/components/zha/test_base.py
Normal file
19
tests/components/zha/test_base.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
"""Test ZHA base channel module."""
|
||||||
|
|
||||||
|
from homeassistant.components.zha.core.channels.base import parse_and_log_command
|
||||||
|
|
||||||
|
from tests.components.zha.test_channels import ( # noqa: F401
|
||||||
|
channel_pool,
|
||||||
|
poll_control_ch,
|
||||||
|
zigpy_coordinator_device,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_and_log_command(poll_control_ch): # noqa: F811
|
||||||
|
"""Test that `parse_and_log_command` correctly parses a known command."""
|
||||||
|
assert parse_and_log_command(poll_control_ch, 0x00, 0x01, []) == "fast_poll_stop"
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_and_log_command_unknown(poll_control_ch): # noqa: F811
|
||||||
|
"""Test that `parse_and_log_command` correctly parses an unknown command."""
|
||||||
|
assert parse_and_log_command(poll_control_ch, 0x00, 0xAB, []) == "0xAB"
|
Loading…
x
Reference in New Issue
Block a user