Skip to content

Commit 86153eb

Browse files
committed
Bring coverage up
1 parent c09cde8 commit 86153eb

File tree

1 file changed

+79
-1
lines changed

1 file changed

+79
-1
lines changed

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)