From fe550cfe96f871658d5a6a38af9c1307716718a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bitard=20Micha=C3=ABl?= Date: Sat, 8 Jan 2022 14:25:19 +0100 Subject: [PATCH 1/6] handle response 0x8012 --- zigpy_zigate/api.py | 1 + zigpy_zigate/zigbee/application.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/zigpy_zigate/api.py b/zigpy_zigate/api.py index ac6097d..2cdc199 100644 --- a/zigpy_zigate/api.py +++ b/zigpy_zigate/api.py @@ -30,6 +30,7 @@ 0x8009: (t.NWK, t.EUI64, t.uint16_t, t.uint64_t, t.uint8_t), 0x8010: (t.uint16_t, t.uint16_t), 0x8011: (t.uint8_t, t.NWK, t.uint8_t, t.uint16_t, t.uint8_t), + 0x8012: (t.uint8_t, t.uint8_t, t.uint8_t, t.Address, t.uint8_t), 0x8017: (t.uint32_t,), 0x8024: (t.uint8_t, t.NWK, t.EUI64, t.uint8_t), 0x8035: (t.uint8_t, t.uint32_t), diff --git a/zigpy_zigate/zigbee/application.py b/zigpy_zigate/zigbee/application.py index c99bb0f..5143896 100644 --- a/zigpy_zigate/zigbee/application.py +++ b/zigpy_zigate/zigbee/application.py @@ -42,8 +42,8 @@ async def startup(self, auto_form=False): version = '{:x}'.format(version[1]) version = '{}.{}'.format(version[0], version[1:]) self.version = version - if version < '3.1d': - LOGGER.warning('Old ZiGate firmware detected, you should upgrade to 3.1d or newer') + if version < '3.21': + LOGGER.warning('Old ZiGate firmware detected, you should upgrade to 3.21 or newer') network_state, lqi = await self._api.get_network_state() should_form = not network_state or network_state[0] == 0xffff or network_state[3] == 0 From 67f372dc43751c3646c933b2f2c10be6fff47f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bitard=20Micha=C3=ABl?= Date: Sat, 8 Jan 2022 14:47:40 +0100 Subject: [PATCH 2/6] debug log the 0x8012 response --- zigpy_zigate/zigbee/application.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zigpy_zigate/zigbee/application.py b/zigpy_zigate/zigbee/application.py index 5143896..e9d5079 100644 --- a/zigpy_zigate/zigbee/application.py +++ b/zigpy_zigate/zigbee/application.py @@ -140,7 +140,7 @@ def zigate_callback_handler(self, msg, response, lqi): self.handle_message(device, response[1], response[2], response[3], response[4], response[-1]) - elif msg == 0x8011: # ACK Data + elif msg == 0x8011 or msg == 0x8012: # ACK Data LOGGER.debug('ACK Data received %s %s', response[4], response[0]) # disabled because of https://github.com/fairecasoimeme/ZiGate/issues/324 # self._handle_frame_failure(response[4], response[0]) From 429b38e4235f58e6ef23c8ca9f8c1c886cb3c16f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bitard=20Micha=C3=ABl?= Date: Sat, 8 Jan 2022 20:19:27 +0100 Subject: [PATCH 3/6] add unit test --- tests/test_types.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_types.py b/tests/test_types.py index 1f8abf9..b181f28 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -1,3 +1,4 @@ +import binascii from zigpy_zigate import types as t from zigpy_zigate.api import RESPONSES, COMMANDS @@ -63,6 +64,17 @@ def test_deserialize(): assert result[3] is None assert len(result) == 4 + data = binascii.unhexlify(b'00010102bc8c730001') + schema = RESPONSES[0x8012] + result, rest = t.deserialize(data, schema) + assert result[0] == 0x00 + assert result[1] == 0x01 + assert result[2] == 0x01 + assert result[3] == t.Address(address_mode=t.ADDRESS_MODE.NWK, + address=t.NWK.deserialize(b'\xbc\x8c')[0]) + assert result[4] == 0x73 + assert len(result) == 5 + def test_serialize(): data = [True] schema = COMMANDS[0x0002] From 7043c910994f05abae6b9824f37e571e2b0276c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bitard=20Micha=C3=ABl?= Date: Sat, 8 Jan 2022 20:44:25 +0100 Subject: [PATCH 4/6] manage 0x9999 + separate log for each message --- tests/test_types.py | 12 ++++++++++++ zigpy_zigate/api.py | 1 + zigpy_zigate/zigbee/application.py | 6 +++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/test_types.py b/tests/test_types.py index b181f28..74f6409 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -64,6 +64,9 @@ def test_deserialize(): assert result[3] is None assert len(result) == 4 + # Frame received: 8012000a2800010102bc8c73000100 + # data received 0x8012 b'00010102bc8c730001' + data = binascii.unhexlify(b'00010102bc8c730001') schema = RESPONSES[0x8012] result, rest = t.deserialize(data, schema) @@ -75,6 +78,15 @@ def test_deserialize(): assert result[4] == 0x73 assert len(result) == 5 + # Frame received: 99990002828000 + # data received 0x9999 b'80' LQI:0 + + data = binascii.unhexlify(b'80') + schema = RESPONSES[0x9999] + result, rest = t.deserialize(data, schema) + assert result[0] == 0x80 + assert len(result) == 1 + def test_serialize(): data = [True] schema = COMMANDS[0x0002] diff --git a/zigpy_zigate/api.py b/zigpy_zigate/api.py index 2cdc199..2cd172e 100644 --- a/zigpy_zigate/api.py +++ b/zigpy_zigate/api.py @@ -38,6 +38,7 @@ 0x8701: (t.uint8_t, t.uint8_t), 0x8702: (t.uint8_t, t.uint8_t, t.uint8_t, t.Address, t.uint8_t), 0x8806: (t.uint8_t,), + 0x9999: (t.uint8_t,), } COMMANDS = { diff --git a/zigpy_zigate/zigbee/application.py b/zigpy_zigate/zigbee/application.py index e9d5079..442f838 100644 --- a/zigpy_zigate/zigbee/application.py +++ b/zigpy_zigate/zigbee/application.py @@ -140,10 +140,12 @@ def zigate_callback_handler(self, msg, response, lqi): self.handle_message(device, response[1], response[2], response[3], response[4], response[-1]) - elif msg == 0x8011 or msg == 0x8012: # ACK Data + elif msg == 0x8011: # ACK Data LOGGER.debug('ACK Data received %s %s', response[4], response[0]) # disabled because of https://github.com/fairecasoimeme/ZiGate/issues/324 # self._handle_frame_failure(response[4], response[0]) + elif msg == 0x8012: # ZPS Event + LOGGER.debug('ZPS Event APS data confirm, message routed to %s %s', response[3], response[0]) elif msg == 0x8035: # PDM Event try: event = PDM_EVENT(response[0]).name @@ -153,6 +155,8 @@ def zigate_callback_handler(self, msg, response, lqi): elif msg == 0x8702: # APS Data confirm Fail LOGGER.debug('APS Data confirm Fail %s %s', response[4], response[0]) self._handle_frame_failure(response[4], response[0]) + elif msg == 0x9999: # ZCL event + LOGGER.debug('ZCL application started %s', response[0]) def _handle_frame_failure(self, message_tag, status): try: From 42c9469922b100a5767b6bbc9942ccb6cd26e58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bitard=20Micha=C3=ABl?= Date: Thu, 20 Jan 2022 10:58:56 +0100 Subject: [PATCH 5/6] PR review N*1 --- zigpy_zigate/zigbee/application.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zigpy_zigate/zigbee/application.py b/zigpy_zigate/zigbee/application.py index 442f838..da228a1 100644 --- a/zigpy_zigate/zigbee/application.py +++ b/zigpy_zigate/zigbee/application.py @@ -156,7 +156,7 @@ def zigate_callback_handler(self, msg, response, lqi): LOGGER.debug('APS Data confirm Fail %s %s', response[4], response[0]) self._handle_frame_failure(response[4], response[0]) elif msg == 0x9999: # ZCL event - LOGGER.debug('ZCL application started %s', response[0]) + LOGGER.debug('Extended error code %s', response[0]) def _handle_frame_failure(self, message_tag, status): try: From 50ecfea120ff2daac99b6fb0dd0d5474e12653ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bitard=20Micha=C3=ABl?= Date: Thu, 20 Jan 2022 14:42:52 +0100 Subject: [PATCH 6/6] change debug to warning message --- zigpy_zigate/zigbee/application.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zigpy_zigate/zigbee/application.py b/zigpy_zigate/zigbee/application.py index da228a1..7d0e48b 100644 --- a/zigpy_zigate/zigbee/application.py +++ b/zigpy_zigate/zigbee/application.py @@ -156,7 +156,7 @@ def zigate_callback_handler(self, msg, response, lqi): LOGGER.debug('APS Data confirm Fail %s %s', response[4], response[0]) self._handle_frame_failure(response[4], response[0]) elif msg == 0x9999: # ZCL event - LOGGER.debug('Extended error code %s', response[0]) + LOGGER.warning('Extended error code %s', response[0]) def _handle_frame_failure(self, message_tag, status): try: