Skip to content

Commit e7170c0

Browse files
committed
Handle LVList parameter binding and test LVList type errors
1 parent 1f6195f commit e7170c0

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

tests/test_commands.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,21 @@ def test_command_param_binding():
192192
)
193193
assert isinstance(cmd.Value, t.ShortBytes)
194194

195+
# Lists are converted to typed LVLists
196+
c.UtilCommands.BindAddEntry.Req(
197+
DstAddrModeAddr=t.AddrModeAddress(mode=t.AddrMode.NWK, address=0x1234),
198+
DstEndpoint=0x56,
199+
ClusterIdList=[0x12, 0x45],
200+
)
201+
202+
# Type errors within containers are also caught
203+
with pytest.raises(ValueError):
204+
c.UtilCommands.BindAddEntry.Req(
205+
DstAddrModeAddr=t.AddrModeAddress(mode=t.AddrMode.NWK, address=0x1234),
206+
DstEndpoint=0x56,
207+
ClusterIdList=[0x12, 0x457890], # 0x457890 doesn't fit into a uint8_t
208+
)
209+
195210

196211
def test_command_immutability():
197212
command1 = c.SysCommands.NVWrite.Req(

tests/test_types_basic.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ def test_lvlist():
111111

112112
assert isinstance(d, t.LVList(t.uint8_t))
113113

114+
with pytest.raises(OverflowError):
115+
t.LVList(t.uint8_t)([1, 2, 0xFFFF, 4]).serialize()
116+
114117

115118
def test_lvlist_too_short():
116119
with pytest.raises(ValueError):

zigpy_znp/commands/types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ def __init__(self, *, partial=False, **params):
318318
param.type, (t.ShortBytes, t.LongBytes)
319319
):
320320
value = param.type(value)
321+
elif isinstance(value, list) and issubclass(param.type, list):
322+
value = param.type(value)
321323
else:
322324
raise ValueError(
323325
f"In {type(self)}, param {param.name} is "

0 commit comments

Comments
 (0)