| 1 |
"""Tests for aioacaia.encoder command framing.""" |
| 2 |
|
| 3 |
from aioacaia.encoder import encode, encode_id, encode_notification_request |
| 4 |
|
| 5 |
|
| 6 |
def test_encode_frames_headers_type_and_split_checksum(): |
| 7 |
"""encode wraps the payload with headers, type and an even/odd checksum.""" |
| 8 |
assert encode(5, [1, 2, 3, 4]) == bytes.fromhex("efdd05010203040406") |
| 9 |
|
| 10 |
|
| 11 |
def test_encode_masks_payload_bytes_to_one_byte(): |
| 12 |
"""Payload values are masked to a single byte before framing.""" |
| 13 |
assert encode(0, [0x102, 0x1]) == bytes.fromhex("efdd0002010201") |
| 14 |
|
| 15 |
|
| 16 |
def test_encode_id_classic(): |
| 17 |
"""The classic identify payload is 15 dashes.""" |
| 18 |
assert encode_id(is_pyxis_style=False) == bytes.fromhex( |
| 19 |
"efdd0b2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d683b" |
| 20 |
) |
| 21 |
|
| 22 |
|
| 23 |
def test_encode_id_pyxis(): |
| 24 |
"""The pyxis identify payload is the ascii digits 012345678901234.""" |
| 25 |
assert encode_id(is_pyxis_style=True) == bytes.fromhex( |
| 26 |
"efdd0b3031323334353637383930313233349a6d" |
| 27 |
) |
| 28 |
|
| 29 |
|
| 30 |
def test_encode_notification_request(): |
| 31 |
"""The notification request subscribes to the expected event registers.""" |
| 32 |
assert encode_notification_request() == bytes.fromhex( |
| 33 |
"efdd0c0900010102020503041506" |
| 34 |
) |