44
55import logging
66
7+ import pytest
78from zigpy .device import Device as ZigpyDevice
89from zigpy .profiles import zha
910from zigpy .zcl .clusters import general
2122)
2223from zha .application import Platform
2324from zha .application .gateway import Gateway
25+ from zha .application .platforms .event import BaseEvent
2426
2527IEEE_GROUPABLE_DEVICE = "01:2d:6f:00:0a:90:69:e8"
2628IEEE_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