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
21 changes: 16 additions & 5 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

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 @@ -22,7 +23,7 @@
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


Expand All @@ -32,7 +33,7 @@ def test_zigpy_ieee(app):
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 @@ -148,4 +149,14 @@ async def test_startup_connect(zigate_new, app, version_rsp, expected_version):

await app.connect()

assert app.version == expected_version
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()
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
4 changes: 2 additions & 2 deletions zigpy_zigate/zigbee/application.py
Original file line number Diff line number Diff line change
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