11
11
12
12
from tests .common import ClusterListener
13
13
import zhaquirks
14
- from zhaquirks .const import COMMAND_BUTTON_DOUBLE , COMMAND_BUTTON_HOLD
14
+ from zhaquirks .const import (
15
+ COMMAND_M_INITIAL_PRESS ,
16
+ COMMAND_M_LONG_RELEASE ,
17
+ COMMAND_M_MULTI_PRESS_COMPLETE ,
18
+ COMMAND_M_SHORT_RELEASE ,
19
+ TURN_OFF ,
20
+ TURN_ON ,
21
+ )
15
22
from zhaquirks .sinope import SINOPE_MANUFACTURER_CLUSTER_ID
16
23
from zhaquirks .sinope .light import (
17
24
SinopeTechnologieslight ,
@@ -92,20 +99,22 @@ def _get_packet_data(
92
99
93
100
@pytest .mark .parametrize ("quirk" , (SinopeTechnologieslight ,))
94
101
@pytest .mark .parametrize (
95
- "press_type,exp_event" ,
102
+ "press_type,button, exp_event" ,
96
103
(
97
- (ButtonAction .Single_off , None ),
98
- (ButtonAction .Single_on , None ),
99
- (ButtonAction .Double_on , COMMAND_BUTTON_DOUBLE ),
100
- (ButtonAction .Double_off , COMMAND_BUTTON_DOUBLE ),
101
- (ButtonAction .Long_on , COMMAND_BUTTON_HOLD ),
102
- (ButtonAction .Long_off , COMMAND_BUTTON_HOLD ),
104
+ (ButtonAction .Pressed_off , TURN_OFF , COMMAND_M_INITIAL_PRESS ),
105
+ (ButtonAction .Pressed_on , TURN_ON , COMMAND_M_INITIAL_PRESS ),
106
+ (ButtonAction .Released_off , TURN_OFF , COMMAND_M_SHORT_RELEASE ),
107
+ (ButtonAction .Released_on , TURN_ON , COMMAND_M_SHORT_RELEASE ),
108
+ (ButtonAction .Double_on , TURN_ON , COMMAND_M_MULTI_PRESS_COMPLETE ),
109
+ (ButtonAction .Double_off , TURN_OFF , COMMAND_M_MULTI_PRESS_COMPLETE ),
110
+ (ButtonAction .Long_on , TURN_ON , COMMAND_M_LONG_RELEASE ),
111
+ (ButtonAction .Long_off , TURN_OFF , COMMAND_M_LONG_RELEASE ),
103
112
# Should gracefully handle broken actions.
104
- (t .uint8_t (0x00 ), None ),
113
+ (t .uint8_t (0x00 ), None , None ),
105
114
),
106
115
)
107
116
async def test_sinope_light_switch (
108
- zigpy_device_from_quirk , quirk , press_type , exp_event
117
+ zigpy_device_from_quirk , quirk , press_type , button , exp_event
109
118
):
110
119
"""Test that button presses are sent as events."""
111
120
device : Device = zigpy_device_from_quirk (quirk )
@@ -126,7 +135,16 @@ class Listener:
126
135
),
127
136
)
128
137
data = _get_packet_data (foundation .GeneralCommand .Report_Attributes , attr )
129
- device .handle_message (260 , cluster_id , endpoint_id , endpoint_id , data )
138
+
139
+ device .packet_received (
140
+ t .ZigbeePacket (
141
+ profile_id = 260 ,
142
+ cluster_id = cluster_id ,
143
+ src_ep = endpoint_id ,
144
+ dst_ep = endpoint_id ,
145
+ data = t .SerializableBytes (data ),
146
+ )
147
+ )
130
148
131
149
if exp_event is None :
132
150
assert cluster_listener .zha_send_event .call_count == 0
@@ -137,6 +155,8 @@ class Listener:
137
155
{
138
156
"attribute_id" : 84 ,
139
157
"attribute_name" : "action_report" ,
158
+ "button" : button ,
159
+ "description" : press_type .name ,
140
160
"value" : press_type .value ,
141
161
},
142
162
)
@@ -162,7 +182,15 @@ class Listener:
162
182
163
183
# read attributes general command
164
184
data = _get_packet_data (foundation .GeneralCommand .Read_Attributes )
165
- device .handle_message (260 , cluster_id , endpoint_id , endpoint_id , data )
185
+ device .packet_received (
186
+ t .ZigbeePacket (
187
+ profile_id = 260 ,
188
+ cluster_id = cluster_id ,
189
+ src_ep = endpoint_id ,
190
+ dst_ep = endpoint_id ,
191
+ data = t .SerializableBytes (data ),
192
+ )
193
+ )
166
194
# no ZHA events emitted because we only handle Report_Attributes
167
195
assert cluster_listener .zha_send_event .call_count == 0
168
196
@@ -174,7 +202,15 @@ class Listener:
174
202
), # 0x29 = t.int16s
175
203
)
176
204
data = _get_packet_data (foundation .GeneralCommand .Report_Attributes , attr )
177
- device .handle_message (260 , cluster_id , endpoint_id , endpoint_id , data )
205
+ device .packet_received (
206
+ t .ZigbeePacket (
207
+ profile_id = 260 ,
208
+ cluster_id = cluster_id ,
209
+ src_ep = endpoint_id ,
210
+ dst_ep = endpoint_id ,
211
+ data = t .SerializableBytes (data ),
212
+ )
213
+ )
178
214
# ZHA event emitted because we pass non "action_report"
179
215
# reports to the base class handler.
180
216
assert cluster_listener .zha_send_event .call_count == 1
0 commit comments