Skip to content

Commit b5d5cea

Browse files
committed
Bring coverage up
1 parent 71b479a commit b5d5cea

2 files changed

Lines changed: 101 additions & 1 deletion

File tree

tests/test_application.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2607,3 +2607,25 @@ def test_on_packet_received_multicast(app: ControllerApplication) -> None:
26072607

26082608
# Verify packet_received was called with the same packet (dst already set)
26092609
assert packet_received_mock.mock_calls == [call(event.packet)]
2610+
2611+
2612+
async def test_on_message_sent_via_binding(app: ControllerApplication) -> None:
2613+
"""Test _on_message_sent with OUTGOING_VIA_BINDING message type."""
2614+
# Create a pending request future
2615+
future = asyncio.get_running_loop().create_future()
2616+
app._pending_requests[(0x1234, 0x42)] = future
2617+
2618+
event = MessageSentEvent(
2619+
status=t.sl_Status.OK,
2620+
message_type=t.EmberOutgoingMessageType.OUTGOING_VIA_BINDING,
2621+
destination=0x1234,
2622+
aps_frame=t.EmberApsFrame(),
2623+
message_tag=0x42,
2624+
message_contents=b"test",
2625+
)
2626+
2627+
app._on_message_sent(event)
2628+
2629+
# Verify the future was resolved
2630+
assert future.done()
2631+
assert future.result() == (t.sl_Status.OK, "message send success")

tests/test_ezsp_protocol.py

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
import zigpy.types
77

88
from bellows.ezsp import EZSP
9-
from bellows.ezsp.protocol import PacketReceivedEvent
9+
from bellows.ezsp.protocol import (
10+
IdConflictEvent,
11+
PacketReceivedEvent,
12+
RouteRecordEvent,
13+
TrustCenterJoinEvent,
14+
)
1015
import bellows.ezsp.v4
1116
import bellows.ezsp.v9
1217
from bellows.ezsp.v9.commands import GetTokenDataRsp
@@ -423,3 +428,76 @@ def test_incoming_message_ignored_type(prot_hndl, caplog) -> None:
423428
# No event should be emitted for ignored message types
424429
assert len(handler.mock_calls) == 0
425430
assert "Ignoring message type" in caplog.text
431+
432+
433+
def test_trust_center_join_handler(prot_hndl) -> None:
434+
"""Test trustCenterJoinHandler callback."""
435+
handler = MagicMock()
436+
prot_hndl.on_event(TrustCenterJoinEvent.event_type, handler)
437+
438+
ieee = t.EUI64.convert("aa:bb:cc:dd:ee:ff:00:11")
439+
prot_hndl.handle_parsed_callback(
440+
"trustCenterJoinHandler",
441+
{
442+
"newNodeId": t.EmberNodeId(0x1234),
443+
"newNodeEui64": ieee,
444+
"status": t.EmberDeviceUpdate.STANDARD_SECURITY_UNSECURED_JOIN,
445+
"policyDecision": t.EmberJoinDecision.NO_ACTION,
446+
"parentOfNewNodeId": t.EmberNodeId(0x0000),
447+
}.values(),
448+
)
449+
450+
assert handler.mock_calls == [
451+
call(
452+
TrustCenterJoinEvent(
453+
nwk=t.EmberNodeId(0x1234),
454+
ieee=ieee,
455+
device_update_status=t.EmberDeviceUpdate.STANDARD_SECURITY_UNSECURED_JOIN,
456+
decision=t.EmberJoinDecision.NO_ACTION,
457+
parent_nwk=t.EmberNodeId(0x0000),
458+
)
459+
)
460+
]
461+
462+
463+
def test_incoming_route_record_handler(prot_hndl) -> None:
464+
"""Test incomingRouteRecordHandler callback."""
465+
handler = MagicMock()
466+
prot_hndl.on_event(RouteRecordEvent.event_type, handler)
467+
468+
ieee = t.EUI64.convert("aa:bb:cc:dd:ee:ff:00:11")
469+
prot_hndl.handle_parsed_callback(
470+
"incomingRouteRecordHandler",
471+
{
472+
"source": t.EmberNodeId(0x1234),
473+
"sourceEui": ieee,
474+
"lastHopLqi": t.uint8_t(200),
475+
"lastHopRssi": t.int8s(-40),
476+
"relayList": [t.EmberNodeId(0x0001), t.EmberNodeId(0x0002)],
477+
}.values(),
478+
)
479+
480+
assert handler.mock_calls == [
481+
call(
482+
RouteRecordEvent(
483+
nwk=t.EmberNodeId(0x1234),
484+
ieee=ieee,
485+
lqi=t.uint8_t(200),
486+
rssi=t.int8s(-40),
487+
relays=[t.EmberNodeId(0x0001), t.EmberNodeId(0x0002)],
488+
)
489+
)
490+
]
491+
492+
493+
def test_id_conflict_handler(prot_hndl) -> None:
494+
"""Test idConflictHandler callback."""
495+
handler = MagicMock()
496+
prot_hndl.on_event(IdConflictEvent.event_type, handler)
497+
498+
prot_hndl.handle_parsed_callback(
499+
"idConflictHandler",
500+
{"conflictingId": t.EmberNodeId(0x1234)}.values(),
501+
)
502+
503+
assert handler.mock_calls == [call(IdConflictEvent(nwk=t.EmberNodeId(0x1234)))]

0 commit comments

Comments
 (0)