File tree 2 files changed +44
-1
lines changed 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -285,3 +285,36 @@ async def test_znp_unknown_frame(connected_znp, caplog):
285
285
286
286
# Unknown frames are logged in their entirety but an error is not thrown
287
287
assert repr (frame ) in caplog .text
288
+
289
+
290
+ async def test_handling_known_bad_command_parsing (connected_znp , caplog ):
291
+ znp , _ = connected_znp
292
+
293
+ bad_frame = GeneralFrame (
294
+ header = t .CommandHeader (
295
+ id = 0x9F , subsystem = t .Subsystem .ZDO , type = t .CommandType .AREQ
296
+ ),
297
+ data = b"\x13 \xDB \x84 \x01 \x21 " ,
298
+ )
299
+
300
+ caplog .set_level (logging .WARNING )
301
+ znp .frame_received (bad_frame )
302
+
303
+ # The frame is expected to fail to parse so will be logged as only a warning
304
+ assert len (caplog .records ) == 1
305
+ assert caplog .records [0 ].levelname == "WARNING"
306
+ assert repr (bad_frame ) in caplog .messages [0 ]
307
+
308
+
309
+ async def test_handling_unknown_bad_command_parsing (connected_znp ):
310
+ znp , _ = connected_znp
311
+
312
+ bad_frame = GeneralFrame (
313
+ header = t .CommandHeader (
314
+ id = 0xCB , subsystem = t .Subsystem .ZDO , type = t .CommandType .AREQ
315
+ ),
316
+ data = b"\x13 \xDB \x84 \x01 \x21 " ,
317
+ )
318
+
319
+ with pytest .raises (ValueError ):
320
+ znp .frame_received (bad_frame )
Original file line number Diff line number Diff line change @@ -358,7 +358,17 @@ def frame_received(self, frame: GeneralFrame) -> bool:
358
358
return
359
359
360
360
command_cls = c .COMMANDS_BY_ID [frame .header ]
361
- command = command_cls .from_frame (frame , align = self .nvram .align_structs )
361
+
362
+ try :
363
+ command = command_cls .from_frame (frame , align = self .nvram .align_structs )
364
+ except ValueError :
365
+ # Some commands can be received corrupted. They are not useful:
366
+ # https://github.com/home-assistant/core/issues/50005
367
+ if command_cls == c .ZDO .ParentAnnceRsp .Callback :
368
+ LOGGER .warning ("Failed to parse broken %s as %s" , frame , command_cls )
369
+ return
370
+
371
+ raise
362
372
363
373
LOGGER .debug ("Received command: %s" , command )
364
374
You can’t perform that action at this time.
0 commit comments