Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix startup version command handling #137

Merged
merged 2 commits into from
Oct 9, 2022
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
7 changes: 0 additions & 7 deletions tests/async_mock.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
import serial
import serial_asyncio
from .async_mock import AsyncMock, MagicMock, patch, sentinel
from unittest.mock import AsyncMock, MagicMock, patch, sentinel

import zigpy_zigate.config as config
import zigpy_zigate.uart
Expand Down
20 changes: 17 additions & 3 deletions tests/test_application.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from unittest import mock
from .async_mock import AsyncMock, MagicMock, patch, sentinel
from unittest.mock import AsyncMock, MagicMock, patch, sentinel

import pytest
import logging
Expand Down Expand Up @@ -28,7 +27,7 @@ def app():


def test_zigpy_ieee(app):
cluster = mock.MagicMock()
cluster = MagicMock()
cluster.cluster_id = 0x0000
data = b"\x01\x02\x03\x04\x05\x06\x07\x08"

Expand Down Expand Up @@ -135,3 +134,18 @@ async def test_disconnect_multiple(app):
await app.disconnect()

assert app._api is None


@pytest.mark.asyncio
@patch("zigpy_zigate.zigbee.application.ZiGate.new")
@pytest.mark.parametrize("version_rsp, expected_version", [
[((261, 798), 0), "3.1e"],
[((5, 801), 0), "3.21"]
])
async def test_startup_connect(zigate_new, app, version_rsp, expected_version):
api = zigate_new.return_value
api.version.return_value = version_rsp

await app.connect()

assert app.version == expected_version
2 changes: 1 addition & 1 deletion tests/test_uart.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .async_mock import MagicMock, AsyncMock
from unittest.mock import MagicMock, AsyncMock

import pytest
import gpiozero
Expand Down
6 changes: 3 additions & 3 deletions zigpy_zigate/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ async def connect(self):
api = await ZiGate.new(self._config[CONF_DEVICE], self)
await api.set_raw_mode()
await api.set_time()
version, lqi = await api.version()

self._api = api

(_, version), lqi = await api.version()
major, minor = version.to_bytes(2, "big")
self.version = f"{major:x}.{minor:x}"

self._api = api

if self.version < '3.21':
LOGGER.error('Old ZiGate firmware detected, you should upgrade to 3.21 or newer')

Expand Down