2
2
3
3
from unittest .mock import call , patch
4
4
5
+ import pytest
5
6
from zhaquirks import (
6
7
DEVICE_TYPE ,
7
8
ENDPOINTS ,
27
28
join_zigpy_device ,
28
29
send_attributes_report ,
29
30
)
31
+ from tests .conftest import CombinedGateways
30
32
from zha .application import Platform
31
- from zha .application .gateway import Gateway
32
- from zha .application .platforms import EntityCategory
33
+ from zha .application .platforms import EntityCategory , PlatformEntity
33
34
from zha .application .platforms .select import AqaraMotionSensitivities
34
35
35
36
36
- async def test_select (zha_gateway : Gateway ) -> None :
37
+ @pytest .mark .parametrize (
38
+ "gateway_type" ,
39
+ ["zha_gateway" , "ws_gateway" ],
40
+ )
41
+ async def test_select (zha_gateways : CombinedGateways , gateway_type : str ) -> None :
37
42
"""Test zha select platform."""
43
+ zha_gateway = getattr (zha_gateways , gateway_type )
38
44
zigpy_device = create_mock_zigpy_device (
39
45
zha_gateway ,
40
46
{
@@ -63,7 +69,9 @@ async def test_select(zha_gateway: Gateway) -> None:
63
69
"Fire Panic" ,
64
70
"Emergency Panic" ,
65
71
]
66
- assert entity ._enum == security .IasWd .Warning .WarningMode
72
+
73
+ if isinstance (entity , PlatformEntity ):
74
+ assert entity ._enum == security .IasWd .Warning .WarningMode
67
75
68
76
# change value from client
69
77
await entity .async_select_option (security .IasWd .Warning .WarningMode .Burglar .name )
@@ -107,9 +115,16 @@ def __init__(self, *args, **kwargs):
107
115
}
108
116
109
117
110
- async def test_on_off_select_attribute_report (zha_gateway : Gateway ) -> None :
118
+ @pytest .mark .parametrize (
119
+ "gateway_type" ,
120
+ ["zha_gateway" , "ws_gateway" ],
121
+ )
122
+ async def test_on_off_select_attribute_report (
123
+ zha_gateways : CombinedGateways , gateway_type : str
124
+ ) -> None :
111
125
"""Test ZHA attribute report parsing for select platform."""
112
126
127
+ zha_gateway = getattr (zha_gateways , gateway_type )
113
128
zigpy_device = create_mock_zigpy_device (
114
129
zha_gateway ,
115
130
{
@@ -126,7 +141,7 @@ async def test_on_off_select_attribute_report(zha_gateway: Gateway) -> None:
126
141
127
142
zigpy_device = get_device (zigpy_device )
128
143
aqara_sensor = await join_zigpy_device (zha_gateway , zigpy_device )
129
- cluster = aqara_sensor . device .endpoints .get (1 ).opple_cluster
144
+ cluster = zigpy_device .endpoints .get (1 ).opple_cluster
130
145
131
146
entity = get_entity (aqara_sensor , platform = Platform .SELECT )
132
147
assert entity .state ["state" ] == AqaraMotionSensitivities .Medium .name
@@ -160,11 +175,16 @@ async def test_on_off_select_attribute_report(zha_gateway: Gateway) -> None:
160
175
)
161
176
162
177
178
+ @pytest .mark .parametrize (
179
+ "gateway_type" ,
180
+ ["zha_gateway" , "ws_gateway" ],
181
+ )
163
182
async def test_on_off_select_attribute_report_v2 (
164
- zha_gateway : Gateway ,
183
+ zha_gateways : CombinedGateways , gateway_type : str
165
184
) -> None :
166
185
"""Test ZHA attribute report parsing for select platform."""
167
186
187
+ zha_gateway = getattr (zha_gateways , gateway_type )
168
188
zigpy_device = create_mock_zigpy_device (
169
189
zha_gateway ,
170
190
{
@@ -184,7 +204,7 @@ async def test_on_off_select_attribute_report_v2(
184
204
185
205
zha_device = await join_zigpy_device (zha_gateway , zigpy_device )
186
206
cluster = zigpy_device .endpoints [1 ].opple_cluster
187
- assert isinstance (zha_device . device , CustomDeviceV2 )
207
+ assert isinstance (zigpy_device , CustomDeviceV2 )
188
208
189
209
entity = get_entity (zha_device , platform = Platform .SELECT )
190
210
@@ -228,8 +248,15 @@ async def test_on_off_select_attribute_report_v2(
228
248
)
229
249
230
250
231
- async def test_non_zcl_select_state_restoration (zha_gateway : Gateway ) -> None :
251
+ @pytest .mark .parametrize (
252
+ "gateway_type" ,
253
+ ["zha_gateway" , "ws_gateway" ],
254
+ )
255
+ async def test_non_zcl_select_state_restoration (
256
+ zha_gateways : CombinedGateways , gateway_type : str
257
+ ) -> None :
232
258
"""Test the non-ZCL select state restoration."""
259
+ zha_gateway = getattr (zha_gateways , gateway_type )
233
260
zigpy_device = create_mock_zigpy_device (
234
261
zha_gateway ,
235
262
{
@@ -251,9 +278,11 @@ async def test_non_zcl_select_state_restoration(zha_gateway: Gateway) -> None:
251
278
entity .restore_external_state_attributes (
252
279
state = security .IasWd .Warning .WarningMode .Burglar .name
253
280
)
281
+ await zha_gateway .async_block_till_done () # needed for WS operations
254
282
assert entity .state ["state" ] == security .IasWd .Warning .WarningMode .Burglar .name
255
283
256
284
entity .restore_external_state_attributes (
257
285
state = security .IasWd .Warning .WarningMode .Fire .name
258
286
)
287
+ await zha_gateway .async_block_till_done () # needed for WS operations
259
288
assert entity .state ["state" ] == security .IasWd .Warning .WarningMode .Fire .name
0 commit comments