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
5 changes: 5 additions & 0 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,8 @@ def test_handle_reply_unexpected(app):
assert app.handle_message.call_args[0][6] == tsn
assert app.handle_message.call_args[0][7] == mock.sentinel.command_id
assert app.handle_message.call_args[0][8] == mock.sentinel.args


@pytest.mark.asyncio
async def test_force_remove(app):
await app.force_remove(mock.sentinel.device)
42 changes: 42 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from zigpy_xbee import types as t


def test_deserialize():
extra = b'\xBE\xEF'
data = b'\xff\xff\xfe01234567'
schema = (t.uint8_t, t.int16s, t.EUI64)
result, rest = t.deserialize(data + extra, schema)

assert rest == extra
assert result[0] == 0xff
assert result[1] == -2
assert result[2] == t.EUI64((0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37))


def test_serialize():
data = [0xff, -2, t.EUI64([t.uint8_t(i) for i in range(0x30, 0x38)])]
schema = (t.uint8_t, t.int16s, t.EUI64)
result = t.serialize(data, schema)

assert result == b'\xff\xff\xfe01234567'


def test_bytes_serialize():
data = 0x89ab.to_bytes(4, 'big')
result = t.Bytes(data).serialize()
assert result == data


def test_bytes_deserialize():
data, rest = t.Bytes.deserialize(0x89AB.to_bytes(3, 'big'))
assert data == b'\x00\x89\xAB'
assert rest == b''


def test_atcommand():
cmd = 'AI'.encode('ascii')
data = 0x06.to_bytes(4, 'big')
r_cmd, r_data = t.ATCommand.deserialize(cmd + data)

assert r_cmd == cmd
assert r_data == data
7 changes: 7 additions & 0 deletions tests/test_uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ def test_command_mode_rsp(gw):
assert gw._api.handle_command_mode_rsp.call_args[0][0] == 'OK'


def test_command_mode_rsp_decode_exc(gw):
data = b'OK\x81'
with pytest.raises(UnicodeDecodeError):
gw.command_mode_rsp(data)
assert gw._api.handle_command_mode_rsp.call_count == 0


def test_command_mode_send(gw):
data = b'ATAP2\x0D'
gw.command_mode_send(data)
Expand Down
6 changes: 4 additions & 2 deletions zigpy_xbee/uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ def command_mode_rsp(self, data):
"""Handles AT command mode response."""
try:
data = data.decode('ascii')
except Exception:
pass
except UnicodeDecodeError as ex:
LOGGER.debug("Couldn't ascii decode AT command mode response: %s",
ex)
raise
LOGGER.debug("Handling AT command mode response: %s", data)
self._api.handle_command_mode_rsp(data)

Expand Down