Skip to content

Commit

Permalink
0.12.0 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
Adminiuga authored Mar 23, 2021
2 parents a47b228 + 8420a38 commit 2ddaeec
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ jobs:
COVERALLS_PARALLEL: true
run: |
. venv/bin/activate
coveralls
coveralls --service=github
coverage:
Expand Down Expand Up @@ -374,4 +374,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
. venv/bin/activate
coveralls --finish
coveralls --service=github --finish
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Test dependencies

asynctest
coveralls
coveralls==3.0.1
pytest
pytest-cov
pytest-asyncio
Expand Down
35 changes: 19 additions & 16 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import asyncio
import binascii
import logging
import sys

import pytest
import serial
import zigpy.config

from zigpy_deconz import api as deconz_api, types as t, uart
Expand Down Expand Up @@ -239,7 +237,7 @@ def test_simplified_beacon(api):


async def test_aps_data_confirm(api, monkeypatch):
monkeypatch.setattr(deconz_api, "COMMAND_TIMEOUT", 0.1)
monkeypatch.setattr(deconz_api, "COMMAND_TIMEOUT", 0.01)

success = True

Expand All @@ -254,9 +252,10 @@ def mock_cmd(*args, **kwargs):

res = await api._aps_data_confirm()
assert res is not None
assert api._data_confirm is True
assert api._data_confirm is False

success = False
api._data_confirm = True
res = await api._aps_data_confirm()
assert res is None
assert api._data_confirm is False
Expand Down Expand Up @@ -291,9 +290,10 @@ def mock_cmd(*args, **kwargs):

res = await api._aps_data_indication()
assert res is not None
assert api._data_indication is True
assert api._data_indication is False

success = False
api._data_indication = True
res = await api._aps_data_indication()
assert res is None
assert api._data_indication is False
Expand Down Expand Up @@ -524,16 +524,7 @@ async def test_probe_success(mock_connect, mock_device_state):

@patch.object(deconz_api.Deconz, "device_state", new_callable=AsyncMock)
@patch("zigpy_deconz.uart.connect", return_value=MagicMock(spec_set=uart.Gateway))
@pytest.mark.parametrize(
"exception",
(
asyncio.TimeoutError,
serial.SerialException,
zigpy_deconz.exception.CommandError,
)
if sys.version_info[:3] != (3, 7, 9)
else (asyncio.TimeoutError,),
)
@pytest.mark.parametrize("exception", (asyncio.TimeoutError,))
async def test_probe_fail(mock_connect, mock_device_state, exception):
"""Test device probing fails."""

Expand Down Expand Up @@ -587,7 +578,7 @@ async def test_aps_data_req_deserialize_error(api, uart_gw, status, caplog):

device_state = (
deconz_api.DeviceState.APSDE_DATA_INDICATION
| deconz_api.DeviceState.APSDE_DATA_REQUEST_SLOTS_AVAILABLE
| deconz_api.DeviceState.APSDE_DATA_CONFIRM
| deconz_api.NetworkState.CONNECTED
)
api._handle_device_state_value(device_state)
Expand All @@ -606,3 +597,15 @@ async def test_aps_data_req_deserialize_error(api, uart_gw, status, caplog):
await asyncio.sleep(0)
await asyncio.sleep(0)
assert api._data_indication is False


async def test_set_item(api):
"""Test item setter."""

with patch.object(api, "write_parameter", new=AsyncMock()) as write_mock:
api["test"] = sentinel.test_param
for i in range(10):
await asyncio.sleep(0)
assert write_mock.await_count == 1
assert write_mock.call_args[0][0] == "test"
assert write_mock.call_args[0][1] is sentinel.test_param
8 changes: 4 additions & 4 deletions zigpy_deconz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# coding: utf-8
MAJOR_VERSION = 0
MINOR_VERSION = 11
PATCH_VERSION = "1"
__short_version__ = "{}.{}".format(MAJOR_VERSION, MINOR_VERSION)
__version__ = "{}.{}".format(__short_version__, PATCH_VERSION)
MINOR_VERSION = 12
PATCH_VERSION = "0"
__short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}"
__version__ = f"{__short_version__}.{PATCH_VERSION}"
27 changes: 21 additions & 6 deletions zigpy_deconz/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ async def _command(self, cmd, *args):
LOGGER.warning(
"No response to '%s' command with seq id '0x%02x'", cmd, seq
)
self._awaiting.pop(seq)
self._awaiting.pop(seq, None)
raise

def _api_frame(self, cmd, *args):
Expand Down Expand Up @@ -338,16 +338,21 @@ def data_received(self, data):
if solicited and seq in self._awaiting:
fut = self._awaiting.pop(seq)
if status != Status.SUCCESS:
fut.set_exception(
CommandError(status, "%s, status: %s" % (command, status))
)
try:
fut.set_exception(
CommandError(status, "%s, status: %s" % (command, status))
)
except asyncio.InvalidStateError:
LOGGER.warning(
"Duplicate or delayed response for 0x:%02x sequence", seq
)
return

try:
data, _ = t.deserialize(data[5:], schema)
except Exception:
LOGGER.warning("Failed to deserialize frame: %s", binascii.hexlify(data))
if fut is not None:
if fut is not None and not fut.done():
fut.set_exception(
APIException(
f"Failed to deserialize frame: {binascii.hexlify(data)}"
Expand All @@ -356,7 +361,13 @@ def data_received(self, data):
return

if fut is not None:
fut.set_result(data)
try:
fut.set_result(data)
except asyncio.InvalidStateError:
LOGGER.warning(
"Duplicate or delayed response for 0x:%02x sequence", seq
)

getattr(self, "_handle_%s" % (command.name,))(data)

add_neighbour = functools.partialmethod(_command, Command.add_neighbour, 12)
Expand Down Expand Up @@ -475,6 +486,8 @@ async def _aps_data_indication(self):
)
return r
except (asyncio.TimeoutError, zigpy.exceptions.ZigbeeException):
pass
finally:
self._data_indication = False

def _handle_aps_data_indication(self, data):
Expand Down Expand Up @@ -537,6 +550,8 @@ async def _aps_data_confirm(self):
)
return r
except (asyncio.TimeoutError, zigpy.exceptions.ZigbeeException):
pass
finally:
self._data_confirm = False

def _handle_add_neighbour(self, data) -> None:
Expand Down
5 changes: 4 additions & 1 deletion zigpy_deconz/uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ def data_received(self, data):
continue

LOGGER.debug("Frame received: 0x%s", binascii.hexlify(frame).decode())
self._api.data_received(frame)
try:
self._api.data_received(frame)
except Exception as exc:
LOGGER.error("Unexpected error handling the frame: %s", exc)

def _unescape(self, data):
ret = []
Expand Down
2 changes: 1 addition & 1 deletion zigpy_deconz/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def __init__(self, version: int, device_path: str, *args):
"""Initialize instance."""

super().__init__(*args)
is_gpio_device = re.match(r"/dev/tty(S|AMA)\d+", device_path)
is_gpio_device = re.match(r"/dev/tty(S|AMA|ACM)\d+", device_path)
self._model = "RaspBee" if is_gpio_device else "ConBee"
self._model += " II" if ((version & 0x0000FF00) == 0x00000700) else ""

Expand Down

0 comments on commit 2ddaeec

Please sign in to comment.