Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,23 @@ def new_api(*args):
assert app.version is sentinel.version


async def test_connect_failure(app):
with patch.object(application, "Deconz") as api_mock:
api = api_mock.return_value = MagicMock()
api.connect = AsyncMock()
api.version = AsyncMock(side_effect=RuntimeError("Broken"))

app._api = None

with pytest.raises(RuntimeError):
await app.connect()

assert app._api is None
api.connect.assert_called_once()
api.version.assert_called_once()
api.close.assert_called_once()


async def test_disconnect(app):
reset_watchdog_task = app._reset_watchdog_task = MagicMock()
api_close = app._api.close = MagicMock()
Expand Down
2 changes: 1 addition & 1 deletion zigpy_deconz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
# coding: utf-8
MAJOR_VERSION = 0
MINOR_VERSION = 19
PATCH_VERSION = "0"
PATCH_VERSION = "1"
__short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}"
__version__ = f"{__short_version__}.{PATCH_VERSION}"
10 changes: 8 additions & 2 deletions zigpy_deconz/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ async def _reset_watchdog(self):

async def connect(self):
api = Deconz(self, self._config[zigpy.config.CONF_DEVICE])
await api.connect()
self.version = await api.version()

try:
await api.connect()
self.version = await api.version()
except Exception:
api.close()
raise

self._api = api
self._written_endpoints.clear()

Expand Down