Skip to content

Commit

Permalink
handle ZBOSS response with bad status
Browse files Browse the repository at this point in the history
  • Loading branch information
DamKast committed Nov 16, 2023
1 parent 587f7cd commit f8a6dbd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
5 changes: 1 addition & 4 deletions zigpy_zboss/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ def frame_received(self, frame: Frame) -> bool:

command_cls = c.COMMANDS_BY_ID[frame.hl_packet.header]

try:
command, _ = command_cls.from_frame(frame)
except ValueError:
raise
command = command_cls.from_frame(frame)

LOGGER.debug("Received command: %s", command)
matched = False
Expand Down
15 changes: 8 additions & 7 deletions zigpy_zboss/types/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,13 @@ def from_frame(cls, frame, *, align=False) -> "CommandBase":
else:
params[param.name], data = param.type.deserialize(data)
except ValueError:
if frame.hl_packet.header.control_type == ControlType.RSP:
# If the response to a request failed, the status code
# is different from 0 and the NCP does not send more data.
# Return a partial command object including the status.
status_code = params["StatusCode"]
if status_code != 0:
return cls(**params, partial=True)
if not data and param.optional:
# If we're out of data and the parameter is optional,
# we're done
Expand All @@ -517,13 +524,7 @@ def from_frame(cls, frame, *, align=False) -> "CommandBase":
else:
# Otherwise, let the exception happen
raise

# if data:
# raise ValueError(
# f"Frame {frame} contains trailing data after parsing: {data}"
# )

return cls(**params), data
return cls(**params)

def matches(self, other: "CommandBase") -> bool:
"""Match parameters and values with other CommandBase."""
Expand Down

0 comments on commit f8a6dbd

Please sign in to comment.