Skip to content

Commit

Permalink
Fix Python 3.12.3 regression with enums (#616)
Browse files Browse the repository at this point in the history
* Migrate bellows to directly use zigpy types

* Convert `data` to bytes when dumping packets

* Fix LVBytes32 prefix type

* Fix failing EZSP protocol tests

* Fix broken data types

* Add undocumented `radius` field

* Revert "Add undocumented `radius` field"

This reverts commit 95e83bb.

* Remove unnecessary "bogus" value from unit tests
  • Loading branch information
puddly authored Apr 14, 2024
1 parent bf634b5 commit 7833647
Show file tree
Hide file tree
Showing 32 changed files with 170 additions and 587 deletions.
2 changes: 1 addition & 1 deletion bellows/cli/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def cb(frame_name, response):
hdr = pure_pcapy.Pkthdr(ts_sec, ts_usec, len(data), len(data))

try:
pcap.dump(hdr, data)
pcap.dump(hdr, bytes(data))
except BrokenPipeError:
done_event.set()

Expand Down
2 changes: 1 addition & 1 deletion bellows/cli/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def cb(fut, frame_name, response):
if isinstance(extended_pan_id, str):
extended_pan_id = util.parse_epan(extended_pan_id)
if extended_pan_id is None:
extended_pan_id = t.fixed_list(8, t.uint8_t)([t.uint8_t(0)] * 8)
extended_pan_id = t.FixedList[t.uint8_t, 8]([t.uint8_t(0)] * 8)

v = await util.network_init(s)

Expand Down
2 changes: 1 addition & 1 deletion bellows/cli/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ async def network_init(s):
def parse_epan(epan):
"""Parse a user specified extended PAN ID"""
epan_list = [t.uint8_t(x, 16) for x in epan.split(":")]
return t.fixed_list(8, t.uint8_t)(epan_list)
return t.FixedList[t.uint8_t, 8](epan_list)


async def basic_tc_permits(s):
Expand Down
22 changes: 11 additions & 11 deletions bellows/ezsp/v10/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
t.uint8_t,
t.uint8_t,
t.uint8_t,
t.List(t.uint16_t),
t.List(t.uint16_t),
t.List[t.uint16_t],
t.List[t.uint16_t],
),
(t.EzspStatus,),
),
Expand All @@ -35,8 +35,8 @@
"invalidCommand": (0x0058, (), (t.EzspStatus,)),
"callback": (0x0006, (), ()),
"noCallbacks": (0x0007, (), ()),
"setToken": (0x0009, (t.uint8_t, t.fixed_list(8, t.uint8_t)), (t.EmberStatus,)),
"getToken": (0x000A, (t.uint8_t,), (t.EmberStatus, t.fixed_list(8, t.uint8_t))),
"setToken": (0x0009, (t.uint8_t, t.FixedList[t.uint8_t, 8]), (t.EmberStatus,)),
"getToken": (0x000A, (t.uint8_t,), (t.EmberStatus, t.FixedList[t.uint8_t, 8])),
"getMfgToken": (0x000B, (t.EzspMfgTokenId,), (t.LVBytes,)),
"setMfgToken": (0x000C, (t.EzspMfgTokenId, t.LVBytes), (t.EmberStatus,)),
"stackTokenChangedHandler": (0x000D, (), (t.uint16_t,)),
Expand All @@ -52,12 +52,12 @@
"readAndClearCounters": (
0x0065,
(),
(t.fixed_list(len(t.EmberCounterType), t.uint16_t),),
(t.FixedList[t.uint16_t, len(t.EmberCounterType)],),
),
"readCounters": (
0x00F1,
(),
(t.fixed_list(len(t.EmberCounterType), t.uint16_t),),
(t.FixedList[t.uint16_t, len(t.EmberCounterType)],),
),
"counterRolloverHandler": (0x00F2, (), (t.EmberCounterType,)),
"delayTest": (0x009D, (t.uint16_t,), ()),
Expand Down Expand Up @@ -181,7 +181,7 @@
"getCurrentDutyCycle": (
0x004C,
(t.uint8_t,),
(t.EmberStatus, t.fixed_list(134, t.uint8_t)),
(t.EmberStatus, t.FixedList[t.uint8_t, 134]),
),
"dutyCycleHandler": (
0x004D,
Expand Down Expand Up @@ -306,7 +306,7 @@
"incomingRouteRecordHandler": (
0x0059,
(),
(t.EmberNodeId, t.EUI64, t.uint8_t, t.int8s, t.LVList(t.EmberNodeId)),
(t.EmberNodeId, t.EUI64, t.uint8_t, t.int8s, t.LVList[t.EmberNodeId]),
),
"incomingNetworkStatusHandler": (
0x00C4,
Expand All @@ -315,7 +315,7 @@
),
"setSourceRoute": (
0x00AE,
(t.EmberNodeId, t.LVList(t.EmberNodeId)),
(t.EmberNodeId, t.LVList[t.EmberNodeId]),
(t.EmberStatus,),
),
"setSourceRouteDiscoveryMode": (0x005A, (t.uint8_t,), (t.uint32_t,)),
Expand Down Expand Up @@ -550,8 +550,8 @@
"bootloadTransmitCompleteHandler": (0x0093, (), (t.EmberStatus, t.LVBytes)),
"aesEncrypt": (
0x0094,
(t.fixed_list(16, t.uint8_t), t.fixed_list(16, t.uint8_t)),
(t.fixed_list(16, t.uint8_t),),
(t.FixedList[t.uint8_t, 16], t.FixedList[t.uint8_t, 16]),
(t.FixedList[t.uint8_t, 16],),
),
# 14. ZLL Frames
"zllNetworkOps": (
Expand Down
4 changes: 2 additions & 2 deletions bellows/ezsp/v10/types/named.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,15 +702,15 @@ class SecureEzspSecurityLevel(basic.uint8_t):
"""Security level of the Secure EZSP Protocol."""


class SecureEzspRandomNumber(basic.fixed_list(16, basic.uint8_t)):
class SecureEzspRandomNumber(basic.FixedList[basic.uint8_t, 16]):
"""Randomly generated 64-bit number.
Both NCP and Host contribute this number to create the Session ID,
which is used in the nonce.
"""


class SecureEzspSessionId(basic.fixed_list(8, basic.uint8_t)):
class SecureEzspSessionId(basic.FixedList[basic.uint8_t, 8]):
"""Generated 64-bit Session ID, using random numbers from Host and NCP.
It is generated at each reboot (during negotiation phase). Having both sides
Expand Down
6 changes: 3 additions & 3 deletions bellows/ezsp/v10/types/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class EmberGpProxyTableEntry(EzspStruct):
# The security frame counter of the GPD.
gpdSecurityFrameCounter: named.EmberGpSecurityFrameCounter
# The list of sinks (hardcoded to 2 which is the spec minimum).
sinkList: basic.fixed_list(2, EmberGpSinkListEntry)
sinkList: basic.FixedList[EmberGpSinkListEntry, 2]
# The groupcast radius.
groupcastRadius: basic.uint8_t
# The search counter
Expand All @@ -160,7 +160,7 @@ class EmberGpSinkTableEntry(EzspStruct):
# The device id for the GPD.
deviceId: basic.uint8_t
# The list of sinks (hardcoded to 2 which is the spec minimum).
sinkList: basic.fixed_list(2, EmberGpSinkListEntry)
sinkList: basic.FixedList[EmberGpSinkListEntry, 2]
# The assigned alias for the GPD.
assignedAlias: named.EmberNodeId
# The groupcast radius.
Expand All @@ -185,7 +185,7 @@ class EmberDutyCycleLimits(EzspStruct):
# The vendor identifier field shall contain the vendor identifier of the node.
vendorId: basic.uint16_t
# The vendor string field shall contain the vendor string of the node.
vendorString: basic.fixed_list(7, basic.uint8_t)
vendorString: basic.FixedList[basic.uint8_t, 7]


class EmberPerDeviceDutyCycle(EzspStruct):
Expand Down
1 change: 0 additions & 1 deletion bellows/ezsp/v13/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
tuple(
{
"status": t.sl_Status,
"bogus": t.uint16_t,
"network_key_info": t.sl_zb_sec_man_network_key_info_t,
}.values()
),
Expand Down
22 changes: 11 additions & 11 deletions bellows/ezsp/v4/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
t.uint8_t,
t.uint8_t,
t.uint8_t,
t.List(t.uint16_t),
t.List(t.uint16_t),
t.List[t.uint16_t],
t.List[t.uint16_t],
),
(t.EzspStatus,),
),
Expand Down Expand Up @@ -47,8 +47,8 @@
"invalidCommand": (0x58, (), (t.EzspStatus,)),
"callback": (0x06, (), ()),
"noCallbacks": (0x07, (), ()),
"setToken": (0x09, (t.uint8_t, t.fixed_list(8, t.uint8_t)), (t.EmberStatus,)),
"getToken": (0x0A, (t.uint8_t,), (t.EmberStatus, t.fixed_list(8, t.uint8_t))),
"setToken": (0x09, (t.uint8_t, t.FixedList[t.uint8_t, 8]), (t.EmberStatus,)),
"getToken": (0x0A, (t.uint8_t,), (t.EmberStatus, t.FixedList[t.uint8_t, 8])),
"getMfgToken": (0x0B, (t.EzspMfgTokenId,), (t.LVBytes,)),
"setMfgToken": (0x0C, (t.EzspMfgTokenId, t.LVBytes), (t.EmberStatus,)),
"stackTokenChangedHandler": (0x0D, (), (t.uint16_t,)),
Expand All @@ -64,12 +64,12 @@
"readAndClearCounters": (
0x65,
(),
(t.fixed_list(len(t.EmberCounterType), t.uint16_t),),
(t.FixedList[t.uint16_t, len(t.EmberCounterType)],),
),
"readCounters": (
0xF1,
(),
(t.fixed_list(len(t.EmberCounterType), t.uint16_t),),
(t.FixedList[t.uint16_t, len(t.EmberCounterType)],),
),
"counterRolloverHandler": (0xF2, (), (t.EmberCounterType,)),
"delayTest": (0x9D, (t.uint16_t,), ()),
Expand Down Expand Up @@ -220,11 +220,11 @@
"incomingRouteRecordHandler": (
0x59,
(),
(t.EmberNodeId, t.EUI64, t.uint8_t, t.int8s, t.LVList(t.EmberNodeId)),
(t.EmberNodeId, t.EUI64, t.uint8_t, t.int8s, t.LVList[t.EmberNodeId]),
),
"setSourceRoute": (
0x5A,
(t.EmberNodeId, t.LVList(t.EmberNodeId)),
(t.EmberNodeId, t.LVList[t.EmberNodeId]),
(t.EmberStatus,),
),
"incomingManyToOneRouteRequestHandler": (
Expand Down Expand Up @@ -412,8 +412,8 @@
"bootloadTransmitCompleteHandler": (0x93, (), (t.EmberStatus, t.LVBytes)),
"aesEncrypt": (
0x94,
(t.fixed_list(16, t.uint8_t), t.fixed_list(16, t.uint8_t)),
(t.fixed_list(16, t.uint8_t),),
(t.FixedList[t.uint8_t, 16], t.FixedList[t.uint8_t, 16]),
(t.FixedList[t.uint8_t, 16],),
),
"overrideCurrentChannel": (0x95, (t.uint8_t,), (t.EmberStatus,)),
# 14. ZLL Frames
Expand Down Expand Up @@ -501,7 +501,7 @@
t.uint8_t,
t.uint16_t,
t.uint8_t,
t.LVList(t.uint8_t),
t.LVList[t.uint8_t],
),
(t.EmberStatus,),
),
Expand Down
10 changes: 5 additions & 5 deletions bellows/ezsp/v4/types/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class EmberRf4ceVendorInfo(EzspStruct):
# the node.
vendorId: basic.uint16_t
# The vendor string field shall contain the vendor string of the node.
vendorString: basic.fixed_list(7, basic.uint8_t)
vendorString: basic.FixedList[basic.uint8_t, 7]


class EmberRf4ceApplicationInfo(EzspStruct):
Expand All @@ -62,13 +62,13 @@ class EmberRf4ceApplicationInfo(EzspStruct):
capabilities: named.EmberRf4ceApplicationCapabilities
# The user string field shall contain the user specified identification
# string.
userString: basic.fixed_list(15, basic.uint8_t)
userString: basic.FixedList[basic.uint8_t, 15]
# The device type list field shall contain the list of device types
# supported by the node.
deviceTypeList: basic.fixed_list(3, basic.uint8_t)
deviceTypeList: basic.FixedList[basic.uint8_t, 3]
# The profile ID list field shall contain the list of profile
# identifiers disclosed as supported by the node.
profileIdList: basic.fixed_list(7, basic.uint8_t)
profileIdList: basic.FixedList[basic.uint8_t, 7]


class EmberRf4cePairingTableEntry(EzspStruct):
Expand All @@ -88,7 +88,7 @@ class EmberRf4cePairingTableEntry(EzspStruct):
# The vendor ID of the destination device.
destVendorId: basic.uint16_t
# The list of profiles supported by the destination device.
destProfileIdList: basic.fixed_list(7, basic.uint8_t)
destProfileIdList: basic.FixedList[basic.uint8_t, 7]
# The length of the list of supported profiles.
destProfileIdListLength: basic.uint8_t
# Info byte.
Expand Down
22 changes: 11 additions & 11 deletions bellows/ezsp/v5/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
t.uint8_t,
t.uint8_t,
t.uint8_t,
t.List(t.uint16_t),
t.List(t.uint16_t),
t.List[t.uint16_t],
t.List[t.uint16_t],
),
(t.EzspStatus,),
),
Expand Down Expand Up @@ -48,8 +48,8 @@
"invalidCommand": (0x58, (), (t.EzspStatus,)),
"callback": (0x06, (), ()),
"noCallbacks": (0x07, (), ()),
"setToken": (0x09, (t.uint8_t, t.fixed_list(8, t.uint8_t)), (t.EmberStatus,)),
"getToken": (0x0A, (t.uint8_t,), (t.EmberStatus, t.fixed_list(8, t.uint8_t))),
"setToken": (0x09, (t.uint8_t, t.FixedList[t.uint8_t, 8]), (t.EmberStatus,)),
"getToken": (0x0A, (t.uint8_t,), (t.EmberStatus, t.FixedList[t.uint8_t, 8])),
"getMfgToken": (0x0B, (t.EzspMfgTokenId,), (t.LVBytes,)),
"setMfgToken": (0x0C, (t.EzspMfgTokenId, t.LVBytes), (t.EmberStatus,)),
"stackTokenChangedHandler": (0x0D, (), (t.uint16_t,)),
Expand All @@ -65,12 +65,12 @@
"readAndClearCounters": (
0x65,
(),
(t.fixed_list(len(t.EmberCounterType), t.uint16_t),),
(t.FixedList[t.uint16_t, len(t.EmberCounterType)],),
),
"readCounters": (
0xF1,
(),
(t.fixed_list(len(t.EmberCounterType), t.uint16_t),),
(t.FixedList[t.uint16_t, len(t.EmberCounterType)],),
),
"counterRolloverHandler": (0xF2, (), (t.EmberCounterType,)),
"delayTest": (0x9D, (t.uint16_t,), ()),
Expand Down Expand Up @@ -221,12 +221,12 @@
"incomingRouteRecordHandler": (
0x59,
(),
(t.EmberNodeId, t.EUI64, t.uint8_t, t.int8s, t.LVList(t.EmberNodeId)),
(t.EmberNodeId, t.EUI64, t.uint8_t, t.int8s, t.LVList[t.EmberNodeId]),
),
"changeSourceRouteHandler": (0xC4, (), (t.EmberNodeId, t.EmberNodeId, t.Bool)),
"setSourceRoute": (
0x5A,
(t.EmberNodeId, t.LVList(t.EmberNodeId)),
(t.EmberNodeId, t.LVList[t.EmberNodeId]),
(t.EmberStatus,),
),
"incomingManyToOneRouteRequestHandler": (
Expand Down Expand Up @@ -419,8 +419,8 @@
"bootloadTransmitCompleteHandler": (0x93, (), (t.EmberStatus, t.LVBytes)),
"aesEncrypt": (
0x94,
(t.fixed_list(16, t.uint8_t), t.fixed_list(16, t.uint8_t)),
(t.fixed_list(16, t.uint8_t),),
(t.FixedList[t.uint8_t, 16], t.FixedList[t.uint8_t, 16]),
(t.FixedList[t.uint8_t, 16],),
),
"overrideCurrentChannel": (0x95, (t.uint8_t,), (t.EmberStatus,)),
# 14. ZLL Frames
Expand Down Expand Up @@ -508,7 +508,7 @@
t.uint8_t,
t.uint16_t,
t.uint8_t,
t.LVList(t.uint8_t),
t.LVList[t.uint8_t],
),
(t.EmberStatus,),
),
Expand Down
4 changes: 2 additions & 2 deletions bellows/ezsp/v5/types/named.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,15 +624,15 @@ class SecureEzspSecurityLevel(basic.uint8_t):
"""Security level of the Secure EZSP Protocol."""


class SecureEzspRandomNumber(basic.fixed_list(16, basic.uint8_t)):
class SecureEzspRandomNumber(basic.FixedList[basic.uint8_t, 16]):
"""Randomly generated 64-bit number.
Both NCP and Host contribute this number to create the Session ID,
which is used in the nonce.
"""


class SecureEzspSessionId(basic.fixed_list(8, basic.uint8_t)):
class SecureEzspSessionId(basic.FixedList[basic.uint8_t, 8]):
"""Generated 64-bit Session ID, using random numbers from Host and NCP.
It is generated at each reboot (during negotiation phase). Having both sides
Expand Down
10 changes: 5 additions & 5 deletions bellows/ezsp/v5/types/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class EmberRf4ceVendorInfo(EzspStruct):
# the node.
vendorId: basic.uint16_t
# The vendor string field shall contain the vendor string of the node.
vendorString: basic.fixed_list(7, basic.uint8_t)
vendorString: basic.FixedList[basic.uint8_t, 7]


class EmberRf4ceApplicationInfo(EzspStruct):
Expand All @@ -62,13 +62,13 @@ class EmberRf4ceApplicationInfo(EzspStruct):
capabilities: named.EmberRf4ceApplicationCapabilities
# The user string field shall contain the user specified identification
# string.
userString: basic.fixed_list(15, basic.uint8_t)
userString: basic.FixedList[basic.uint8_t, 15]
# The device type list field shall contain the list of device types
# supported by the node.
deviceTypeList: basic.fixed_list(3, basic.uint8_t)
deviceTypeList: basic.FixedList[basic.uint8_t, 3]
# The profile ID list field shall contain the list of profile
# identifiers disclosed as supported by the node.
profileIdList: basic.fixed_list(7, basic.uint8_t)
profileIdList: basic.FixedList[basic.uint8_t, 7]


class EmberRf4cePairingTableEntry(EzspStruct):
Expand All @@ -88,7 +88,7 @@ class EmberRf4cePairingTableEntry(EzspStruct):
# The vendor ID of the destination device.
destVendorId: basic.uint16_t
# The list of profiles supported by the destination device.
destProfileIdList: basic.fixed_list(7, basic.uint8_t)
destProfileIdList: basic.FixedList[basic.uint8_t, 7]
# The length of the list of supported profiles.
destProfileIdListLength: basic.uint8_t
# Info byte.
Expand Down
Loading

0 comments on commit 7833647

Please sign in to comment.