Skip to content

Commit 05f94d4

Browse files
committed
Add some tests
1 parent e50b448 commit 05f94d4

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

tests/test_platform_event.py

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import logging
66

7+
import pytest
78
from zigpy.device import Device as ZigpyDevice
89
from zigpy.profiles import zha
910
from zigpy.zcl.clusters import general
@@ -21,6 +22,7 @@
2122
)
2223
from zha.application import Platform
2324
from zha.application.gateway import Gateway
25+
from zha.application.platforms.event import BaseEvent
2426

2527
IEEE_GROUPABLE_DEVICE = "01:2d:6f:00:0a:90:69:e8"
2628
IEEE_GROUPABLE_DEVICE2 = "02:2d:6f:00:0a:90:69:e8"
@@ -75,14 +77,20 @@ async def test_event(
7577
]
7678

7779
entity = get_entity(zha_device, platform=Platform.EVENT)
78-
assert entity
80+
assert isinstance(entity, BaseEvent)
81+
assert entity.event_types == [
82+
"step",
83+
"step_with_on_off",
84+
"stop",
85+
"move",
86+
"move_with_on_off",
87+
"move_to_level",
88+
"move_to_level_with_on_off",
89+
]
7990

80-
hdr = make_zcl_header(
81-
cluster.ServerCommandDefs.step.id, global_command=False, tsn=1
82-
)
83-
msg = cluster.ServerCommandDefs.step.schema(
84-
step_mode=1, step_size=10, transition_time=5
85-
)
91+
cmd = cluster.ServerCommandDefs.step
92+
hdr = make_zcl_header(cmd.id, global_command=False, tsn=1)
93+
msg = cmd.schema(step_mode=1, step_size=10, transition_time=5)
8694
cluster.handle_message(hdr, msg)
8795
assert entity.state == {
8896
"event_attributes": {
@@ -94,3 +102,30 @@ async def test_event(
94102
"available": True,
95103
"class_name": "LevelControlEvent",
96104
}
105+
106+
107+
async def test_invalid_event(
108+
zha_gateway: Gateway,
109+
caplog: pytest.LogCaptureFixture,
110+
) -> None:
111+
"""Test that an invalid command does not trigger an exception."""
112+
113+
zigpy_device = zigpy_device_mock(zha_gateway)
114+
zha_device = await join_zigpy_device(zha_gateway, zigpy_device)
115+
cluster: general.LevelControl = zigpy_device.endpoints.get(1).out_clusters[
116+
general.LevelControl.cluster_id
117+
]
118+
119+
entity = get_entity(zha_device, platform=Platform.EVENT)
120+
assert isinstance(entity, BaseEvent)
121+
122+
# cmd = general.OnOff.ServerCommandDefs.on
123+
hdr = make_zcl_header(0xFF, global_command=False, tsn=1)
124+
msg = b""
125+
126+
caplog.clear()
127+
cluster.handle_message(hdr, msg)
128+
assert (
129+
"[0xB79C:1:0x0008_client]: received '0xFF' command with b'' args on cluster_id '8' tsn '1'\n"
130+
in caplog.text
131+
)

0 commit comments

Comments
 (0)