1
1
import asyncio
2
2
import contextlib
3
+ from unittest import mock
3
4
4
5
import pytest
5
6
import zigpy .util
@@ -272,6 +273,7 @@ async def test_on_zdo_device_join_and_announce_fast(device, make_application, mo
272
273
await app .shutdown ()
273
274
274
275
276
+ @mock .patch ("zigpy_znp.zigbee.application.DEVICE_JOIN_MAX_DELAY" , new = 0.1 )
275
277
@pytest .mark .parametrize ("device" , FORMED_DEVICES )
276
278
async def test_on_zdo_device_join_and_announce_slow (device , make_application , mocker ):
277
279
app , znp_server = make_application (server_cls = device )
@@ -283,7 +285,6 @@ async def test_on_zdo_device_join_and_announce_slow(device, make_application, mo
283
285
)
284
286
285
287
mocker .patch .object (app , "handle_join" , wraps = app .handle_join )
286
- mocker .patch ("zigpy_znp.zigbee.application.DEVICE_JOIN_MAX_DELAY" , new = 0.1 )
287
288
288
289
nwk = 0x1234
289
290
ieee = t .EUI64 .convert ("11:22:33:44:55:66:77:88" )
@@ -295,11 +296,13 @@ async def test_on_zdo_device_join_and_announce_slow(device, make_application, mo
295
296
# We're waiting for the device to announce itself
296
297
assert app .handle_join .call_count == 0
297
298
298
- await asyncio .sleep (0.3 )
299
+ # Wait for the trust center join timeout to elapse
300
+ while app .handle_join .call_count == 0 :
301
+ await asyncio .sleep (0.1 )
299
302
300
- # Too late, it already happened
301
303
app .handle_join .assert_called_once_with (nwk = nwk , ieee = ieee , parent_nwk = 0x0001 )
302
304
305
+ # Finally, send the device announcement
303
306
znp_server .send (
304
307
c .ZDO .MsgCbIncoming .Callback (
305
308
Src = nwk ,
@@ -327,9 +330,10 @@ async def test_on_zdo_device_join_and_announce_slow(device, make_application, mo
327
330
)
328
331
)
329
332
330
- await asyncio .sleep (0.1 )
333
+ await asyncio .sleep (0.5 )
331
334
332
335
# The announcement will trigger another join indication
333
336
assert app .handle_join .call_count == 2
334
337
338
+ app .get_device (ieee = ieee ).cancel_initialization ()
335
339
await app .shutdown ()
0 commit comments