Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_security_iaswd_warning_mode(raw, mode, name):
"""Test warning command class of IasWD cluster."""
def _test(warning, data):
assert warning.serialize() == data
assert warning == raw
assert warning.mode == mode
assert warning.mode.name == name
warning.mode = mode
assert warning.serialize() == data
assert warning.mode == mode
data = types.uint8_t(raw).serialize()
_test(sec.IasWd.Warning(raw), data)
extra = b"The rest of the owl\xaa\x55"
warn, rest = sec.IasWd.Warning.deserialize(data + extra)
assert rest == extra
_test(warn, data)
repr(warn)
def test_struct_init():
class TestStruct(t.Struct):
a: t.uint8_t
b: t.uint16_t
c: t.CharacterString
ts = TestStruct(a=1, b=0x0100, c="TestStruct")
assert repr(ts)
assert isinstance(ts.a, t.uint8_t)
assert isinstance(ts.b, t.uint16_t)
assert isinstance(ts.c, t.CharacterString)
assert ts.a == 1
assert ts.b == 0x100
assert ts.c == "TestStruct"
ts2, remaining = TestStruct.deserialize(b"\x01\x00\x01\x0aTestStruct")
assert not remaining
assert ts == ts2
assert ts.serialize() == ts2.serialize()
ts3 = ts2.replace(b=0x0100)
assert ts3 == ts2
assert ts3.serialize() == ts2.serialize()
ts4 = ts2.replace(b=0x0101)
data = tsn.serialize()
extra = b"abcdefExtraDataHere"
hdr, rest = types.ZDOHeader.deserialize(cmd_id, data + extra)
assert rest == extra
assert hdr.tsn == tsn
assert hdr.command_id == cmd_id
assert hdr.is_reply is False
hdr.command_id = types.ZDOCmd.Bind_rsp
assert hdr.is_reply is True
assert hdr.serialize() == data
new_tsn = 0xBB
hdr.tsn = new_tsn
assert isinstance(hdr.tsn, t.uint8_t)
assert hdr.tsn == new_tsn
async def test_broadcast(app):
app.ieee = t.EUI64(map(t.uint8_t, [8, 9, 10, 11, 12, 13, 14, 15]))
(profile, cluster, src_ep, dst_ep, data) = (
zha.PROFILE_ID,
1,
2,
3,
b"\x02\x01\x00",
)
await device.broadcast(app, profile, cluster, src_ep, dst_ep, 0, 0, 123, data)
assert app.broadcast.call_count == 1
assert app.broadcast.call_args[0][0] == profile
assert app.broadcast.call_args[0][1] == cluster
assert app.broadcast.call_args[0][2] == src_ep
assert app.broadcast.call_args[0][3] == dst_ep
assert app.broadcast.call_args[0][7] == data
Unbind_rsp = 0x8022
# ... TODO optional stuff ...
# Network Management Server Services Responses
Mgmt_Lqi_rsp = 0x8031
Mgmt_Rtg_rsp = 0x8032
# ... TODO optional stuff ...
Mgmt_Leave_rsp = 0x8034
Mgmt_Permit_Joining_rsp = 0x8036
# ... TODO optional stuff ...
Mgmt_NWK_Update_rsp = 0x8038
CLUSTERS = {
# Device and Service Discovery Server Requests
ZDOCmd.NWK_addr_req: (IEEE, ("RequestType", t.uint8_t), ("StartIndex", t.uint8_t)),
ZDOCmd.IEEE_addr_req: (NWKI, ("RequestType", t.uint8_t), ("StartIndex", t.uint8_t)),
ZDOCmd.Node_Desc_req: (NWKI,),
ZDOCmd.Power_Desc_req: (NWKI,),
ZDOCmd.Simple_Desc_req: (NWKI, ("EndPoint", t.uint8_t)),
ZDOCmd.Active_EP_req: (NWKI,),
ZDOCmd.Match_Desc_req: (
NWKI,
("ProfileID", t.uint16_t),
("InClusterList", t.LVList(t.uint16_t)),
("OutClusterList", t.LVList(t.uint16_t)),
),
# ZDO.Complex_Desc_req: (NWKI, ),
ZDOCmd.User_Desc_req: (NWKI,),
ZDOCmd.Discovery_Cache_req: (NWK, IEEE),
ZDOCmd.Device_annce: (NWK, IEEE, ("Capability", t.uint8_t)),
ZDOCmd.User_Desc_set: (
NWKI,
if (AES.block_size - remaining_length) < 3:
(result_len, result) = aes_mmo_hash_update(result_len, result, temp)
# Since this extra data is due to the concatenation,
# we remove that length. We want the length of data only
# and not the padding.
result_len -= AES.block_size
temp = bytearray([0] * AES.block_size)
bit_size = result_len * 8
temp[AES.block_size - 2] = (bit_size >> 8) & 0xFF
temp[AES.block_size - 1] = (bit_size) & 0xFF
(result_len, result) = aes_mmo_hash_update(result_len, result, temp)
return t.KeyData([t.uint8_t(c) for c in result])
cluster_id = 0x001A
ep_attribute = "power_profile"
attributes = {
0x0000: ("total_profile_num", t.uint8_t),
0x0001: ("multiple_scheduling", t.uint8_t),
0x0002: ("energy_formatting", t.bitmap8),
0x0003: ("energy_remote", t.Bool),
0x0004: ("schedule_mode", t.bitmap8),
}
class ScheduleRecord(t.Struct):
phase_id: t.uint8_t
scheduled_time: t.uint16_t
class PowerProfilePhase(t.Struct):
energy_phase_id: t.uint8_t
macro_phase_id: t.uint8_t
expected_duration: t.uint16_t
peak_power: t.uint16_t
energy: t.uint16_t
class PowerProfile(t.Struct):
power_profile_id: t.uint8_t
energy_phase_id: t.uint8_t
power_profile_remote_control: t.Bool
power_profile_state: t.uint8_t
server_commands = {
0x0000: ("power_profile_request", (t.uint8_t,), False),
0x0001: ("power_profile_state_request", (), False),
0x0002: (
"get_power_profile_price_response",
def command_id(self, value: Command) -> None:
"""Setter for command identifier."""
if self.frame_control.is_general:
self._cmd_id = Command(value)
return
self._cmd_id = t.uint8_t(value)
return (
self.addrmode.to_bytes(1, "little")
+ self.ieee.serialize()
+ self.endpoint.to_bytes(1, "little")
)
else:
raise ValueError("Invalid value for addrmode")
class Neighbor(t.Struct):
"""Neighbor Descriptor"""
PanId: t.EUI64
IEEEAddr: t.EUI64
NWKAddr: t.NWK
NeighborType: t.uint8_t
PermitJoining: t.uint8_t
Depth: t.uint8_t
LQI: t.uint8_t
class Neighbors(t.Struct):
"""Mgmt_Lqi_rsp"""
Entries: t.uint8_t
StartIndex: t.uint8_t
NeighborTableList: t.LVList(Neighbor)
class Route(t.Struct):
"""Route Descriptor"""
def __init__(self, value: int = 0) -> None:
self.value = t.uint8_t(value)