Skip to content

Commit f196f2c

Browse files
authored
Bail out on deserialization failure in data_received(). (#65)
Don't fall through data_received() handling, if deserialization throws an exception.
1 parent cf69f7e commit f196f2c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

zigpy_deconz/api.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def _api_frame(self, name, *args):
151151
def data_received(self, data):
152152
try:
153153
command = self._commands_by_id[data[0]]
154+
_, schema, solicited = RX_COMMANDS[command]
154155
except KeyError:
155156
LOGGER.debug("Unknown command received: 0x%02x", data[0])
156157
return
@@ -160,10 +161,14 @@ def data_received(self, data):
160161
except ValueError:
161162
status = data[2]
162163
try:
163-
data, _ = t.deserialize(data[5:], RX_COMMANDS[command][1])
164-
except Exception:
164+
data, _ = t.deserialize(data[5:], schema)
165+
except Exception as exc:
165166
LOGGER.warning("Failed to deserialize frame: %s", binascii.hexlify(data))
166-
if RX_COMMANDS[command][2] and seq in self._awaiting:
167+
if solicited and seq in self._awaiting:
168+
fut = self._awaiting.pop(seq)
169+
fut.set_exception(exc)
170+
return
171+
if solicited and seq in self._awaiting:
167172
fut = self._awaiting.pop(seq)
168173
if status != STATUS.SUCCESS:
169174
fut.set_exception(

0 commit comments

Comments
 (0)