zigpy 2.1.0__tar.gz → 2.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {zigpy-2.1.0/zigpy.egg-info → zigpy-2.2.0}/PKG-INFO +1 -1
- {zigpy-2.1.0 → zigpy-2.2.0}/pyproject.toml +3 -4
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_appdb_migration.py +1 -1
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_backups.py +0 -1
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_struct.py +105 -1
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_types.py +104 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_zcl.py +141 -51
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/quirks/v2/__init__.py +0 -1
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/types/basic.py +51 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/types/struct.py +3 -2
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zcl/__init__.py +19 -2
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zcl/clusters/greenpower.py +4 -4
- zigpy-2.2.0/zigpy/zgp/__init__.py +45 -0
- zigpy-2.2.0/zigpy/zgp/commands.py +459 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zgp/types.py +32 -3
- {zigpy-2.1.0 → zigpy-2.2.0/zigpy.egg-info}/PKG-INFO +1 -1
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy.egg-info/SOURCES.txt +1 -1
- zigpy-2.1.0/zigpy/zgp/__init__.py +0 -21
- zigpy-2.1.0/zigpy/zgp/frame.py +0 -145
- {zigpy-2.1.0 → zigpy-2.2.0}/COPYING +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/LICENSE +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/README.md +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/setup.cfg +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/setup.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_app_state.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_appdb.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_application.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_config.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_datastructures.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_datastructures_cpython.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_device.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_endpoint.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_event.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_group.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_listeners.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_packet_callbacks.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_serial.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_topology.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_zcl_clusters.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_zcl_foundation.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_zcl_helpers.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_zdo.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_zdo_types.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tests/test_zigbee_util.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tools/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/tools/regenerate_mypy_ignores.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/appdb.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/appdb_schemas/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/appdb_schemas/schema_v0.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/appdb_schemas/schema_v1.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/appdb_schemas/schema_v10.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/appdb_schemas/schema_v11.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/appdb_schemas/schema_v12.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/appdb_schemas/schema_v13.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/appdb_schemas/schema_v14.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/appdb_schemas/schema_v15.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/appdb_schemas/schema_v2.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/appdb_schemas/schema_v3.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/appdb_schemas/schema_v4.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/appdb_schemas/schema_v5.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/appdb_schemas/schema_v6.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/appdb_schemas/schema_v7.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/appdb_schemas/schema_v8.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/appdb_schemas/schema_v9.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/application.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/backports/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/backups.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/config/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/config/defaults.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/config/validators.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/const.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/datastructures.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/device.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/endpoint.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/event/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/event/event_base.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/exceptions.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/group.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/listeners.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/ota/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/ota/image.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/ota/json_schemas.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/ota/manager.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/ota/providers.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/ota/validators.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/profiles/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/profiles/zgp.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/profiles/zha.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/profiles/zll.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/py.typed +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/quirks/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/quirks/registry.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/quirks/v2/homeassistant/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/quirks/v2/homeassistant/binary_sensor.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/quirks/v2/homeassistant/number.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/quirks/v2/homeassistant/sensor.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/serial.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/state.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/topology.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/types/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/types/named.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/typing.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/util.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zcl/clusters/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zcl/clusters/closures.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zcl/clusters/general.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zcl/clusters/general_const.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zcl/clusters/homeautomation.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zcl/clusters/hvac.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zcl/clusters/lighting.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zcl/clusters/lightlink.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zcl/clusters/manufacturer_specific.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zcl/clusters/measurement.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zcl/clusters/protocol.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zcl/clusters/security.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zcl/clusters/smartenergy.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zcl/clusters/wwah.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zcl/foundation.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zcl/helpers.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zdo/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zdo/types.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy/zgp/crypto.py +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy.egg-info/dependency_links.txt +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy.egg-info/requires.txt +0 -0
- {zigpy-2.1.0 → zigpy-2.2.0}/zigpy.egg-info/top_level.txt +0 -0
|
@@ -239,7 +239,6 @@ ignore = [
|
|
|
239
239
|
|
|
240
240
|
[tool.ruff.lint.per-file-ignores]
|
|
241
241
|
"tests/*.py" = [
|
|
242
|
-
"F811", # Redefinition of unused name from line N
|
|
243
242
|
"PIE794", # Class field defined multiple times
|
|
244
243
|
"PLC0206", # Extracting value from dictionary without calling `.items()`
|
|
245
244
|
"PLC0415", # `import` should be at the top-level of a file
|
|
@@ -484,10 +483,10 @@ disable_error_code = [
|
|
|
484
483
|
]
|
|
485
484
|
|
|
486
485
|
[[tool.mypy.overrides]]
|
|
487
|
-
module = "zigpy.zgp.
|
|
486
|
+
module = "zigpy.zgp.commands"
|
|
488
487
|
disable_error_code = [
|
|
489
|
-
"assignment", #
|
|
490
|
-
"attr-defined", #
|
|
488
|
+
"assignment", # 22
|
|
489
|
+
"attr-defined", # 27
|
|
491
490
|
]
|
|
492
491
|
# Autogenerated mypy overrides: end
|
|
493
492
|
|
|
@@ -8,7 +8,7 @@ from aiosqlite.context import contextmanager
|
|
|
8
8
|
import pytest
|
|
9
9
|
|
|
10
10
|
from tests.async_mock import AsyncMock, MagicMock, patch
|
|
11
|
-
from tests.conftest import
|
|
11
|
+
from tests.conftest import make_node_desc
|
|
12
12
|
from tests.test_appdb import make_app_with_db
|
|
13
13
|
import zigpy.appdb
|
|
14
14
|
import zigpy.appdb_schemas
|
|
@@ -620,7 +620,9 @@ def test_bitstruct_misaligned():
|
|
|
620
620
|
baz: t.uint7_t
|
|
621
621
|
|
|
622
622
|
s = TestStruct(foo=0b1, bar=0b10101010, baz=0b1110111)
|
|
623
|
-
|
|
623
|
+
|
|
624
|
+
# The segment spans two bytes, so the first byte holds the first-declared fields
|
|
625
|
+
assert s.serialize() == bytes([0b0101010_1, 0b1110111_1])
|
|
624
626
|
|
|
625
627
|
s2, remaining = TestStruct.deserialize(s.serialize() + b"asd")
|
|
626
628
|
assert s == s2
|
|
@@ -629,6 +631,108 @@ def test_bitstruct_misaligned():
|
|
|
629
631
|
TestStruct.deserialize(b"\xff")
|
|
630
632
|
|
|
631
633
|
|
|
634
|
+
def test_bitstruct_multi_byte_segment():
|
|
635
|
+
"""A bitfield segment wider than one byte is little-endian."""
|
|
636
|
+
|
|
637
|
+
class TestStruct(t.Struct):
|
|
638
|
+
foo: t.uint3_t
|
|
639
|
+
bar: t.uint1_t
|
|
640
|
+
baz: t.uint2_t
|
|
641
|
+
# This field straddles the byte boundary, so the whole struct is one segment
|
|
642
|
+
qux: t.uint3_t
|
|
643
|
+
quux: t.uint7_t
|
|
644
|
+
|
|
645
|
+
s = TestStruct(foo=0b101, bar=0b1, baz=0b10, qux=0b111, quux=0b1010101)
|
|
646
|
+
value = 0b101 | (0b1 << 3) | (0b10 << 4) | (0b111 << 6) | (0b1010101 << 9)
|
|
647
|
+
|
|
648
|
+
# A segment is laid out exactly like the integer of the same width would be
|
|
649
|
+
assert s.serialize() == t.uint16_t(value).serialize()
|
|
650
|
+
assert TestStruct.deserialize(s.serialize() + b"asd") == (s, b"asd")
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
def test_bitstruct_multi_byte_segment_enums(expose_global):
|
|
654
|
+
"""Sub-byte enums and bitmaps pack like the plain integers they derive from."""
|
|
655
|
+
|
|
656
|
+
@expose_global
|
|
657
|
+
class TestEnum(t.enum3):
|
|
658
|
+
FOO = 0b101
|
|
659
|
+
|
|
660
|
+
@expose_global
|
|
661
|
+
class TestBitmap(t.bitmap6):
|
|
662
|
+
BAR = 0b000010
|
|
663
|
+
BAZ = 0b100000
|
|
664
|
+
|
|
665
|
+
class TestStruct(t.Struct):
|
|
666
|
+
first: TestEnum
|
|
667
|
+
second: t.uint4_t
|
|
668
|
+
# Straddles the byte boundary
|
|
669
|
+
third: TestBitmap
|
|
670
|
+
fourth: t.uint3_t
|
|
671
|
+
|
|
672
|
+
s = TestStruct(
|
|
673
|
+
first=TestEnum.FOO,
|
|
674
|
+
second=0b1001,
|
|
675
|
+
third=TestBitmap.BAR | TestBitmap.BAZ,
|
|
676
|
+
fourth=0b110,
|
|
677
|
+
)
|
|
678
|
+
value = 0b101 | (0b1001 << 3) | (0b100010 << 7) | (0b110 << 13)
|
|
679
|
+
|
|
680
|
+
assert s.serialize() == t.uint16_t(value).serialize()
|
|
681
|
+
assert TestStruct.deserialize(s.serialize() + b"asd") == (s, b"asd")
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
def test_bitstruct_three_byte_segment():
|
|
685
|
+
"""Segments wider than two bytes are little-endian as well."""
|
|
686
|
+
|
|
687
|
+
class TestStruct(t.Struct):
|
|
688
|
+
foo: t.uint7_t
|
|
689
|
+
# Byte-serializable but misaligned, like every field after it
|
|
690
|
+
bar: t.uint8_t
|
|
691
|
+
baz: t.uint4_t
|
|
692
|
+
qux: t.uint5_t
|
|
693
|
+
|
|
694
|
+
s = TestStruct(foo=0b1010101, bar=0b11110000, baz=0b1001, qux=0b11011)
|
|
695
|
+
value = 0b1010101 | (0b11110000 << 7) | (0b1001 << 15) | (0b11011 << 19)
|
|
696
|
+
|
|
697
|
+
assert s.serialize() == t.uint24_t(value).serialize()
|
|
698
|
+
assert TestStruct.deserialize(s.serialize() + b"asd") == (s, b"asd")
|
|
699
|
+
|
|
700
|
+
|
|
701
|
+
def test_bitstruct_gp_commissioning_notification_options() -> None:
|
|
702
|
+
"""The GP commissioning notification options round trip."""
|
|
703
|
+
|
|
704
|
+
class CommissioningNotificationOptions(t.Struct):
|
|
705
|
+
application_id: t.uint3_t
|
|
706
|
+
rx_after_tx: t.uint1_t
|
|
707
|
+
security_level: t.uint2_t
|
|
708
|
+
security_key_type: t.uint3_t
|
|
709
|
+
security_failed: t.uint1_t
|
|
710
|
+
bidirectional_cap: t.uint1_t
|
|
711
|
+
proxy_info_present: t.uint1_t
|
|
712
|
+
_reserved: t.uint4_t
|
|
713
|
+
|
|
714
|
+
options = CommissioningNotificationOptions(
|
|
715
|
+
application_id=0b010,
|
|
716
|
+
rx_after_tx=1,
|
|
717
|
+
security_level=0b11,
|
|
718
|
+
security_key_type=0b111,
|
|
719
|
+
security_failed=1,
|
|
720
|
+
bidirectional_cap=0,
|
|
721
|
+
proxy_info_present=1,
|
|
722
|
+
_reserved=0,
|
|
723
|
+
)
|
|
724
|
+
|
|
725
|
+
value = (
|
|
726
|
+
0b010 | (1 << 3) | (0b11 << 4) | (0b111 << 6) | (1 << 9) | (0 << 10) | (1 << 11)
|
|
727
|
+
)
|
|
728
|
+
assert value == 0x0BFA
|
|
729
|
+
assert options.serialize() == b"\xfa\x0b"
|
|
730
|
+
assert options.serialize() == t.uint16_t(value).serialize()
|
|
731
|
+
assert CommissioningNotificationOptions.deserialize(
|
|
732
|
+
options.serialize() + b"asd"
|
|
733
|
+
) == (options, b"asd")
|
|
734
|
+
|
|
735
|
+
|
|
632
736
|
def test_non_byte_sized_struct():
|
|
633
737
|
class TestStruct(t.Struct):
|
|
634
738
|
foo: t.uint1_t
|
|
@@ -458,6 +458,110 @@ def test_fixedlist():
|
|
|
458
458
|
assert t.FixedList[t.uint8_t, 2]([1, 2]).serialize() == b"\x01\x02"
|
|
459
459
|
|
|
460
460
|
|
|
461
|
+
class VariableSizeItem(t.Struct):
|
|
462
|
+
"""Item whose serialized size depends on its contents."""
|
|
463
|
+
|
|
464
|
+
id: t.uint8_t
|
|
465
|
+
data: t.LVBytes
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
def test_size_prefixed_list() -> None:
|
|
469
|
+
lst, rest = t.SizePrefixedList[t.uint16_t, t.uint8_t].deserialize(
|
|
470
|
+
b"\x04\x01\x00\x02\x00" + b"leftover"
|
|
471
|
+
)
|
|
472
|
+
|
|
473
|
+
assert lst == [0x0001, 0x0002]
|
|
474
|
+
assert rest == b"leftover"
|
|
475
|
+
assert lst.serialize() == b"\x04\x01\x00\x02\x00"
|
|
476
|
+
assert isinstance(lst, t.SizePrefixedList[t.uint16_t, t.uint8_t])
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
def test_size_prefixed_list_empty() -> None:
|
|
480
|
+
lst, rest = t.SizePrefixedList[t.uint16_t, t.uint8_t].deserialize(b"\x00\xaa")
|
|
481
|
+
|
|
482
|
+
assert lst == []
|
|
483
|
+
assert rest == b"\xaa"
|
|
484
|
+
assert lst.serialize() == b"\x00"
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
def test_size_prefixed_list_variable_size_items() -> None:
|
|
488
|
+
"""The prefix delimits a region, so items may differ in size (unlike `LVList`)."""
|
|
489
|
+
items = b"\x01\x02ab" + b"\x02\x00" + b"\x03\x01c"
|
|
490
|
+
lst, rest = t.SizePrefixedList[VariableSizeItem, t.uint8_t].deserialize(
|
|
491
|
+
bytes([len(items)]) + items + b"\xff"
|
|
492
|
+
)
|
|
493
|
+
|
|
494
|
+
assert [(item.id, item.data) for item in lst] == [(1, b"ab"), (2, b""), (3, b"c")]
|
|
495
|
+
assert rest == b"\xff"
|
|
496
|
+
assert lst.serialize() == bytes([len(items)]) + items
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
def test_size_prefixed_list_size_type() -> None:
|
|
500
|
+
lst, rest = t.SizePrefixedList[t.uint16_t, t.uint16_t].deserialize(
|
|
501
|
+
b"\x04\x00\x01\x00\x02\x00"
|
|
502
|
+
)
|
|
503
|
+
|
|
504
|
+
assert lst == [0x0001, 0x0002]
|
|
505
|
+
assert rest == b""
|
|
506
|
+
assert lst.serialize() == b"\x04\x00\x01\x00\x02\x00"
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
def test_size_prefixed_list_misaligned_size() -> None:
|
|
510
|
+
"""A size that does not cover whole items is malformed, not silently truncated."""
|
|
511
|
+
with pytest.raises(ValueError):
|
|
512
|
+
t.SizePrefixedList[t.uint16_t, t.uint8_t].deserialize(b"\x03\x01\x00\x02\x00")
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
def test_size_prefixed_list_too_short() -> None:
|
|
516
|
+
with pytest.raises(ValueError):
|
|
517
|
+
t.SizePrefixedList[t.uint16_t, t.uint8_t].deserialize(b"")
|
|
518
|
+
|
|
519
|
+
with pytest.raises(ValueError, match="too short"):
|
|
520
|
+
t.SizePrefixedList[t.uint16_t, t.uint8_t].deserialize(b"\x08\x01\x00")
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
def test_size_prefixed_list_types() -> None:
|
|
524
|
+
# Brackets create singleton types
|
|
525
|
+
anon_lst1 = t.SizePrefixedList[t.uint16_t, t.uint8_t]
|
|
526
|
+
anon_lst2 = t.SizePrefixedList[t.uint16_t, t.uint8_t]
|
|
527
|
+
|
|
528
|
+
assert anon_lst1._size_type is t.uint8_t
|
|
529
|
+
assert anon_lst1._item_type is t.uint16_t
|
|
530
|
+
assert anon_lst1 is anon_lst2
|
|
531
|
+
assert not issubclass(
|
|
532
|
+
t.SizePrefixedList[t.uint16_t, t.uint8_t],
|
|
533
|
+
t.SizePrefixedList[t.uint8_t, t.uint16_t],
|
|
534
|
+
)
|
|
535
|
+
|
|
536
|
+
# Bracketed types are compatible with explicit subclasses
|
|
537
|
+
class SizePrefixedListSubclass(
|
|
538
|
+
t.SizePrefixedList, item_type=t.uint16_t, size_type=t.uint8_t
|
|
539
|
+
):
|
|
540
|
+
pass
|
|
541
|
+
|
|
542
|
+
assert issubclass(
|
|
543
|
+
SizePrefixedListSubclass, t.SizePrefixedList[t.uint16_t, t.uint8_t]
|
|
544
|
+
)
|
|
545
|
+
assert isinstance(
|
|
546
|
+
SizePrefixedListSubclass(), t.SizePrefixedList[t.uint16_t, t.uint8_t]
|
|
547
|
+
)
|
|
548
|
+
|
|
549
|
+
# A count-prefixed list and a size-prefixed one are never interchangeable, as their
|
|
550
|
+
# length prefixes mean different things on the wire
|
|
551
|
+
assert not issubclass(
|
|
552
|
+
t.SizePrefixedList[t.uint8_t, t.uint8_t], t.LVList[t.uint8_t, t.uint8_t]
|
|
553
|
+
)
|
|
554
|
+
assert not issubclass(
|
|
555
|
+
t.LVList[t.uint8_t, t.uint8_t], t.SizePrefixedList[t.uint8_t, t.uint8_t]
|
|
556
|
+
)
|
|
557
|
+
assert not isinstance(
|
|
558
|
+
t.LVList[t.uint8_t, t.uint8_t](), t.SizePrefixedList[t.uint8_t, t.uint8_t]
|
|
559
|
+
)
|
|
560
|
+
assert not isinstance(
|
|
561
|
+
t.SizePrefixedList[t.uint8_t, t.uint8_t](), t.LVList[t.uint8_t, t.uint8_t]
|
|
562
|
+
)
|
|
563
|
+
|
|
564
|
+
|
|
461
565
|
def test_lvlist_types():
|
|
462
566
|
# Brackets create singleton types
|
|
463
567
|
anon_lst1 = t.LVList[t.uint16_t, t.uint8_t]
|
|
@@ -1932,7 +1932,8 @@ def test_find_attributes() -> None:
|
|
|
1932
1932
|
TestCluster.find_attributes(0x0002, manufacturer_code=0xABCD)
|
|
1933
1933
|
|
|
1934
1934
|
|
|
1935
|
-
|
|
1935
|
+
@pytest.mark.parametrize("split_requests", [True, False])
|
|
1936
|
+
async def test_read_attributes_complex(split_requests: bool) -> None:
|
|
1936
1937
|
"""Test reading attributes, complex scenario."""
|
|
1937
1938
|
|
|
1938
1939
|
class TestCluster(zcl.Cluster):
|
|
@@ -1944,6 +1945,14 @@ async def test_read_attributes_complex() -> None:
|
|
|
1944
1945
|
attribute1 = foundation.ZCLAttributeDef(id=0x0001, type=t.uint8_t)
|
|
1945
1946
|
attribute2 = foundation.ZCLAttributeDef(id=0x0002, type=t.uint8_t)
|
|
1946
1947
|
|
|
1948
|
+
# Six attributes without a manufacturer code in total, so that group spans
|
|
1949
|
+
# two requests with splitting enabled (MAX_READ_ATTRIBUTES_PER_REQ is 5)
|
|
1950
|
+
# and exactly one with it disabled
|
|
1951
|
+
attribute7 = foundation.ZCLAttributeDef(id=0x0003, type=t.uint8_t)
|
|
1952
|
+
attribute8 = foundation.ZCLAttributeDef(id=0x0004, type=t.uint8_t)
|
|
1953
|
+
attribute9 = foundation.ZCLAttributeDef(id=0x0005, type=t.uint8_t)
|
|
1954
|
+
attribute10 = foundation.ZCLAttributeDef(id=0x0006, type=t.uint8_t)
|
|
1955
|
+
|
|
1947
1956
|
# These two can be read together
|
|
1948
1957
|
attribute3 = foundation.ZCLAttributeDef(
|
|
1949
1958
|
id=0x0001, type=t.uint8_t, manufacturer_code=0x1234
|
|
@@ -1966,54 +1975,71 @@ async def test_read_attributes_complex() -> None:
|
|
|
1966
1975
|
async def mock_read_attributes(
|
|
1967
1976
|
attribute_ids: list[int], manufacturer: int | None = None, **kwargs
|
|
1968
1977
|
):
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
),
|
|
1979
|
-
),
|
|
1980
|
-
# The other is not
|
|
1981
|
-
foundation.ReadAttributeRecord(
|
|
1982
|
-
attrid=0x0002,
|
|
1983
|
-
status=foundation.Status.UNSUPPORTED_ATTRIBUTE,
|
|
1978
|
+
# The attributes without a manufacturer code are split across two requests
|
|
1979
|
+
# or read in one, depending on `split_requests`, so respond per attribute ID
|
|
1980
|
+
no_manuf_code_records = {
|
|
1981
|
+
# This one is supported
|
|
1982
|
+
0x0001: foundation.ReadAttributeRecord(
|
|
1983
|
+
attrid=0x0001,
|
|
1984
|
+
status=foundation.Status.SUCCESS,
|
|
1985
|
+
value=foundation.TypeValue(
|
|
1986
|
+
type=foundation.DataTypeId.uint8,
|
|
1987
|
+
value=t.uint8_t(123),
|
|
1984
1988
|
),
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1989
|
+
),
|
|
1990
|
+
# This one is not
|
|
1991
|
+
0x0002: foundation.ReadAttributeRecord(
|
|
1992
|
+
attrid=0x0002,
|
|
1993
|
+
status=foundation.Status.UNSUPPORTED_ATTRIBUTE,
|
|
1994
|
+
),
|
|
1995
|
+
**{
|
|
1996
|
+
attrid: foundation.ReadAttributeRecord(
|
|
1997
|
+
attrid=attrid,
|
|
1990
1998
|
status=foundation.Status.SUCCESS,
|
|
1991
1999
|
value=foundation.TypeValue(
|
|
1992
2000
|
type=foundation.DataTypeId.uint8,
|
|
1993
|
-
value=t.uint8_t(
|
|
2001
|
+
value=t.uint8_t(attrid),
|
|
1994
2002
|
),
|
|
1995
|
-
)
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2003
|
+
)
|
|
2004
|
+
for attrid in (0x0003, 0x0004, 0x0005, 0x0006)
|
|
2005
|
+
},
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
if manufacturer is None:
|
|
2009
|
+
status_records = [no_manuf_code_records[attrid] for attrid in attribute_ids]
|
|
2010
|
+
else:
|
|
2011
|
+
status_records = {
|
|
2012
|
+
(0x1234, (0x0001, 0x0002)): [
|
|
2013
|
+
# Both are supported
|
|
2014
|
+
foundation.ReadAttributeRecord(
|
|
2015
|
+
attrid=0x0001,
|
|
2016
|
+
status=foundation.Status.SUCCESS,
|
|
2017
|
+
value=foundation.TypeValue(
|
|
2018
|
+
type=foundation.DataTypeId.uint8,
|
|
2019
|
+
value=t.uint8_t(12),
|
|
2020
|
+
),
|
|
2002
2021
|
),
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2022
|
+
foundation.ReadAttributeRecord(
|
|
2023
|
+
attrid=0x0002,
|
|
2024
|
+
status=foundation.Status.SUCCESS,
|
|
2025
|
+
value=foundation.TypeValue(
|
|
2026
|
+
type=foundation.DataTypeId.uint8,
|
|
2027
|
+
value=t.uint8_t(34),
|
|
2028
|
+
),
|
|
2029
|
+
),
|
|
2030
|
+
],
|
|
2031
|
+
(0x5678, (0x0003, 0x0004)): [
|
|
2032
|
+
# Neither of these are supported
|
|
2033
|
+
foundation.ReadAttributeRecord(
|
|
2034
|
+
attrid=0x0003,
|
|
2035
|
+
status=foundation.Status.UNSUPPORTED_ATTRIBUTE,
|
|
2036
|
+
),
|
|
2037
|
+
foundation.ReadAttributeRecord(
|
|
2038
|
+
attrid=0x0004,
|
|
2039
|
+
status=foundation.Status.UNSUPPORTED_ATTRIBUTE,
|
|
2040
|
+
),
|
|
2041
|
+
],
|
|
2042
|
+
}[manufacturer, tuple(attribute_ids)]
|
|
2017
2043
|
|
|
2018
2044
|
return foundation.GENERAL_COMMANDS[
|
|
2019
2045
|
foundation.GeneralCommand.Read_Attributes_rsp
|
|
@@ -2032,13 +2058,22 @@ async def test_read_attributes_complex() -> None:
|
|
|
2032
2058
|
TestCluster.AttributeDefs.attribute2, # Batch 1 (no code)
|
|
2033
2059
|
TestCluster.AttributeDefs.attribute4, # Batch 2 (0x5678)
|
|
2034
2060
|
TestCluster.AttributeDefs.attribute6, # Batch 3 (0x1234)
|
|
2035
|
-
|
|
2061
|
+
TestCluster.AttributeDefs.attribute7, # Batch 1 (no code)
|
|
2062
|
+
TestCluster.AttributeDefs.attribute8, # Batch 1 (no code)
|
|
2063
|
+
TestCluster.AttributeDefs.attribute9, # Batch 1 (no code)
|
|
2064
|
+
TestCluster.AttributeDefs.attribute10, # Batch 1 (no code)
|
|
2065
|
+
],
|
|
2066
|
+
split_requests=split_requests,
|
|
2036
2067
|
)
|
|
2037
2068
|
|
|
2038
2069
|
assert success == {
|
|
2039
2070
|
TestCluster.AttributeDefs.attribute1: 123,
|
|
2040
2071
|
TestCluster.AttributeDefs.attribute3: 12,
|
|
2041
2072
|
TestCluster.AttributeDefs.attribute4: 34,
|
|
2073
|
+
TestCluster.AttributeDefs.attribute7: 0x0003,
|
|
2074
|
+
TestCluster.AttributeDefs.attribute8: 0x0004,
|
|
2075
|
+
TestCluster.AttributeDefs.attribute9: 0x0005,
|
|
2076
|
+
TestCluster.AttributeDefs.attribute10: 0x0006,
|
|
2042
2077
|
}
|
|
2043
2078
|
|
|
2044
2079
|
assert failure == {
|
|
@@ -2047,11 +2082,22 @@ async def test_read_attributes_complex() -> None:
|
|
|
2047
2082
|
TestCluster.AttributeDefs.attribute6: foundation.Status.UNSUPPORTED_ATTRIBUTE,
|
|
2048
2083
|
}
|
|
2049
2084
|
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2085
|
+
if split_requests:
|
|
2086
|
+
# The six attributes without a manufacturer code need two requests
|
|
2087
|
+
assert mock_raw.mock_calls == [
|
|
2088
|
+
call([0x0001, 0x0002, 0x0003, 0x0004, 0x0005], manufacturer=None),
|
|
2089
|
+
call([0x0006], manufacturer=None),
|
|
2090
|
+
call([0x0003, 0x0004], manufacturer=0x5678),
|
|
2091
|
+
call([0x0001, 0x0002], manufacturer=0x1234),
|
|
2092
|
+
]
|
|
2093
|
+
else:
|
|
2094
|
+
# They all fit into a single request, but the manufacturer code grouping
|
|
2095
|
+
# still applies
|
|
2096
|
+
assert mock_raw.mock_calls == [
|
|
2097
|
+
call([0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006], manufacturer=None),
|
|
2098
|
+
call([0x0003, 0x0004], manufacturer=0x5678),
|
|
2099
|
+
call([0x0001, 0x0002], manufacturer=0x1234),
|
|
2100
|
+
]
|
|
2055
2101
|
|
|
2056
2102
|
|
|
2057
2103
|
async def test_command_explicit_manufacturer():
|
|
@@ -2640,6 +2686,47 @@ async def test_read_attributes_chunked_by_count(app_mock) -> None:
|
|
|
2640
2686
|
}
|
|
2641
2687
|
|
|
2642
2688
|
|
|
2689
|
+
async def test_read_attributes_unsplit(app_mock) -> None:
|
|
2690
|
+
"""Read_attributes sends a single request when splitting is disabled."""
|
|
2691
|
+
|
|
2692
|
+
class TestCluster(Basic):
|
|
2693
|
+
_skip_registry = True
|
|
2694
|
+
|
|
2695
|
+
class AttributeDefs(Basic.AttributeDefs):
|
|
2696
|
+
attr_0 = foundation.ZCLAttributeDef(id=0xFF00, type=t.uint8_t)
|
|
2697
|
+
attr_1 = foundation.ZCLAttributeDef(id=0xFF01, type=t.uint8_t)
|
|
2698
|
+
attr_2 = foundation.ZCLAttributeDef(id=0xFF02, type=t.uint8_t)
|
|
2699
|
+
attr_3 = foundation.ZCLAttributeDef(id=0xFF03, type=t.uint8_t)
|
|
2700
|
+
attr_4 = foundation.ZCLAttributeDef(id=0xFF04, type=t.uint8_t)
|
|
2701
|
+
attr_5 = foundation.ZCLAttributeDef(id=0xFF05, type=t.uint8_t)
|
|
2702
|
+
attr_6 = foundation.ZCLAttributeDef(id=0xFF06, type=t.uint8_t)
|
|
2703
|
+
attr_7 = foundation.ZCLAttributeDef(id=0xFF07, type=t.uint8_t)
|
|
2704
|
+
attr_8 = foundation.ZCLAttributeDef(id=0xFF08, type=t.uint8_t)
|
|
2705
|
+
attr_9 = foundation.ZCLAttributeDef(id=0xFF09, type=t.uint8_t)
|
|
2706
|
+
attr_10 = foundation.ZCLAttributeDef(id=0xFF0A, type=t.uint8_t)
|
|
2707
|
+
|
|
2708
|
+
dev = add_initialized_device(app_mock, nwk=0x1234, ieee=make_ieee(1))
|
|
2709
|
+
cluster = TestCluster(dev.endpoints[1])
|
|
2710
|
+
dev.endpoints[1].add_input_cluster(TestCluster.cluster_id, cluster)
|
|
2711
|
+
|
|
2712
|
+
attrs = [getattr(TestCluster.AttributeDefs, f"attr_{i}") for i in range(11)]
|
|
2713
|
+
|
|
2714
|
+
# Exclude 2 and 7 so the mock returns UNSUPPORTED
|
|
2715
|
+
supported = {attr: i for i, attr in enumerate(attrs) if i not in (2, 7)}
|
|
2716
|
+
with mock_attribute_reads(cluster, supported) as (mock_read, _):
|
|
2717
|
+
success, failure = await cluster.read_attributes(attrs, split_requests=False)
|
|
2718
|
+
|
|
2719
|
+
# All 11 attributes are requested in a single request, in order
|
|
2720
|
+
chunks = [call_obj.args[0] for call_obj in mock_read.call_args_list]
|
|
2721
|
+
assert chunks == [[attr.id for attr in attrs]]
|
|
2722
|
+
|
|
2723
|
+
assert success == supported
|
|
2724
|
+
assert failure == {
|
|
2725
|
+
attrs[2]: foundation.Status.UNSUPPORTED_ATTRIBUTE,
|
|
2726
|
+
attrs[7]: foundation.Status.UNSUPPORTED_ATTRIBUTE,
|
|
2727
|
+
}
|
|
2728
|
+
|
|
2729
|
+
|
|
2643
2730
|
async def test_read_attributes_insufficient_space_retry_success(app_mock) -> None:
|
|
2644
2731
|
"""An INSUFFICIENT_SPACE record is re-read individually and can then succeed."""
|
|
2645
2732
|
|
|
@@ -2801,8 +2888,9 @@ async def test_read_attributes_insufficient_space_single_chunk_no_retry(
|
|
|
2801
2888
|
|
|
2802
2889
|
|
|
2803
2890
|
@pytest.mark.parametrize("omitted_again", [False, True])
|
|
2891
|
+
@pytest.mark.parametrize("split_requests", [True, False])
|
|
2804
2892
|
async def test_read_attributes_omitted_record_retry(
|
|
2805
|
-
app_mock, omitted_again: bool
|
|
2893
|
+
app_mock, omitted_again: bool, split_requests: bool
|
|
2806
2894
|
) -> None:
|
|
2807
2895
|
"""Records omitted from a response are re-read individually (ZCL R8 §2.5.2.3)."""
|
|
2808
2896
|
|
|
@@ -2827,7 +2915,9 @@ async def test_read_attributes_omitted_record_retry(
|
|
|
2827
2915
|
}
|
|
2828
2916
|
|
|
2829
2917
|
with mock_attribute_reads(cluster, supported) as (mock_read, _):
|
|
2830
|
-
success, failure = await cluster.read_attributes(
|
|
2918
|
+
success, failure = await cluster.read_attributes(
|
|
2919
|
+
attrs, split_requests=split_requests
|
|
2920
|
+
)
|
|
2831
2921
|
|
|
2832
2922
|
if omitted_again:
|
|
2833
2923
|
assert success == {TestCluster.AttributeDefs.attr_0: 10}
|
|
@@ -17,7 +17,6 @@ import warnings
|
|
|
17
17
|
_MOVED_NAMES: dict[str, tuple[str, str]] = {
|
|
18
18
|
"CustomDeviceV2": ("zhaquirks.device", "CustomZigpyDevice"),
|
|
19
19
|
"QuirkBuilder": ("zhaquirks.builder", "QuirkBuilder"),
|
|
20
|
-
"UNBUILT_QUIRK_BUILDERS": ("zhaquirks.builder", "UNBUILT_QUIRK_BUILDERS"),
|
|
21
20
|
"ReportingConfig": ("zhaquirks.builder.metadata", "ReportingConfig"),
|
|
22
21
|
"EntityMetadata": ("zhaquirks.builder.metadata", "EntityMetadata"),
|
|
23
22
|
"ZCLEnumMetadata": ("zhaquirks.builder.metadata", "ZCLEnumMetadata"),
|
|
@@ -1104,6 +1104,57 @@ class LVList(list, Generic[_T, _V], metaclass=KwargTypeMeta):
|
|
|
1104
1104
|
return r, data
|
|
1105
1105
|
|
|
1106
1106
|
|
|
1107
|
+
class SizePrefixedList(list, Generic[_T, _V], metaclass=KwargTypeMeta):
|
|
1108
|
+
"""List prefixed by the total size in octets of its serialized items.
|
|
1109
|
+
|
|
1110
|
+
Where `LVList` counts items, the prefix here delimits the region the items occupy,
|
|
1111
|
+
so the items themselves may vary in size. Items are read until that region is
|
|
1112
|
+
exactly consumed; anything else is malformed.
|
|
1113
|
+
"""
|
|
1114
|
+
|
|
1115
|
+
_item_type: type[_T] | None
|
|
1116
|
+
_size_type: type[_V] = uint8_t
|
|
1117
|
+
|
|
1118
|
+
_getitem_kwargs = {"item_type": None, "size_type": uint8_t}
|
|
1119
|
+
|
|
1120
|
+
def __init_subclass__(
|
|
1121
|
+
cls, item_type: type[_T] | None = None, size_type: type[_V] | None = None
|
|
1122
|
+
) -> None:
|
|
1123
|
+
if item_type is not None:
|
|
1124
|
+
cls._item_type = item_type
|
|
1125
|
+
|
|
1126
|
+
if size_type is not None:
|
|
1127
|
+
cls._size_type = size_type
|
|
1128
|
+
|
|
1129
|
+
def serialize(self) -> bytes:
|
|
1130
|
+
assert self._size_type is not None
|
|
1131
|
+
assert self._item_type is not None
|
|
1132
|
+
|
|
1133
|
+
items = b"".join([self._item_type(i).serialize() for i in self])
|
|
1134
|
+
|
|
1135
|
+
return self._size_type(len(items)).serialize() + items
|
|
1136
|
+
|
|
1137
|
+
@classmethod
|
|
1138
|
+
def deserialize(cls, data: bytes) -> tuple[Self, bytes]:
|
|
1139
|
+
assert cls._size_type is not None
|
|
1140
|
+
assert cls._item_type is not None
|
|
1141
|
+
|
|
1142
|
+
size, data = cls._size_type.deserialize(data)
|
|
1143
|
+
|
|
1144
|
+
# Without this the region would be silently truncated to the data on hand
|
|
1145
|
+
if len(data) < size:
|
|
1146
|
+
raise ValueError(f"Data is too short to contain {size} bytes: {data!r}")
|
|
1147
|
+
|
|
1148
|
+
chunk, data = data[:size], data[size:]
|
|
1149
|
+
r = cls()
|
|
1150
|
+
|
|
1151
|
+
while chunk:
|
|
1152
|
+
item, chunk = cls._item_type.deserialize(chunk)
|
|
1153
|
+
r.append(item)
|
|
1154
|
+
|
|
1155
|
+
return r, data
|
|
1156
|
+
|
|
1157
|
+
|
|
1107
1158
|
class FixedList(list, Generic[_T], metaclass=KwargTypeMeta):
|
|
1108
1159
|
_item_type: type[_T] | None
|
|
1109
1160
|
_length: int | None
|
|
@@ -307,7 +307,8 @@ class Struct:
|
|
|
307
307
|
|
|
308
308
|
# Serialize the current segment of bitfields once we reach a boundary
|
|
309
309
|
if bit_offset % 8 == 0:
|
|
310
|
-
|
|
310
|
+
segment = t.Bits.from_bitfields(bitfields).serialize()[::-1]
|
|
311
|
+
chunks.append(segment)
|
|
311
312
|
bitfields = []
|
|
312
313
|
|
|
313
314
|
continue
|
|
@@ -358,7 +359,7 @@ class Struct:
|
|
|
358
359
|
if len(data) < bit_length // 8:
|
|
359
360
|
raise ValueError(f"Data is too short to contain {bitfields}")
|
|
360
361
|
|
|
361
|
-
bits, _ = t.Bits.deserialize(data[: bit_length // 8])
|
|
362
|
+
bits, _ = t.Bits.deserialize(data[: bit_length // 8][::-1])
|
|
362
363
|
data = data[bit_length // 8 :]
|
|
363
364
|
|
|
364
365
|
for f in bitfields:
|
|
@@ -1116,8 +1116,17 @@ class Cluster(util.ListenableMixin, util.CatchingTaskMixin, EventBase):
|
|
|
1116
1116
|
allow_cache: bool = False,
|
|
1117
1117
|
only_cache: bool = False,
|
|
1118
1118
|
manufacturer: int | UndefinedType | None = UNDEFINED,
|
|
1119
|
+
*,
|
|
1120
|
+
split_requests: bool = True,
|
|
1119
1121
|
**kwargs,
|
|
1120
1122
|
) -> Any:
|
|
1123
|
+
"""Read attributes from the device.
|
|
1124
|
+
|
|
1125
|
+
Setting ``split_requests`` to ``False`` disables fixed-size chunking, but
|
|
1126
|
+
attributes with different manufacturer codes are still read separately.
|
|
1127
|
+
Attributes omitted from a response or reported as ``INSUFFICIENT_SPACE`` are
|
|
1128
|
+
also re-read individually.
|
|
1129
|
+
"""
|
|
1121
1130
|
# Find definition objects for every attribute
|
|
1122
1131
|
attribute_defs: list[foundation.ZCLAttributeDef] = []
|
|
1123
1132
|
|
|
@@ -1179,8 +1188,16 @@ class Cluster(util.ListenableMixin, util.CatchingTaskMixin, EventBase):
|
|
|
1179
1188
|
for manufacturer_code, attribute_group in reads_by_manuf_code.items():
|
|
1180
1189
|
retry_attrs: list[foundation.ZCLAttributeDef] = []
|
|
1181
1190
|
|
|
1182
|
-
|
|
1183
|
-
|
|
1191
|
+
if split_requests:
|
|
1192
|
+
chunks = [
|
|
1193
|
+
attribute_group[i : i + MAX_READ_ATTRIBUTES_PER_REQ]
|
|
1194
|
+
for i in range(0, len(attribute_group), MAX_READ_ATTRIBUTES_PER_REQ)
|
|
1195
|
+
]
|
|
1196
|
+
else:
|
|
1197
|
+
# Read every attribute in the group with a single request
|
|
1198
|
+
chunks = [attribute_group]
|
|
1199
|
+
|
|
1200
|
+
for chunk in chunks:
|
|
1184
1201
|
result = await self.read_attributes_raw(
|
|
1185
1202
|
[attr_def.id for attr_def in chunk],
|
|
1186
1203
|
manufacturer=manufacturer_code,
|