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
6 changes: 6 additions & 0 deletions bellows/ezsp/xncp.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ def from_payload(cls, payload: XncpCommandPayload) -> XncpCommand:
def from_bytes(cls, data: bytes) -> XncpCommand:
command_id, data = XncpCommandId.deserialize(data)
status, data = EmberStatus.deserialize(data)

if command_id not in COMMANDS:
raise ValueError(
f"Unknown XNCP command ID: 0x{command_id:04X} (payload {data!r})"
)

payload, rest = COMMANDS[command_id].deserialize(data)

if rest:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_xncp.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ async def test_xncp_failure_multiprotocol(ezsp_f: EZSP) -> None:
]


async def test_xncp_failure_lidl(ezsp_f: EZSP) -> None:
"""Test XNCP failure with hacked LIDL gateway."""
ezsp_f._mock_commands["customFrame"] = customFrame = AsyncMock(
return_value=[t.EmberStatus.SUCCESS, b"\x00\x01\x03"]
)

with pytest.raises(InvalidCommandError):
await ezsp_f.xncp_get_supported_firmware_features()

assert customFrame.mock_calls == [
call(xncp.XncpCommand.from_payload(xncp.GetSupportedFeaturesReq()).serialize())
]


async def test_xncp_failure_unknown(ezsp_f: EZSP) -> None:
"""Test XNCP failure, unknown command."""
ezsp_f._mock_commands["customFrame"] = customFrame = AsyncMock(
Expand Down
Loading