@@ -246,6 +246,14 @@ def _update_last_seen(*args, **kwargs): # pylint: disable=unused-argument
246
246
"zha.zigbee.cluster_handlers.general.BasicClusterHandler.async_initialize" ,
247
247
new = mock .AsyncMock (),
248
248
)
249
+ @pytest .mark .parametrize (
250
+ "zha_gateway" ,
251
+ [
252
+ "zha_gateway" ,
253
+ "ws_gateways" ,
254
+ ],
255
+ indirect = True ,
256
+ )
249
257
async def test_check_available_unsuccessful (
250
258
zha_gateway : Gateway ,
251
259
) -> None :
@@ -257,59 +265,78 @@ async def test_check_available_unsuccessful(
257
265
zha_device = await join_zigpy_device (zha_gateway , device_with_basic_cluster_handler )
258
266
basic_ch = device_with_basic_cluster_handler .endpoints [3 ].basic
259
267
268
+ if hasattr (zha_gateway , "ws_gateway" ):
269
+ server_device = zha_gateway .ws_gateway .devices [zha_device .ieee ]
270
+ server_gateway = zha_gateway .ws_gateway
271
+ else :
272
+ server_device = zha_device
273
+ server_gateway = zha_gateway
274
+
260
275
assert zha_device .available is True
261
276
assert basic_ch .read_attributes .await_count == 0
262
277
263
278
device_with_basic_cluster_handler .last_seen = (
264
- time .time () - zha_device .consider_unavailable_time - 2
279
+ time .time () - server_device .consider_unavailable_time - 2
265
280
)
266
281
267
- for entity in zha_device .platform_entities .values ():
282
+ for entity in server_device .platform_entities .values ():
268
283
entity .emit = mock .MagicMock (wraps = entity .emit )
269
284
270
285
# we want to test the device availability handling alone
271
- zha_gateway .global_updater .stop ()
286
+ server_gateway .global_updater .stop ()
272
287
273
288
# unsuccessfully ping zigpy device, but zha_device is still available
274
289
await _send_time_changed (
275
- zha_gateway , zha_gateway ._device_availability_checker .__polling_interval + 1
290
+ zha_gateway , server_gateway ._device_availability_checker .__polling_interval + 1
276
291
)
277
292
278
293
assert basic_ch .read_attributes .await_count == 1
279
294
assert basic_ch .read_attributes .await_args [0 ][0 ] == ["manufacturer" ]
280
295
assert zha_device .available is True
281
296
282
- for entity in zha_device .platform_entities .values ():
297
+ for entity in server_device .platform_entities .values ():
283
298
entity .emit .assert_not_called ()
284
299
assert entity .available
300
+ if server_device != zha_device :
301
+ assert zha_device .platform_entities [
302
+ (entity .PLATFORM , entity .unique_id )
303
+ ].available
285
304
entity .emit .reset_mock ()
286
305
287
306
# still no traffic, but zha_device is still available
288
307
await _send_time_changed (
289
- zha_gateway , zha_gateway ._device_availability_checker .__polling_interval + 1
308
+ zha_gateway , server_gateway ._device_availability_checker .__polling_interval + 1
290
309
)
291
310
292
311
assert basic_ch .read_attributes .await_count == 2
293
312
assert basic_ch .read_attributes .await_args [0 ][0 ] == ["manufacturer" ]
294
313
assert zha_device .available is True
295
314
296
- for entity in zha_device .platform_entities .values ():
315
+ for entity in server_device .platform_entities .values ():
297
316
entity .emit .assert_not_called ()
298
317
assert entity .available
318
+ if server_device != zha_device :
319
+ assert zha_device .platform_entities [
320
+ (entity .PLATFORM , entity .unique_id )
321
+ ].available
299
322
entity .emit .reset_mock ()
300
323
301
324
# not even trying to update, device is unavailable
302
325
await _send_time_changed (
303
- zha_gateway , zha_gateway ._device_availability_checker .__polling_interval + 1
326
+ zha_gateway , server_gateway ._device_availability_checker .__polling_interval + 1
304
327
)
305
328
306
329
assert basic_ch .read_attributes .await_count == 2
307
330
assert basic_ch .read_attributes .await_args [0 ][0 ] == ["manufacturer" ]
308
331
assert zha_device .available is False
309
332
310
- for entity in zha_device .platform_entities .values ():
333
+ for entity in server_device .platform_entities .values ():
311
334
entity .emit .assert_called ()
312
335
assert not entity .available
336
+ if server_device != zha_device :
337
+ assert not zha_device .platform_entities [
338
+ (entity .PLATFORM , entity .unique_id )
339
+ ].available
313
340
entity .emit .reset_mock ()
314
341
315
342
0 commit comments