From 455373df8315401047aaacfe7dc4f355bb8a74f4 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Mon, 31 Oct 2022 16:18:21 -0400 Subject: [PATCH 1/2] Always enable ACKs on older firmwares (#141) --- tests/test_application.py | 18 ++++++++++++++++++ zigpy_zigate/zigbee/application.py | 9 +++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/test_application.py b/tests/test_application.py index c965217..68297e0 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -152,6 +152,24 @@ async def test_startup_connect(zigate_new, app, version_rsp, expected_version): assert app.version == expected_version +@pytest.mark.asyncio +@pytest.mark.parametrize("version, addr_mode", [ + ["3.1z", t.AddressMode.NWK_NO_ACK], + ["3.1d", t.AddressMode.NWK], +]) +async def test_send_unicast_request(app, version, addr_mode): + packet = zigpy_t.ZigbeePacket(src=zigpy_t.AddrModeAddress(addr_mode=zigpy_t.AddrMode.NWK, address=0x0000), src_ep=1, dst=zigpy_t.AddrModeAddress(addr_mode=zigpy_t.AddrMode.NWK, address=0xFA5D), dst_ep=1, source_route=None, extended_timeout=False, tsn=20, profile_id=260, cluster_id=6, data=zigpy_t.SerializableBytes(b'\x01\x14\x00'), tx_options=zigpy_t.TransmitOptions.NONE, radius=0, non_member_radius=0, lqi=None, rssi=None) + + app.version = version + app._api.raw_aps_data_request.return_value = ([t.Status.Success, 163, 1328, b'\x00\x00'], 0) + await app.send_packet(packet) + + # The packet was sent with ACKs, even though zigpy didn't ask for it + assert app._api.raw_aps_data_request.mock_calls[0].kwargs["addr_mode"] == addr_mode + + app._api.raw_aps_data_request.assert_called_once() + + @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) diff --git a/zigpy_zigate/zigbee/application.py b/zigpy_zigate/zigbee/application.py index 8dedfbd..374b581 100644 --- a/zigpy_zigate/zigbee/application.py +++ b/zigpy_zigate/zigbee/application.py @@ -238,7 +238,12 @@ def _handle_frame_failure(self, message_tag, status): async def send_packet(self, packet): LOGGER.debug("Sending packet %r", packet) - ack = (zigpy.types.TransmitOptions.ACK in packet.tx_options) + # Firmwares 3.1d and below allow a couple of _NO_ACK packets to send but all + # subsequent ones will fail. ACKs must be enabled. + ack = ( + zigpy.types.TransmitOptions.ACK in packet.tx_options + or self.version <= "3.1d" + ) try: (status, tsn, packet_type, _), _ = await self._api.raw_aps_data_request( @@ -263,7 +268,7 @@ async def send_packet(self, packet): if status == t.Status.InvalidParameter and self.version <= "3.1d": pass else: - raise zigpy.exceptions.DeliveryError(f"Failed to send packet: {status}", status=status) + raise zigpy.exceptions.DeliveryError(f"Failed to send packet: {status!r}", status=status) # disabled because of https://github.com/fairecasoimeme/ZiGate/issues/324 # try: From a43c7bfbdb0315c224afb95e9d14abb0279ab847 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Mon, 31 Oct 2022 16:27:31 -0400 Subject: [PATCH 2/2] 0.10.3 version bump --- zigpy_zigate/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zigpy_zigate/__init__.py b/zigpy_zigate/__init__.py index 68838e0..9c80242 100644 --- a/zigpy_zigate/__init__.py +++ b/zigpy_zigate/__init__.py @@ -1,5 +1,5 @@ MAJOR_VERSION = 0 -MINOR_VERSION = 11 -PATCH_VERSION = '0.dev0' +MINOR_VERSION = 10 +PATCH_VERSION = '3' __short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION) __version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)