@@ -58,7 +58,7 @@ async def test_probe_unsuccessful():
5858
5959
6060@pytest .mark .parametrize ("device" , FORMED_DEVICES )
61- async def test_probe_unsuccessful_slow (device , make_znp_server , mocker ):
61+ async def test_probe_unsuccessful_slow1 (device , make_znp_server , mocker ):
6262 znp_server = make_znp_server (server_cls = device , shorten_delays = False )
6363
6464 # Don't respond to anything
@@ -75,6 +75,24 @@ async def test_probe_unsuccessful_slow(device, make_znp_server, mocker):
7575 assert not any ([t ._is_connected for t in znp_server ._transports ])
7676
7777
78+ @pytest .mark .parametrize ("device" , FORMED_DEVICES )
79+ async def test_probe_unsuccessful_slow2 (device , make_znp_server , mocker ):
80+ znp_server = make_znp_server (server_cls = device , shorten_delays = False )
81+
82+ # Don't respond to anything
83+ znp_server ._listeners .clear ()
84+
85+ mocker .patch ("zigpy_znp.zigbee.application.PROBE_TIMEOUT" , new = 0.1 )
86+
87+ assert not (
88+ await ControllerApplication .probe (
89+ conf .SCHEMA_DEVICE ({conf .CONF_DEVICE_PATH : znp_server .serial_port })
90+ )
91+ )
92+
93+ assert not any ([t ._is_connected for t in znp_server ._transports ])
94+
95+
7896@pytest .mark .parametrize ("device" , FORMED_DEVICES )
7997async def test_probe_successful (device , make_znp_server ):
8098 znp_server = make_znp_server (server_cls = device , shorten_delays = False )
@@ -101,7 +119,7 @@ async def test_probe_multiple(device, make_znp_server):
101119
102120
103121@pytest .mark .parametrize ("device" , FORMED_DEVICES )
104- async def test_reconnect (device , event_loop , make_application ):
122+ async def test_reconnect (device , make_application ):
105123 app , znp_server = await make_application (
106124 server_cls = device ,
107125 client_config = {
@@ -180,7 +198,7 @@ async def test_multiple_shutdown(make_application):
180198
181199
182200@pytest .mark .parametrize ("device" , FORMED_DEVICES )
183- async def test_reconnect_lockup (device , event_loop , make_application , mocker ):
201+ async def test_reconnect_lockup (device , make_application , mocker ):
184202 mocker .patch ("zigpy_znp.zigbee.application.WATCHDOG_PERIOD" , 0.1 )
185203
186204 app , znp_server = await make_application (
@@ -221,7 +239,7 @@ async def test_reconnect_lockup(device, event_loop, make_application, mocker):
221239
222240
223241@pytest .mark .parametrize ("device" , [FormedLaunchpadCC26X2R1 ])
224- async def test_reconnect_lockup_pyserial (device , event_loop , make_application , mocker ):
242+ async def test_reconnect_lockup_pyserial (device , make_application , mocker ):
225243 mocker .patch ("zigpy_znp.zigbee.application.WATCHDOG_PERIOD" , 0.1 )
226244
227245 app , znp_server = await make_application (
@@ -271,3 +289,49 @@ async def patched_start_network(old_start_network=app.start_network, **kwargs):
271289 assert app ._znp and app ._znp ._uart
272290
273291 await app .shutdown ()
292+
293+
294+ @pytest .mark .parametrize ("device" , [FormedLaunchpadCC26X2R1 ])
295+ async def test_disconnect (device , make_application ):
296+ app , znp_server = await make_application (
297+ server_cls = device ,
298+ client_config = {
299+ conf .CONF_ZNP_CONFIG : {
300+ conf .CONF_SREQ_TIMEOUT : 0.1 ,
301+ }
302+ },
303+ )
304+
305+ assert app ._znp is None
306+ await app .connect ()
307+
308+ assert app ._znp is not None
309+
310+ await app .disconnect ()
311+ assert app ._znp is None
312+
313+ await app .disconnect ()
314+ await app .disconnect ()
315+
316+
317+ @pytest .mark .parametrize ("device" , [FormedLaunchpadCC26X2R1 ])
318+ async def test_disconnect_failure (device , make_application ):
319+ app , znp_server = await make_application (
320+ server_cls = device ,
321+ client_config = {
322+ conf .CONF_ZNP_CONFIG : {
323+ conf .CONF_SREQ_TIMEOUT : 0.1 ,
324+ }
325+ },
326+ )
327+
328+ assert app ._znp is None
329+ await app .connect ()
330+
331+ assert app ._znp is not None
332+
333+ with patch .object (app ._znp , "reset" , side_effect = RuntimeError ("An error" )):
334+ # Runs without error
335+ await app .disconnect ()
336+
337+ assert app ._znp is None
0 commit comments