@@ -217,12 +217,18 @@ async def test_broadcast(app):
217217 assert app ._api ._command .call_args [0 ][9 ] == data
218218
219219 app ._api ._command .return_value = xbee_t .TXStatus .ADDRESS_NOT_FOUND
220- r = await app .broadcast (profile , cluster , src_ep , dst_ep , grpid , radius , tsn , data )
221- assert r [0 ] != xbee_t .TXStatus .SUCCESS
220+
221+ with pytest .raises (zigpy .exceptions .DeliveryError ):
222+ r = await app .broadcast (
223+ profile , cluster , src_ep , dst_ep , grpid , radius , tsn , data
224+ )
222225
223226 app ._api ._command .side_effect = asyncio .TimeoutError
224- r = await app .broadcast (profile , cluster , src_ep , dst_ep , grpid , radius , tsn , data )
225- assert r [0 ] != xbee_t .TXStatus .SUCCESS
227+
228+ with pytest .raises (zigpy .exceptions .DeliveryError ):
229+ r = await app .broadcast (
230+ profile , cluster , src_ep , dst_ep , grpid , radius , tsn , data
231+ )
226232
227233
228234async def test_get_association_state (app ):
@@ -242,6 +248,14 @@ async def test_form_network(app):
242248 async def mock_at_command (cmd , * args ):
243249 if cmd == "MY" :
244250 return 0x0000
251+ if cmd == "OI" :
252+ return 0x1234
253+ elif cmd == "ID" :
254+ return 0x1234567812345678
255+ elif cmd == "SL" :
256+ return 0x11223344
257+ elif cmd == "SH" :
258+ return 0x55667788
245259 elif cmd == "WR" :
246260 app ._api .coordinator_started_event .set ()
247261 elif cmd == "CE" and legacy_module :
@@ -393,25 +407,13 @@ async def test_permit(app):
393407
394408
395409async def _test_request (
396- app ,
397- expect_reply = True ,
398- send_success = True ,
399- send_timeout = False ,
400- is_end_device = True ,
401- node_desc = True ,
402- ** kwargs
410+ app , expect_reply = True , send_success = True , send_timeout = False , ** kwargs
403411):
404412 seq = 123
405413 nwk = 0x2345
406414 ieee = t .EUI64 (b"\x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 " )
407415 dev = app .add_device (ieee , nwk )
408416
409- if node_desc :
410- dev .node_desc = mock .MagicMock ()
411- dev .node_desc .is_end_device = is_end_device
412- else :
413- dev .node_desc = None
414-
415417 def _mock_command (
416418 cmdname , ieee , nwk , src_ep , dst_ep , cluster , profile , radius , options , data
417419 ):
@@ -437,42 +439,34 @@ def _mock_command(
437439 )
438440
439441
440- async def test_request_with_reply (app ):
441- r = await _test_request (app , expect_reply = True , send_success = True )
442+ async def test_request_with_ieee (app ):
443+ r = await _test_request (app , use_ieee = True , send_success = True )
442444 assert r [0 ] == 0
443445
444446
445- async def test_request_without_node_desc (app ):
446- r = await _test_request (app , expect_reply = True , send_success = True , node_desc = False )
447+ async def test_request_with_reply (app ):
448+ r = await _test_request (app , expect_reply = True , send_success = True )
447449 assert r [0 ] == 0
448450
449451
450452async def test_request_send_timeout (app ):
451- r = await _test_request ( app , send_timeout = True )
452- assert r [ 0 ] != 0
453+ with pytest . raises ( zigpy . exceptions . DeliveryError ):
454+ await _test_request ( app , send_timeout = True )
453455
454456
455457async def test_request_send_fail (app ):
456- r = await _test_request ( app , send_success = False )
457- assert r [ 0 ] != 0
458+ with pytest . raises ( zigpy . exceptions . DeliveryError ):
459+ await _test_request ( app , send_success = False )
458460
459461
460462async def test_request_extended_timeout (app ):
461- is_end_device = False
462- r = await _test_request (app , True , True , is_end_device = is_end_device )
463+ r = await _test_request (app , True , True , extended_timeout = False )
463464 assert r [0 ] == xbee_t .TXStatus .SUCCESS
464465 assert app ._api ._command .call_count == 1
465466 assert app ._api ._command .call_args [0 ][8 ] & 0x40 == 0x00
466467 app ._api ._command .reset_mock ()
467468
468- r = await _test_request (app , True , True , node_desc = False )
469- assert r [0 ] == xbee_t .TXStatus .SUCCESS
470- assert app ._api ._command .call_count == 1
471- assert app ._api ._command .call_args [0 ][8 ] & 0x40 == 0x40
472- app ._api ._command .reset_mock ()
473-
474- is_end_device = True
475- r = await _test_request (app , True , True , is_end_device = is_end_device )
469+ r = await _test_request (app , True , True , extended_timeout = True )
476470 assert r [0 ] == xbee_t .TXStatus .SUCCESS
477471 assert app ._api ._command .call_count == 1
478472 assert app ._api ._command .call_args [0 ][8 ] & 0x40 == 0x40
@@ -570,10 +564,26 @@ async def test_mrequest_with_reply(app):
570564
571565
572566async def test_mrequest_send_timeout (app ):
573- r = await _test_mrequest ( app , send_timeout = True )
574- assert r [ 0 ] != 0
567+ with pytest . raises ( zigpy . exceptions . DeliveryError ):
568+ await _test_mrequest ( app , send_timeout = True )
575569
576570
577571async def test_mrequest_send_fail (app ):
578- r = await _test_mrequest (app , send_success = False )
579- assert r [0 ] != 0
572+ with pytest .raises (zigpy .exceptions .DeliveryError ):
573+ await _test_mrequest (app , send_success = False )
574+
575+
576+ async def test_reset_network_info (app ):
577+ async def mock_at_command (cmd , * args ):
578+ if cmd == "NR" :
579+ return 0x00
580+
581+ return None
582+
583+ app ._api ._at_command = mock .MagicMock (
584+ spec = XBee ._at_command , side_effect = mock_at_command
585+ )
586+
587+ await app .reset_network_info ()
588+
589+ app ._api ._at_command .assert_called_once_with ("NR" , 0 )
0 commit comments