zigpy 2.0.1__tar.gz → 2.1.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.
Files changed (126) hide show
  1. {zigpy-2.0.1/zigpy.egg-info → zigpy-2.1.0}/PKG-INFO +1 -1
  2. {zigpy-2.0.1 → zigpy-2.1.0}/pyproject.toml +7 -0
  3. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_application.py +50 -0
  4. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_zcl.py +63 -10
  5. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_zcl_clusters.py +34 -1
  6. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/application.py +35 -0
  7. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/ota/manager.py +22 -11
  8. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zcl/__init__.py +12 -4
  9. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zcl/clusters/general.py +65 -0
  10. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zcl/clusters/greenpower.py +58 -32
  11. zigpy-2.1.0/zigpy/zgp/__init__.py +21 -0
  12. zigpy-2.1.0/zigpy/zgp/crypto.py +212 -0
  13. zigpy-2.1.0/zigpy/zgp/frame.py +145 -0
  14. zigpy-2.1.0/zigpy/zgp/types.py +181 -0
  15. {zigpy-2.0.1 → zigpy-2.1.0/zigpy.egg-info}/PKG-INFO +1 -1
  16. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy.egg-info/SOURCES.txt +2 -0
  17. zigpy-2.0.1/zigpy/zgp/__init__.py +0 -1
  18. zigpy-2.0.1/zigpy/zgp/types.py +0 -59
  19. {zigpy-2.0.1 → zigpy-2.1.0}/COPYING +0 -0
  20. {zigpy-2.0.1 → zigpy-2.1.0}/LICENSE +0 -0
  21. {zigpy-2.0.1 → zigpy-2.1.0}/README.md +0 -0
  22. {zigpy-2.0.1 → zigpy-2.1.0}/setup.cfg +0 -0
  23. {zigpy-2.0.1 → zigpy-2.1.0}/setup.py +0 -0
  24. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_app_state.py +0 -0
  25. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_appdb.py +0 -0
  26. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_appdb_migration.py +0 -0
  27. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_backups.py +0 -0
  28. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_config.py +0 -0
  29. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_datastructures.py +0 -0
  30. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_datastructures_cpython.py +0 -0
  31. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_device.py +0 -0
  32. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_endpoint.py +0 -0
  33. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_event.py +0 -0
  34. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_group.py +0 -0
  35. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_listeners.py +0 -0
  36. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_packet_callbacks.py +0 -0
  37. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_serial.py +0 -0
  38. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_struct.py +0 -0
  39. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_topology.py +0 -0
  40. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_types.py +0 -0
  41. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_zcl_foundation.py +0 -0
  42. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_zcl_helpers.py +0 -0
  43. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_zdo.py +0 -0
  44. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_zdo_types.py +0 -0
  45. {zigpy-2.0.1 → zigpy-2.1.0}/tests/test_zigbee_util.py +0 -0
  46. {zigpy-2.0.1 → zigpy-2.1.0}/tools/__init__.py +0 -0
  47. {zigpy-2.0.1 → zigpy-2.1.0}/tools/regenerate_mypy_ignores.py +0 -0
  48. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/__init__.py +0 -0
  49. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/appdb.py +0 -0
  50. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/appdb_schemas/__init__.py +0 -0
  51. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/appdb_schemas/schema_v0.sql +0 -0
  52. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/appdb_schemas/schema_v1.sql +0 -0
  53. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/appdb_schemas/schema_v10.sql +0 -0
  54. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/appdb_schemas/schema_v11.sql +0 -0
  55. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/appdb_schemas/schema_v12.sql +0 -0
  56. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/appdb_schemas/schema_v13.sql +0 -0
  57. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/appdb_schemas/schema_v14.sql +0 -0
  58. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/appdb_schemas/schema_v15.sql +0 -0
  59. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/appdb_schemas/schema_v2.sql +0 -0
  60. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/appdb_schemas/schema_v3.sql +0 -0
  61. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/appdb_schemas/schema_v4.sql +0 -0
  62. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/appdb_schemas/schema_v5.sql +0 -0
  63. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/appdb_schemas/schema_v6.sql +0 -0
  64. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/appdb_schemas/schema_v7.sql +0 -0
  65. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/appdb_schemas/schema_v8.sql +0 -0
  66. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/appdb_schemas/schema_v9.sql +0 -0
  67. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/backports/__init__.py +0 -0
  68. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/backups.py +0 -0
  69. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/config/__init__.py +0 -0
  70. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/config/defaults.py +0 -0
  71. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/config/validators.py +0 -0
  72. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/const.py +0 -0
  73. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/datastructures.py +0 -0
  74. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/device.py +0 -0
  75. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/endpoint.py +0 -0
  76. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/event/__init__.py +0 -0
  77. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/event/event_base.py +0 -0
  78. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/exceptions.py +0 -0
  79. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/group.py +0 -0
  80. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/listeners.py +0 -0
  81. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/ota/__init__.py +0 -0
  82. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/ota/image.py +0 -0
  83. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/ota/json_schemas.py +0 -0
  84. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/ota/providers.py +0 -0
  85. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/ota/validators.py +0 -0
  86. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/profiles/__init__.py +0 -0
  87. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/profiles/zgp.py +0 -0
  88. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/profiles/zha.py +0 -0
  89. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/profiles/zll.py +0 -0
  90. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/py.typed +0 -0
  91. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/quirks/__init__.py +0 -0
  92. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/quirks/registry.py +0 -0
  93. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/quirks/v2/__init__.py +0 -0
  94. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/quirks/v2/homeassistant/__init__.py +0 -0
  95. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/quirks/v2/homeassistant/binary_sensor.py +0 -0
  96. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/quirks/v2/homeassistant/number.py +0 -0
  97. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/quirks/v2/homeassistant/sensor.py +0 -0
  98. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/serial.py +0 -0
  99. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/state.py +0 -0
  100. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/topology.py +0 -0
  101. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/types/__init__.py +0 -0
  102. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/types/basic.py +0 -0
  103. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/types/named.py +0 -0
  104. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/types/struct.py +0 -0
  105. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/typing.py +0 -0
  106. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/util.py +0 -0
  107. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zcl/clusters/__init__.py +0 -0
  108. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zcl/clusters/closures.py +0 -0
  109. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zcl/clusters/general_const.py +0 -0
  110. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zcl/clusters/homeautomation.py +0 -0
  111. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zcl/clusters/hvac.py +0 -0
  112. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zcl/clusters/lighting.py +0 -0
  113. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zcl/clusters/lightlink.py +0 -0
  114. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zcl/clusters/manufacturer_specific.py +0 -0
  115. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zcl/clusters/measurement.py +0 -0
  116. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zcl/clusters/protocol.py +0 -0
  117. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zcl/clusters/security.py +0 -0
  118. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zcl/clusters/smartenergy.py +0 -0
  119. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zcl/clusters/wwah.py +0 -0
  120. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zcl/foundation.py +0 -0
  121. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zcl/helpers.py +0 -0
  122. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zdo/__init__.py +0 -0
  123. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy/zdo/types.py +0 -0
  124. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy.egg-info/dependency_links.txt +0 -0
  125. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy.egg-info/requires.txt +0 -0
  126. {zigpy-2.0.1 → zigpy-2.1.0}/zigpy.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zigpy
3
- Version: 2.0.1
3
+ Version: 2.1.0
4
4
  Summary: Library implementing a Zigbee stack
5
5
  Author-email: Russell Cloran <rcloran@gmail.com>
6
6
  License: GPL-3.0
@@ -482,6 +482,13 @@ disable_error_code = [
482
482
  "attr-defined", # 35
483
483
  "misc", # 285
484
484
  ]
485
+
486
+ [[tool.mypy.overrides]]
487
+ module = "zigpy.zgp.frame"
488
+ disable_error_code = [
489
+ "assignment", # 11
490
+ "attr-defined", # 17
491
+ ]
485
492
  # Autogenerated mypy overrides: end
486
493
 
487
494
  [tool.coverage.run]
@@ -946,6 +946,31 @@ async def test_force_route_discovery(app, device, packet) -> None:
946
946
  ]
947
947
 
948
948
 
949
+ async def test_request_zigbee_direct_aps_encryption(app, device, packet) -> None:
950
+ await app.request(
951
+ device=device,
952
+ profile=0x1234,
953
+ cluster=clusters.general.ZigbeeDirectConfiguration.cluster_id,
954
+ src_ep=0x9A,
955
+ dst_ep=0xBC,
956
+ sequence=0xDE,
957
+ data=b"test data",
958
+ expect_reply=True,
959
+ use_ieee=False,
960
+ extended_timeout=False,
961
+ )
962
+
963
+ assert app.send_packet.mock_calls == [
964
+ call(
965
+ packet.replace(
966
+ cluster_id=clusters.general.ZigbeeDirectConfiguration.cluster_id,
967
+ tx_options=packet.tx_options | t.TransmitOptions.APS_Encryption,
968
+ priority=t.PacketPriority.NORMAL,
969
+ )
970
+ ),
971
+ ]
972
+
973
+
949
974
  def test_build_source_route_has_relays(app):
950
975
  device = MagicMock()
951
976
  device.relays = [0x1234, 0x5678]
@@ -2044,3 +2069,28 @@ async def test_device_resolver_new_kwarg():
2044
2069
  )
2045
2070
  assert app_default._device_resolver is None
2046
2071
  assert app_default._uninitialized_packet_handler is None
2072
+
2073
+
2074
+ async def test_coordinator_group_subscribe_unsubscribe(
2075
+ app: zigpy.application.ControllerApplication,
2076
+ ) -> None:
2077
+ """Test that the coordinator can subscribe and unsubscribe from group messages."""
2078
+ await app.startup()
2079
+
2080
+ # Subscribe to a group
2081
+ with patch.object(app, "_subscribe_to_multicast_group") as mock_subscribe:
2082
+ await app.subscribe_to_multicast_group(0x1234)
2083
+ await app.subscribe_to_multicast_group(0x1234, endpoint_id=2)
2084
+ assert mock_subscribe.mock_calls == [
2085
+ call(group_id=0x1234, endpoint_id=1),
2086
+ call(group_id=0x1234, endpoint_id=2),
2087
+ ]
2088
+
2089
+ # Unsubscribe from a group
2090
+ with patch.object(app, "_unsubscribe_from_multicast_group") as mock_unsubscribe:
2091
+ await app.unsubscribe_from_multicast_group(0x1234)
2092
+ await app.unsubscribe_from_multicast_group(0x1234, endpoint_id=2)
2093
+ assert mock_unsubscribe.mock_calls == [
2094
+ call(group_id=0x1234, endpoint_id=1),
2095
+ call(group_id=0x1234, endpoint_id=2),
2096
+ ]
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import asyncio
4
+ import logging
4
5
  from typing import Any
5
6
  from unittest import mock
6
7
  from unittest.mock import AsyncMock, MagicMock, call, patch, sentinel
@@ -2914,20 +2915,72 @@ def test_chunk_records_by_size(sizes, max_bytes, expected) -> None:
2914
2915
 
2915
2916
 
2916
2917
  @pytest.mark.parametrize(
2917
- ("sizes", "max_bytes"),
2918
+ ("sizes", "max_bytes", "expected"),
2918
2919
  [
2919
2920
  # A single record larger than the limit, on its own
2920
- ([15], 10),
2921
- # An oversized record surrounded by ones that would otherwise fit
2922
- ([3, 15, 4], 10),
2921
+ ([15], 10, [[15]]),
2922
+ # An oversized record does not take the records around it down with it
2923
+ ([3, 15, 4], 10, [[3], [15], [4]]),
2924
+ # Records before an oversized one still pack together
2925
+ ([3, 3, 15, 4], 10, [[3, 3], [15], [4]]),
2926
+ # Consecutive oversized records each get a chunk of their own
2927
+ ([15, 15], 10, [[15], [15]]),
2923
2928
  ],
2924
2929
  )
2925
- def test_chunk_records_by_size_oversized_record(sizes, max_bytes) -> None:
2926
- """A record that on its own exceeds max_bytes can never be sent, so the chunker
2927
- fails loudly instead of emitting an oversized chunk the transport would reject.
2928
- """
2929
- with pytest.raises(ValueError, match="too large to fit in a single request"):
2930
- _chunk_records_by_size(sizes, lambda size: size, max_bytes=max_bytes)
2930
+ def test_chunk_records_by_size_oversized_record(
2931
+ sizes, max_bytes, expected, caplog
2932
+ ) -> None:
2933
+ """A record that on its own exceeds max_bytes is emitted as its own chunk."""
2934
+ with caplog.at_level(logging.DEBUG, logger="zigpy.zcl"):
2935
+ chunks = _chunk_records_by_size(sizes, lambda size: size, max_bytes=max_bytes)
2936
+
2937
+ assert chunks == expected
2938
+ assert caplog.text.count("exceeds the 10 byte request budget") == sum(
2939
+ size > max_bytes for size in sizes
2940
+ )
2941
+
2942
+
2943
+ async def test_write_attributes_oversized_record(app_mock) -> None:
2944
+ """An attribute record over the size budget is still sent, on its own."""
2945
+
2946
+ class TestCluster(Basic):
2947
+ _skip_registry = True
2948
+
2949
+ class AttributeDefs(Basic.AttributeDefs):
2950
+ attr_small = foundation.ZCLAttributeDef(id=0xFF00, type=t.uint8_t)
2951
+ attr_big = foundation.ZCLAttributeDef(id=0xFF01, type=t.LVBytes)
2952
+
2953
+ dev = add_initialized_device(app_mock, nwk=0x1234, ieee=make_ieee(1))
2954
+ cluster = TestCluster(dev.endpoints[1])
2955
+ dev.endpoints[1].add_input_cluster(TestCluster.cluster_id, cluster)
2956
+
2957
+ # 2 bytes of attribute id + 1 type + 1 length prefix + 55 bytes of value
2958
+ oversized = b"\xaa" * 55
2959
+
2960
+ with mock_attribute_writes(
2961
+ cluster,
2962
+ {
2963
+ TestCluster.AttributeDefs.attr_small: foundation.Status.SUCCESS,
2964
+ TestCluster.AttributeDefs.attr_big: foundation.Status.SUCCESS,
2965
+ },
2966
+ ) as (mock_write, _):
2967
+ [results] = await cluster.write_attributes(
2968
+ {
2969
+ TestCluster.AttributeDefs.attr_small: 1,
2970
+ TestCluster.AttributeDefs.attr_big: oversized,
2971
+ }
2972
+ )
2973
+
2974
+ # The small record is sent normally, the oversized one in a request of its own
2975
+ assert mock_write.call_count == 2
2976
+ chunks = [call_obj.args[0] for call_obj in mock_write.call_args_list]
2977
+ assert [[a.attrid for a in chunk] for chunk in chunks] == [[0xFF00], [0xFF01]]
2978
+
2979
+ [big_record] = chunks[1]
2980
+ assert len(big_record.serialize()) == 59 > MAX_ATTRIBUTE_RECORDS_BYTES
2981
+
2982
+ assert len(results) == 2
2983
+ assert all(r.status == foundation.Status.SUCCESS for r in results)
2931
2984
 
2932
2985
 
2933
2986
  def test_manufacturer_id_override_manuf_specific_cluster(app_mock) -> None:
@@ -12,7 +12,7 @@ from zigpy import device, types, zcl
12
12
  import zigpy.endpoint
13
13
  from zigpy.ota import OTA, OtaImagesResult
14
14
  from zigpy.zcl import OtaImageAvailableEvent, OtaQueryCacheUpdatedEvent, foundation
15
- from zigpy.zcl.clusters.general import Basic, Ota, Time
15
+ from zigpy.zcl.clusters.general import Basic, KeepAlive, Ota, Time
16
16
  import zigpy.zcl.clusters.security as sec
17
17
  from zigpy.zdo import types as zdo_t
18
18
 
@@ -137,6 +137,39 @@ async def test_basic_cluster():
137
137
  )
138
138
 
139
139
 
140
+ async def test_keepalive_cluster() -> None:
141
+ ep = MagicMock()
142
+ ep.reply = AsyncMock()
143
+
144
+ cluster = KeepAlive(ep)
145
+
146
+ rsp = await read_attributes(
147
+ cluster,
148
+ [
149
+ KeepAlive.AttributeDefs.tc_keep_alive_base.id,
150
+ KeepAlive.AttributeDefs.tc_keep_alive_jitter.id,
151
+ ],
152
+ )
153
+
154
+ assert rsp.status_records[0] == foundation.ReadAttributeRecord(
155
+ attrid=KeepAlive.AttributeDefs.tc_keep_alive_base.id,
156
+ status=foundation.Status.SUCCESS,
157
+ value=foundation.TypeValue(
158
+ type=foundation.DataTypeId.uint8,
159
+ value=10,
160
+ ),
161
+ )
162
+
163
+ assert rsp.status_records[1] == foundation.ReadAttributeRecord(
164
+ attrid=KeepAlive.AttributeDefs.tc_keep_alive_jitter.id,
165
+ status=foundation.Status.SUCCESS,
166
+ value=foundation.TypeValue(
167
+ type=foundation.DataTypeId.uint16,
168
+ value=300,
169
+ ),
170
+ )
171
+
172
+
140
173
  def _make_patched_datetime(fake_now):
141
174
  """Create a PatchedDatetime class that returns `fake_now` as the current time."""
142
175
 
@@ -995,6 +995,7 @@ class ControllerApplication(zigpy.util.ListenableMixin, abc.ABC):
995
995
  zigpy.zcl.clusters.general.OnOff.cluster_id,
996
996
  zigpy.zcl.clusters.general.Time.cluster_id,
997
997
  zigpy.zcl.clusters.general.Ota.cluster_id,
998
+ zigpy.zcl.clusters.general.KeepAlive.cluster_id,
998
999
  zigpy.zcl.clusters.security.IasAce.cluster_id,
999
1000
  ],
1000
1001
  output_clusters=[
@@ -1133,6 +1134,12 @@ class ControllerApplication(zigpy.util.ListenableMixin, abc.ABC):
1133
1134
  if force_route_discovery:
1134
1135
  tx_options |= t.TransmitOptions.FORCE_ROUTE_DISCOVERY
1135
1136
 
1137
+ if cluster == zigpy.zcl.clusters.general.ZigbeeDirectConfiguration.cluster_id:
1138
+ # All interactions with the Zigbee Direct Configuration cluster require
1139
+ # APS encryption (with the Trust Center link key, in a centralized
1140
+ # security network)
1141
+ tx_options |= t.TransmitOptions.APS_Encryption
1142
+
1136
1143
  await self.send_packet(
1137
1144
  t.ZigbeePacket(
1138
1145
  src=src,
@@ -1667,6 +1674,34 @@ class ControllerApplication(zigpy.util.ListenableMixin, abc.ABC):
1667
1674
  async def _packet_capture_change_channel(self, channel: int) -> None:
1668
1675
  """Change the channel of an active packet capture, internal."""
1669
1676
 
1677
+ async def subscribe_to_multicast_group(
1678
+ self, group_id: t.Group, endpoint_id: int = 1
1679
+ ) -> None:
1680
+ """Ask the coordinator firmware to subscribe to a group, if needed."""
1681
+ await self._subscribe_to_multicast_group(
1682
+ group_id=group_id, endpoint_id=endpoint_id
1683
+ )
1684
+
1685
+ # @abc.abstractmethod
1686
+ async def _subscribe_to_multicast_group(
1687
+ self, group_id: t.Group, endpoint_id: int
1688
+ ) -> None:
1689
+ """Ask the coordinator firmware to subscribe to a group, if needed."""
1690
+
1691
+ async def unsubscribe_from_multicast_group(
1692
+ self, group_id: t.Group, endpoint_id: int = 1
1693
+ ) -> None:
1694
+ """Ask the coordinator firmware to unsubscribe from a group, if needed."""
1695
+ await self._unsubscribe_from_multicast_group(
1696
+ group_id=group_id, endpoint_id=endpoint_id
1697
+ )
1698
+
1699
+ # @abc.abstractmethod
1700
+ async def _unsubscribe_from_multicast_group(
1701
+ self, group_id: t.Group, endpoint_id: int
1702
+ ) -> None:
1703
+ """Ask the coordinator firmware to unsubscribe from a group, if needed."""
1704
+
1670
1705
  async def permit(self, time_s: int = 60, node: t.EUI64 | str | None = None) -> None:
1671
1706
  """Permit joining on a specific node or all router nodes."""
1672
1707
  assert 0 <= time_s <= 254
@@ -26,8 +26,12 @@ if TYPE_CHECKING:
26
26
  from zigpy.ota.providers import OtaImageWithMetadata
27
27
 
28
28
 
29
+ # Maximum time between two block requests, to detect when OTA has permanently stalled
29
30
  MAX_TIME_WITHOUT_PROGRESS = 30
30
31
 
32
+ # Separate timeout for the final block, to give devices time to finally verify the OTA
33
+ FINAL_BLOCK_TIMEOUT = 60
34
+
31
35
 
32
36
  def _image_block_size_for_manufacturer(
33
37
  manufacturer_code: int, requested_size: int
@@ -190,17 +194,21 @@ class OTAManager:
190
194
  return
191
195
 
192
196
  try:
193
- await self.ota_cluster.image_block_response(
194
- status=foundation.Status.SUCCESS,
195
- manufacturer_code=self.image.firmware.header.manufacturer_id,
196
- image_type=self.image.firmware.header.image_type,
197
- file_version=self.image.firmware.header.file_version,
198
- file_offset=command.file_offset,
199
- image_data=block,
200
- tsn=hdr.tsn,
201
- )
197
+ async with self.device.application.request_priority(t.PacketPriority.LOW):
198
+ await self.ota_cluster.image_block_response(
199
+ status=foundation.Status.SUCCESS,
200
+ manufacturer_code=self.image.firmware.header.manufacturer_id,
201
+ image_type=self.image.firmware.header.image_type,
202
+ file_version=self.image.firmware.header.file_version,
203
+ file_offset=command.file_offset,
204
+ image_data=block,
205
+ tsn=hdr.tsn,
206
+ )
202
207
 
203
- self._stall_timer.reschedule(MAX_TIME_WITHOUT_PROGRESS)
208
+ if command.file_offset + len(block) < len(self._image_data):
209
+ self._stall_timer.reschedule(MAX_TIME_WITHOUT_PROGRESS)
210
+ else:
211
+ self._stall_timer.reschedule(FINAL_BLOCK_TIMEOUT)
204
212
 
205
213
  # Image block requests can sometimes succeed after the device aborts the
206
214
  # update. We should not allow the progress callback to be called.
@@ -261,7 +269,10 @@ class OTAManager:
261
269
  image_data=block,
262
270
  )
263
271
 
264
- self._stall_timer.reschedule(MAX_TIME_WITHOUT_PROGRESS)
272
+ if offset < len(self._image_data):
273
+ self._stall_timer.reschedule(MAX_TIME_WITHOUT_PROGRESS)
274
+ else:
275
+ self._stall_timer.reschedule(FINAL_BLOCK_TIMEOUT)
265
276
 
266
277
  if (
267
278
  self.progress_callback is not None
@@ -53,7 +53,7 @@ def _chunk_records_by_size(
53
53
  *,
54
54
  max_bytes: int = MAX_ATTRIBUTE_RECORDS_BYTES,
55
55
  ) -> list[list[_RecordT]]:
56
- """Split records into chunks not exceeding max_bytes of serialized payload."""
56
+ """Split records into chunks of at most max_bytes, except oversized records."""
57
57
  chunks: list[list[_RecordT]] = []
58
58
  chunk_size = 0
59
59
 
@@ -61,10 +61,18 @@ def _chunk_records_by_size(
61
61
  record_size = get_size(record)
62
62
 
63
63
  if record_size > max_bytes:
64
- raise ValueError(
65
- f"Record {record!r} is too large to fit in a single request: "
66
- f"{record_size} > {max_bytes} bytes"
64
+ # Chunking can't shrink a single record, so send it alone and let the
65
+ # device reject it. `max_bytes + 1` keeps the next record out of this
66
+ # chunk, whatever its size.
67
+ LOGGER.debug(
68
+ "Record exceeds the %d byte request budget (%d bytes), sending it"
69
+ " on its own",
70
+ max_bytes,
71
+ record_size,
67
72
  )
73
+ chunks.append([record])
74
+ chunk_size = max_bytes + 1
75
+ continue
68
76
 
69
77
  if not chunks or chunk_size + record_size > max_bytes:
70
78
  chunks.append([])
@@ -2443,3 +2443,68 @@ class KeepAlive(Cluster):
2443
2443
  tc_keep_alive_jitter: Final = ZCLAttributeDef(
2444
2444
  id=0x0001, type=t.uint16_t, access="r", mandatory=True
2445
2445
  )
2446
+
2447
+ def handle_read_attribute_tc_keep_alive_base(self) -> t.uint8_t:
2448
+ # Spec default (0x0A). Represents the time base (in minutes) that a Zigbee 4.0
2449
+ # device will use to check if the trust center is alive.
2450
+ return t.uint8_t(10)
2451
+
2452
+ def handle_read_attribute_tc_keep_alive_jitter(self) -> t.uint16_t:
2453
+ # Spec default (0x012C). Represents the jitter (in _seconds_) that a Zigbee 4.0
2454
+ # device will add to the time base when checking if the trust center is alive.
2455
+ return t.uint16_t(300)
2456
+
2457
+
2458
+ class ZigbeeDirectInterfaceState(t.bitmap8):
2459
+ """Zigbee Direct interface state bitmap."""
2460
+
2461
+ Enabled = 0b00000001
2462
+
2463
+
2464
+ class ZigbeeDirectConfiguration(Cluster):
2465
+ """Zigbee Direct Configuration cluster definition.
2466
+
2467
+ Configures Zigbee Direct on a Zigbee Direct Device (ZDD). Commands are
2468
+ only accepted via unicast and, in a centralized security network, all
2469
+ interactions with this cluster require APS encryption with the Trust
2470
+ Center link key.
2471
+ """
2472
+
2473
+ InterfaceState: Final = ZigbeeDirectInterfaceState
2474
+
2475
+ cluster_id: Final[t.uint16_t] = 0x003D
2476
+ ep_attribute: Final = "zigbee_direct_configuration"
2477
+
2478
+ class AttributeDefs(BaseAttributeDefs):
2479
+ """Zigbee Direct Configuration cluster attributes."""
2480
+
2481
+ interface_state: Final = ZCLAttributeDef(
2482
+ id=0x0000, type=ZigbeeDirectInterfaceState, access="r", mandatory=True
2483
+ )
2484
+ # Timeout in seconds (0x000000-0x100000, or 0xFFFFFF for no timeout)
2485
+ # during which a ZVD can establish a provisioning session using the
2486
+ # Anonymous Well-Known Secret while the network is open
2487
+ anonymous_join_timeout: Final = ZCLAttributeDef(
2488
+ id=0x0001, type=t.uint24_t, access="r", mandatory=True
2489
+ )
2490
+
2491
+ class ServerCommandDefs(BaseCommandDefs):
2492
+ """Zigbee Direct Configuration cluster server commands."""
2493
+
2494
+ configure_interface: Final = ZCLCommandDef(
2495
+ id=0x00, schema={"interface_state": ZigbeeDirectInterfaceState}
2496
+ )
2497
+ configure_anonymous_join_timeout: Final = ZCLCommandDef(
2498
+ id=0x01, schema={"anonymous_join_timeout": t.uint24_t}
2499
+ )
2500
+
2501
+ class ClientCommandDefs(BaseCommandDefs):
2502
+ """Zigbee Direct Configuration cluster client commands."""
2503
+
2504
+ configure_interface_rsp: Final = ZCLCommandDef(
2505
+ id=0x00,
2506
+ schema={
2507
+ "status": foundation.Status,
2508
+ "interface_state": ZigbeeDirectInterfaceState,
2509
+ },
2510
+ )
@@ -16,6 +16,7 @@ from zigpy.zcl.foundation import (
16
16
  import zigpy.zgp.types as zgptypes
17
17
 
18
18
 
19
+ # Figure 31 — 16 bits total
19
20
  class CommissioningNotificationOptions(t.Struct):
20
21
  application_id: zgptypes.ApplicationID
21
22
  rx_after_tx: t.uint1_t
@@ -24,10 +25,10 @@ class CommissioningNotificationOptions(t.Struct):
24
25
  security_failed: t.uint1_t
25
26
  bidirectional_cap: t.uint1_t
26
27
  proxy_info_present: t.uint1_t
27
- _reserved: t.uint6_t
28
+ _reserved: t.uint4_t
28
29
 
29
30
 
30
- # Figure 27
31
+ # Figure 30
31
32
  class CommissioningNotificationSchema(foundation.CommandSchema):
32
33
  options: CommissioningNotificationOptions
33
34
  gpd_id: zgptypes.DeviceID
@@ -35,24 +36,34 @@ class CommissioningNotificationSchema(foundation.CommandSchema):
35
36
  command_id: t.uint8_t
36
37
  payload: t.LVBytes
37
38
  gpp_short_addr: t.uint16_t = StructField(
38
- requires=lambda s: s.proxy_info_present, optional=True
39
+ requires=lambda s: s.options.proxy_info_present, optional=True
40
+ )
41
+ gpp_gpd_link: t.uint8_t = StructField(
42
+ requires=lambda s: s.options.proxy_info_present, optional=True
39
43
  )
40
- distance: t.uint8_t = StructField(
41
- requires=lambda s: s.proxy_info_present, optional=True
44
+ mic: t.uint32_t = StructField(
45
+ requires=lambda s: s.options.security_failed, optional=True
42
46
  )
43
- mic: t.uint32_t = StructField(requires=lambda s: s.security_failed, optional=True)
44
47
 
45
48
 
49
+ # Figure 59
46
50
  class ResponseOptions(t.Struct):
47
51
  application_id: zgptypes.ApplicationID
48
- _reserved: t.uint5_t
52
+ transmit_on_endpoint_match: t.uint1_t
53
+ _reserved: t.uint4_t
54
+
49
55
 
56
+ # Figure 60 — TempMaster TX channel sub-field of the GP Response command
57
+ class TempMasterTxChannel(t.Struct):
58
+ transmit_channel: t.uint4_t # IEEE 802.15.4 channel == transmit_channel + 11
59
+ _reserved: t.uint4_t
50
60
 
51
- # Figure 45
61
+
62
+ # Figure 58
52
63
  class ResponseSchema(foundation.CommandSchema):
53
64
  options: ResponseOptions
54
65
  temp_master_short_addr: t.uint16_t
55
- temp_master_tx_channel: t.uint8_t
66
+ temp_master_tx_channel: TempMasterTxChannel
56
67
  gpd_id: zgptypes.DeviceID
57
68
  gpd_command_id: t.uint8_t
58
69
  gpd_command_payload: t.LVBytes
@@ -114,7 +125,7 @@ class PairingOptions(t.Struct):
114
125
  security_frame_counter_present: t.uint1_t
115
126
  security_key_present: t.uint1_t
116
127
  assigned_alias_present: t.uint1_t
117
- forwarding_radius_present: t.uint1_t
128
+ groupcast_radius_present: t.uint1_t
118
129
  _reserved: t.uint6_t
119
130
 
120
131
 
@@ -124,34 +135,41 @@ class PairingSchema(foundation.CommandSchema):
124
135
  gpd_id: zgptypes.DeviceID
125
136
  # Table 37
126
137
  sink_ieee: t.EUI64 = StructField(
127
- requires=lambda s: not s.options.remove_gpd
128
- and s.options.communication_mode
129
- in (
130
- zgptypes.CommunicationMode.Unicast,
131
- zgptypes.CommunicationMode.UnicastLightweight,
138
+ requires=lambda s: (
139
+ not s.options.remove_gpd
140
+ and s.options.communication_mode
141
+ in (
142
+ zgptypes.CommunicationMode.Unicast,
143
+ zgptypes.CommunicationMode.UnicastLightweight,
144
+ )
132
145
  )
133
146
  )
134
147
  sink_nwk_addr: t.NWK = StructField(
135
- requires=lambda s: not s.options.remove_gpd
136
- and s.options.communication_mode
137
- in (
138
- zgptypes.CommunicationMode.Unicast,
139
- zgptypes.CommunicationMode.UnicastLightweight,
148
+ requires=lambda s: (
149
+ not s.options.remove_gpd
150
+ and s.options.communication_mode
151
+ in (
152
+ zgptypes.CommunicationMode.Unicast,
153
+ zgptypes.CommunicationMode.UnicastLightweight,
154
+ )
140
155
  )
141
156
  )
142
157
  sink_group: t.Group = StructField(
143
- requires=lambda s: not s.options.remove_gpd
144
- and s.options.communication_mode
145
- in (
146
- zgptypes.CommunicationMode.GroupcastForwardToDGroup,
147
- zgptypes.CommunicationMode.GroupcastForwardToCommGroup,
158
+ requires=lambda s: (
159
+ not s.options.remove_gpd
160
+ and s.options.communication_mode
161
+ in (
162
+ zgptypes.CommunicationMode.GroupcastForwardToDGroup,
163
+ zgptypes.CommunicationMode.GroupcastForwardToCommGroup,
164
+ )
148
165
  )
149
166
  )
150
167
 
151
168
  device_id: t.uint8_t = StructField(requires=lambda s: s.options.add_sink)
152
169
  frame_counter: t.uint32_t = StructField(
153
- requires=lambda s: s.options.add_sink
154
- and s.options.security_frame_counter_present
170
+ requires=lambda s: (
171
+ s.options.add_sink and s.options.security_frame_counter_present
172
+ )
155
173
  )
156
174
  key: t.KeyData = StructField(
157
175
  requires=lambda s: s.options.add_sink and s.options.security_key_present
@@ -159,8 +177,8 @@ class PairingSchema(foundation.CommandSchema):
159
177
  alias: t.uint16_t = StructField(
160
178
  requires=lambda s: s.options.add_sink and s.options.assigned_alias_present
161
179
  )
162
- forwarding_radius: t.uint8_t = StructField(
163
- requires=lambda s: s.options.add_sink and s.options.forwarding_radius_present
180
+ groupcast_radius: t.uint8_t = StructField(
181
+ requires=lambda s: s.options.add_sink and s.options.groupcast_radius_present
164
182
  )
165
183
 
166
184
 
@@ -178,18 +196,26 @@ class NotificationResponseSchema(foundation.CommandSchema):
178
196
  frame_counter: t.uint32_t
179
197
 
180
198
 
181
- # Figure 43
199
+ # Figure 56
182
200
  class ProxyCommissioningModeOptions(t.Struct):
183
201
  enter: t.uint1_t
184
- exit_mode: zgptypes.ProxyCommissioningModeExitMode
202
+ commissioning_window_present: t.uint1_t
203
+ # Exit-mode sub-field (Figure 57): bit 0 = on first pairing, bit 1 = on
204
+ # explicit exit. Only 2 bits here, unlike the 3-bit gpsCommissioningExitMode
205
+ # attribute (Figure 22).
206
+ exit_mode: t.uint2_t
185
207
  channel_present: t.uint1_t
186
208
  unicast: t.uint1_t
187
209
  _reserved: t.uint2_t
188
210
 
189
211
 
212
+ # Figure 55
190
213
  class ProxyCommissioningModeSchema(foundation.CommandSchema):
191
214
  options: ProxyCommissioningModeOptions
192
- window: t.uint16_t = StructField(optional=True)
215
+ window: t.uint16_t = StructField(
216
+ requires=lambda s: s.options.commissioning_window_present
217
+ )
218
+ channel: t.uint8_t = StructField(requires=lambda s: s.options.channel_present)
193
219
 
194
220
 
195
221
  class GreenPowerProxy(Cluster):
@@ -0,0 +1,21 @@
1
+ from .crypto import ( # noqa: F401
2
+ build_nonce,
3
+ decrypt_payload,
4
+ decrypt_security_key,
5
+ encrypt_payload,
6
+ encrypt_security_key,
7
+ )
8
+ from .frame import ( # noqa: F401
9
+ GPChannelRequestPayload,
10
+ GPCommissioningAppInfo,
11
+ GPCommissioningExtendedOptions,
12
+ GPCommissioningOptions,
13
+ GPCommissioningPayload,
14
+ )
15
+ from .types import * # noqa: F403, F401
16
+ from .types import ( # noqa: F401
17
+ DEFAULT_GP_LINK_KEY,
18
+ GP_CLUSTER_ID,
19
+ GP_ENDPOINT,
20
+ GP_GROUP_ID,
21
+ )