Skip to content

Commit

Permalink
Merge pull request #139 from puddly/rc
Browse files Browse the repository at this point in the history
0.10.2 Release
  • Loading branch information
puddly authored Oct 10, 2022
2 parents 0fcd626 + 9547dca commit 84eda3e
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 25 deletions.
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
39 changes: 32 additions & 7 deletions tests/test_application.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from unittest import mock
from .async_mock import AsyncMock, MagicMock, patch, sentinel
from unittest.mock import AsyncMock, MagicMock, patch, sentinel

import pytest
import logging
import zigpy.types as zigpy_types
import zigpy.types as zigpy_t
import zigpy.exceptions

import zigpy_zigate.config as config
import zigpy_zigate.api
import zigpy_zigate.types as t
import zigpy_zigate.config as config
import zigpy_zigate.zigbee.application

APP_CONFIG = zigpy_zigate.zigbee.application.ControllerApplication.SCHEMA(
Expand All @@ -23,17 +23,17 @@
def app():
a = zigpy_zigate.zigbee.application.ControllerApplication(APP_CONFIG)
a.version = FAKE_FIRMWARE_VERSION
a._api = MagicMock()
a._api = MagicMock(spec_set=zigpy_zigate.api.ZiGate)
return a


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

zigate_ieee, _ = t.EUI64.deserialize(data)
app.state.node_info.ieee = zigpy_types.EUI64(zigate_ieee)
app.state.node_info.ieee = zigpy_t.EUI64(zigate_ieee)

dst_addr = app.get_dst_address(cluster)
assert dst_addr.serialize() == b"\x03" + data[::-1] + b"\x01"
Expand Down Expand Up @@ -135,3 +135,28 @@ 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


@pytest.mark.asyncio
async def test_send_group_request(app):
packet = zigpy_t.ZigbeePacket(src=None, src_ep=1, dst=zigpy_t.AddrModeAddress(addr_mode=zigpy_t.AddrMode.Group, address=0x0002), dst_ep=None, source_route=None, extended_timeout=False, tsn=21, profile_id=260, cluster_id=6, data=zigpy_t.SerializableBytes(b'\x01\x15\x00'), tx_options=zigpy_t.TransmitOptions.NONE, radius=0, non_member_radius=3, lqi=None, rssi=None)

app._api.raw_aps_data_request.return_value = ([t.Status.Success, 0, 1328, b'\x01\xea\x00\x00'], 0)
await app.send_packet(packet)

app._api.raw_aps_data_request.assert_called_once()
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
2 changes: 1 addition & 1 deletion zigpy_zigate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MAJOR_VERSION = 0
MINOR_VERSION = 10
PATCH_VERSION = '1'
PATCH_VERSION = '2'
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
5 changes: 2 additions & 3 deletions zigpy_zigate/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,12 @@ def set_application(self, app):
self._app = app

def data_received(self, cmd, data, lqi):
LOGGER.debug("data received %s %s LQI:%s", hex(cmd),
binascii.hexlify(data), lqi)
if cmd not in RESPONSES:
LOGGER.warning('Received unhandled response 0x%04x', cmd)
LOGGER.warning('Received unhandled response 0x%04x: %r', cmd, binascii.hexlify(data))
return
cmd = ResponseId(cmd)
data, rest = t.deserialize(data, RESPONSES[cmd])
LOGGER.debug("Response received: %s %s %s (LQI:%s)", cmd, data, rest, lqi)
if cmd == ResponseId.STATUS:
if data[2] in self._status_awaiting:
fut = self._status_awaiting.pop(data[2])
Expand Down
10 changes: 5 additions & 5 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 Expand Up @@ -243,8 +243,8 @@ async def send_packet(self, packet):
try:
(status, tsn, packet_type, _), _ = await self._api.raw_aps_data_request(
addr=packet.dst.address,
src_ep=(1 if packet.dst_ep > 0 else 0), # ZiGate only support endpoint 1
dst_ep=packet.dst_ep,
src_ep=(1 if packet.dst_ep is None or packet.dst_ep > 0 else 0), # ZiGate only support endpoint 1
dst_ep=packet.dst_ep or 0,
profile=packet.profile_id,
cluster=packet.cluster_id,
payload=packet.data.serialize(),
Expand Down

0 comments on commit 84eda3e

Please sign in to comment.