Skip to content

handle response 0x8012 #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 20, 2022
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
24 changes: 24 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import binascii
from zigpy_zigate import types as t
from zigpy_zigate.api import RESPONSES, COMMANDS

Expand Down Expand Up @@ -63,6 +64,29 @@ 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)
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

# 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]
Expand Down
2 changes: 2 additions & 0 deletions zigpy_zigate/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
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),
0x8048: (t.EUI64, t.uint8_t),
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 = {
Expand Down
8 changes: 6 additions & 2 deletions zigpy_zigate/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -144,6 +144,8 @@ def zigate_callback_handler(self, msg, response, lqi):
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
Expand All @@ -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.warning('Extended error code %s', response[0])

def _handle_frame_failure(self, message_tag, status):
try:
Expand Down