mirror of
https://github.com/meshcore-dev/meshcore_py.git
synced 2026-04-20 22:13:49 +00:00
Add channel commands and fix a lint error
This commit is contained in:
parent
d73979f234
commit
cca0ca90e9
6 changed files with 192 additions and 6 deletions
|
|
@ -255,4 +255,23 @@ async def test_send_with_multiple_expected_events_returns_first_completed(comman
|
|||
|
||||
# Verify that even though OK was listed first, the ERROR event was returned
|
||||
assert result.type == EventType.ERROR
|
||||
assert result.payload == error_payload
|
||||
assert result.payload == error_payload
|
||||
|
||||
# Channel command tests
|
||||
async def test_get_channel(command_handler, mock_connection):
|
||||
await command_handler.get_channel(3)
|
||||
assert mock_connection.send.call_args[0][0] == b"\x1f\x03"
|
||||
|
||||
async def test_set_channel(command_handler, mock_connection):
|
||||
channel_secret = bytes(range(16)) # 16 bytes: 0x00, 0x01, ..., 0x0f
|
||||
await command_handler.set_channel(5, "MyChannel", channel_secret)
|
||||
|
||||
expected_data = b"\x20\x05" # CMD_SET_CHANNEL + channel_idx=5
|
||||
expected_data += b"MyChannel" + b"\x00" * (32 - len("MyChannel")) # 32-byte padded name
|
||||
expected_data += channel_secret # 16-byte secret
|
||||
|
||||
assert mock_connection.send.call_args[0][0] == expected_data
|
||||
|
||||
async def test_set_channel_invalid_secret_length(command_handler):
|
||||
with pytest.raises(ValueError, match="Channel secret must be exactly 16 bytes"):
|
||||
await command_handler.set_channel(1, "Test", b"tooshort")
|
||||
|
|
@ -109,4 +109,19 @@ async def test_event_init_with_kwargs():
|
|||
|
||||
assert event.type == EventType.ACK
|
||||
assert event.payload == {"data": "value"}
|
||||
assert event.attributes == {"code": "1234", "status": "ok"}
|
||||
assert event.attributes == {"code": "1234", "status": "ok"}
|
||||
|
||||
async def test_channel_info_event():
|
||||
# Test CHANNEL_INFO event type
|
||||
channel_payload = {
|
||||
"channel_idx": 3,
|
||||
"channel_name": "TestChannel",
|
||||
"channel_secret": b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
|
||||
}
|
||||
|
||||
event = Event(EventType.CHANNEL_INFO, channel_payload)
|
||||
|
||||
assert event.type == EventType.CHANNEL_INFO
|
||||
assert event.payload["channel_idx"] == 3
|
||||
assert event.payload["channel_name"] == "TestChannel"
|
||||
assert len(event.payload["channel_secret"]) == 16
|
||||
Loading…
Add table
Add a link
Reference in a new issue