@@ -246,6 +246,14 @@ def _update_last_seen(*args, **kwargs): # pylint: disable=unused-argument
246246 "zha.zigbee.cluster_handlers.general.BasicClusterHandler.async_initialize" ,
247247 new = mock .AsyncMock (),
248248)
249+ @pytest .mark .parametrize (
250+ "zha_gateway" ,
251+ [
252+ "zha_gateway" ,
253+ "ws_gateways" ,
254+ ],
255+ indirect = True ,
256+ )
249257async def test_check_available_unsuccessful (
250258 zha_gateway : Gateway ,
251259) -> None :
@@ -257,59 +265,78 @@ async def test_check_available_unsuccessful(
257265 zha_device = await join_zigpy_device (zha_gateway , device_with_basic_cluster_handler )
258266 basic_ch = device_with_basic_cluster_handler .endpoints [3 ].basic
259267
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+
260275 assert zha_device .available is True
261276 assert basic_ch .read_attributes .await_count == 0
262277
263278 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
265280 )
266281
267- for entity in zha_device .platform_entities .values ():
282+ for entity in server_device .platform_entities .values ():
268283 entity .emit = mock .MagicMock (wraps = entity .emit )
269284
270285 # we want to test the device availability handling alone
271- zha_gateway .global_updater .stop ()
286+ server_gateway .global_updater .stop ()
272287
273288 # unsuccessfully ping zigpy device, but zha_device is still available
274289 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
276291 )
277292
278293 assert basic_ch .read_attributes .await_count == 1
279294 assert basic_ch .read_attributes .await_args [0 ][0 ] == ["manufacturer" ]
280295 assert zha_device .available is True
281296
282- for entity in zha_device .platform_entities .values ():
297+ for entity in server_device .platform_entities .values ():
283298 entity .emit .assert_not_called ()
284299 assert entity .available
300+ if server_device != zha_device :
301+ assert zha_device .platform_entities [
302+ (entity .PLATFORM , entity .unique_id )
303+ ].available
285304 entity .emit .reset_mock ()
286305
287306 # still no traffic, but zha_device is still available
288307 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
290309 )
291310
292311 assert basic_ch .read_attributes .await_count == 2
293312 assert basic_ch .read_attributes .await_args [0 ][0 ] == ["manufacturer" ]
294313 assert zha_device .available is True
295314
296- for entity in zha_device .platform_entities .values ():
315+ for entity in server_device .platform_entities .values ():
297316 entity .emit .assert_not_called ()
298317 assert entity .available
318+ if server_device != zha_device :
319+ assert zha_device .platform_entities [
320+ (entity .PLATFORM , entity .unique_id )
321+ ].available
299322 entity .emit .reset_mock ()
300323
301324 # not even trying to update, device is unavailable
302325 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
304327 )
305328
306329 assert basic_ch .read_attributes .await_count == 2
307330 assert basic_ch .read_attributes .await_args [0 ][0 ] == ["manufacturer" ]
308331 assert zha_device .available is False
309332
310- for entity in zha_device .platform_entities .values ():
333+ for entity in server_device .platform_entities .values ():
311334 entity .emit .assert_called ()
312335 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
313340 entity .emit .reset_mock ()
314341
315342
0 commit comments