Skip to content

Commit b545d07

Browse files
committed
Update reconnect tests and don't use zigpy startup during reconnect
1 parent 6ad0366 commit b545d07

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

tests/application/test_connect.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,16 @@ async def test_reconnect_lockup(device, event_loop, make_application, mocker):
220220
await app.shutdown()
221221

222222

223-
@pytest.mark.parametrize("device", FORMED_DEVICES)
223+
@pytest.mark.parametrize("device", [FormedLaunchpadCC26X2R1])
224224
async def test_reconnect_lockup_pyserial(device, event_loop, make_application, mocker):
225225
mocker.patch("zigpy_znp.zigbee.application.WATCHDOG_PERIOD", 0.1)
226226

227227
app, znp_server = await make_application(
228228
server_cls=device,
229229
client_config={
230230
conf.CONF_ZNP_CONFIG: {
231-
conf.CONF_AUTO_RECONNECT_RETRY_DELAY: 0.1,
231+
conf.CONF_AUTO_RECONNECT_RETRY_DELAY: 0.01,
232+
conf.CONF_SREQ_TIMEOUT: 0.1,
232233
}
233234
},
234235
)
@@ -243,20 +244,20 @@ async def test_reconnect_lockup_pyserial(device, event_loop, make_application, m
243244
# We are connected
244245
assert app._znp is not None
245246

246-
did_load_info = asyncio.get_running_loop().create_future()
247+
did_start_network = asyncio.get_running_loop().create_future()
247248

248-
async def patched_load_network_info(old_load=app.load_network_info, **kwargs):
249+
async def patched_start_network(old_start_network=app.start_network, **kwargs):
249250
try:
250-
return await old_load(**kwargs)
251+
return await old_start_network(**kwargs)
251252
finally:
252-
did_load_info.set_result(True)
253+
did_start_network.set_result(True)
253254

254-
with patch.object(app, "load_network_info", patched_load_network_info):
255+
with patch.object(app, "start_network", patched_start_network):
255256
# "Drop" the connection like PySerial
256257
app._znp._uart.connection_lost(exc=None)
257258

258259
# Wait until we are reconnecting
259-
await did_load_info
260+
await did_start_network
260261

261262
# "Drop" the connection like PySerial again, but during connect
262263
app._znp._uart.connection_lost(exc=None)

zigpy_znp/zigbee/application.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ async def disconnect(self):
123123
if self._znp is not None:
124124
try:
125125
await self._znp.reset(wait_for_reset=False)
126+
except asyncio.CancelledError:
127+
raise
128+
except Exception as e:
129+
LOGGER.warning("Failed to reset before disconnect: %s", e)
126130
finally:
127131
self._znp.close()
128132
self._znp = None
@@ -881,7 +885,8 @@ async def _reconnect(self) -> None:
881885
)
882886

883887
try:
884-
await self.startup(auto_form=False)
888+
await self.connect()
889+
await self.start_network()
885890
return
886891
except asyncio.CancelledError:
887892
raise

0 commit comments

Comments
 (0)