Skip to content

Commit 7e1008e

Browse files
authored
Fix some EZSP v14 commands (#652)
* Fix some EZSP v14 commands * Remove unnecessary `from_ember_status` * Fix multicast broadcast address * Fix data type for sequence * Match old stack behavior * Add some unit tests * Use the correct calls in tests
1 parent 03dc152 commit 7e1008e

File tree

3 files changed

+102
-2
lines changed

3 files changed

+102
-2
lines changed

bellows/ezsp/v14/__init__.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,43 @@ async def get_tc_link_key(self) -> zigpy.state.Key:
8787

8888
return zigpy.state.Key(key=tc_link_key_data)
8989

90+
async def send_unicast(
91+
self,
92+
nwk: t.NWK,
93+
aps_frame: t.EmberApsFrame,
94+
message_tag: t.uint8_t,
95+
data: bytes,
96+
) -> tuple[t.sl_Status, t.uint8_t]:
97+
status, sequence = await self.sendUnicast(
98+
message_type=t.EmberOutgoingMessageType.OUTGOING_DIRECT,
99+
nwk=nwk,
100+
aps_frame=aps_frame,
101+
message_tag=message_tag,
102+
message=data,
103+
)
104+
105+
return status, sequence
106+
107+
async def send_multicast(
108+
self,
109+
aps_frame: t.EmberApsFrame,
110+
radius: t.uint8_t,
111+
non_member_radius: t.uint8_t,
112+
message_tag: t.uint8_t,
113+
data: bytes,
114+
) -> tuple[t.sl_Status, t.uint8_t]:
115+
status, sequence = await self.sendMulticast(
116+
aps_frame=aps_frame,
117+
hops=radius,
118+
broadcast_addr=t.BroadcastAddress.RX_ON_WHEN_IDLE,
119+
alias=0x0000,
120+
sequence=aps_frame.sequence,
121+
message_tag=message_tag,
122+
message=data,
123+
)
124+
125+
return status, sequence
126+
90127
async def send_broadcast(
91128
self,
92129
address: t.BroadcastAddress,

bellows/ezsp/v14/commands.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class GetTokenDataRsp(Struct):
113113
},
114114
),
115115
"sendBroadcast": (
116-
0x0034,
116+
0x0036,
117117
{
118118
"alias": t.uint16_t,
119119
"destination": BroadcastAddress,
@@ -128,6 +128,22 @@ class GetTokenDataRsp(Struct):
128128
"sequence": t.uint8_t,
129129
},
130130
),
131+
"sendMulticast": (
132+
0x0038,
133+
{
134+
"aps_frame": t.EmberApsFrame,
135+
"hops": t.uint8_t,
136+
"broadcast_addr": t.BroadcastAddress,
137+
"alias": t.uint16_t,
138+
"sequence": t.uint8_t,
139+
"message_tag": t.uint16_t,
140+
"message": t.LVBytes,
141+
},
142+
{
143+
"status": t.sl_Status,
144+
"sequence": t.uint8_t,
145+
},
146+
),
131147
"launchStandaloneBootloader": (
132148
0x008F,
133149
{

tests/test_ezsp_v14.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,55 @@ async def test_get_network_key_without_network(ezsp_f):
155155
await ezsp_f.get_network_key()
156156

157157

158+
async def test_send_unicast(ezsp_f) -> None:
159+
ezsp_f.sendUnicast.return_value = (t.sl_Status.OK, 0x0042)
160+
status, message_tag = await ezsp_f.send_unicast(
161+
nwk=0x1234,
162+
aps_frame=t.EmberApsFrame(),
163+
message_tag=0x42,
164+
data=b"hello",
165+
)
166+
167+
assert status == t.sl_Status.OK
168+
assert message_tag == 0x42
169+
assert ezsp_f.sendUnicast.mock_calls == [
170+
call(
171+
message_type=t.EmberOutgoingMessageType.OUTGOING_DIRECT,
172+
nwk=0x1234,
173+
aps_frame=t.EmberApsFrame(),
174+
message_tag=0x42,
175+
message=b"hello",
176+
)
177+
]
178+
179+
180+
async def test_send_multicast(ezsp_f) -> None:
181+
ezsp_f.sendMulticast.return_value = (t.sl_Status.OK, 0x0042)
182+
status, message_tag = await ezsp_f.send_multicast(
183+
aps_frame=t.EmberApsFrame(sequence=0x34),
184+
radius=12,
185+
non_member_radius=34,
186+
message_tag=0x42,
187+
data=b"hello",
188+
)
189+
190+
assert status == t.sl_Status.OK
191+
assert message_tag == 0x42
192+
assert ezsp_f.sendMulticast.mock_calls == [
193+
call(
194+
aps_frame=t.EmberApsFrame(sequence=0x34),
195+
hops=12,
196+
broadcast_addr=t.BroadcastAddress.RX_ON_WHEN_IDLE,
197+
alias=0x0000,
198+
sequence=0x34,
199+
message_tag=0x0042,
200+
message=b"hello",
201+
)
202+
]
203+
204+
158205
async def test_send_broadcast(ezsp_f) -> None:
159-
ezsp_f.sendBroadcast.return_value = (t.sl_Status.OK, 0x42)
206+
ezsp_f.sendBroadcast.return_value = (t.sl_Status.OK, 0x0042)
160207
status, message_tag = await ezsp_f.send_broadcast(
161208
address=t.BroadcastAddress.ALL_ROUTERS_AND_COORDINATOR,
162209
aps_frame=t.EmberApsFrame(),

0 commit comments

Comments
 (0)