Skip to content

Commit 7e98825

Browse files
committed
Don't raise errors on failed ControllerApplication shutdown
1 parent 24cdaae commit 7e98825

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

tests/test_application.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,3 +1103,20 @@ def nvram_init(req):
11031103
assert nvram[NwkNvIds.STARTUP_OPTION] == t.StartupOptions.ClearState.serialize()
11041104
assert nvram[NwkNvIds.LOGICAL_TYPE] == t.DeviceLogicalType.Coordinator.serialize()
11051105
assert nvram[NwkNvIds.ZDO_DIRECT_CB] == t.Bool(True).serialize()
1106+
1107+
1108+
@pytest_mark_asyncio_timeout(seconds=3)
1109+
async def test_clean_shutdown(application, mocker):
1110+
app, znp_server = application
1111+
1112+
# This should not throw
1113+
await app.shutdown()
1114+
1115+
1116+
@pytest_mark_asyncio_timeout(seconds=3)
1117+
async def test_unclean_shutdown(application, mocker):
1118+
app, znp_server = application
1119+
app._znp = None
1120+
1121+
# This should also not throw
1122+
await app.shutdown()

zigpy_znp/zigbee/application.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ async def shutdown(self):
216216
"""Shutdown application."""
217217

218218
self._reconnect_task.cancel()
219-
self._znp.close()
219+
220+
if self._znp is not None:
221+
self._znp.close()
220222

221223
def _bind_callbacks(self, api):
222224
api.callback_for_response(

0 commit comments

Comments
 (0)