zigpy 2.0.0__tar.gz → 2.0.1__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 (122) hide show
  1. {zigpy-2.0.0/zigpy.egg-info → zigpy-2.0.1}/PKG-INFO +1 -1
  2. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_datastructures.py +64 -0
  3. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_zcl.py +205 -0
  4. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/datastructures.py +8 -3
  5. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zcl/__init__.py +147 -72
  6. {zigpy-2.0.0 → zigpy-2.0.1/zigpy.egg-info}/PKG-INFO +1 -1
  7. {zigpy-2.0.0 → zigpy-2.0.1}/COPYING +0 -0
  8. {zigpy-2.0.0 → zigpy-2.0.1}/LICENSE +0 -0
  9. {zigpy-2.0.0 → zigpy-2.0.1}/README.md +0 -0
  10. {zigpy-2.0.0 → zigpy-2.0.1}/pyproject.toml +0 -0
  11. {zigpy-2.0.0 → zigpy-2.0.1}/setup.cfg +0 -0
  12. {zigpy-2.0.0 → zigpy-2.0.1}/setup.py +0 -0
  13. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_app_state.py +0 -0
  14. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_appdb.py +0 -0
  15. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_appdb_migration.py +0 -0
  16. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_application.py +0 -0
  17. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_backups.py +0 -0
  18. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_config.py +0 -0
  19. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_datastructures_cpython.py +0 -0
  20. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_device.py +0 -0
  21. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_endpoint.py +0 -0
  22. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_event.py +0 -0
  23. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_group.py +0 -0
  24. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_listeners.py +0 -0
  25. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_packet_callbacks.py +0 -0
  26. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_serial.py +0 -0
  27. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_struct.py +0 -0
  28. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_topology.py +0 -0
  29. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_types.py +0 -0
  30. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_zcl_clusters.py +0 -0
  31. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_zcl_foundation.py +0 -0
  32. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_zcl_helpers.py +0 -0
  33. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_zdo.py +0 -0
  34. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_zdo_types.py +0 -0
  35. {zigpy-2.0.0 → zigpy-2.0.1}/tests/test_zigbee_util.py +0 -0
  36. {zigpy-2.0.0 → zigpy-2.0.1}/tools/__init__.py +0 -0
  37. {zigpy-2.0.0 → zigpy-2.0.1}/tools/regenerate_mypy_ignores.py +0 -0
  38. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/__init__.py +0 -0
  39. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/appdb.py +0 -0
  40. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/appdb_schemas/__init__.py +0 -0
  41. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/appdb_schemas/schema_v0.sql +0 -0
  42. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/appdb_schemas/schema_v1.sql +0 -0
  43. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/appdb_schemas/schema_v10.sql +0 -0
  44. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/appdb_schemas/schema_v11.sql +0 -0
  45. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/appdb_schemas/schema_v12.sql +0 -0
  46. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/appdb_schemas/schema_v13.sql +0 -0
  47. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/appdb_schemas/schema_v14.sql +0 -0
  48. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/appdb_schemas/schema_v15.sql +0 -0
  49. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/appdb_schemas/schema_v2.sql +0 -0
  50. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/appdb_schemas/schema_v3.sql +0 -0
  51. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/appdb_schemas/schema_v4.sql +0 -0
  52. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/appdb_schemas/schema_v5.sql +0 -0
  53. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/appdb_schemas/schema_v6.sql +0 -0
  54. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/appdb_schemas/schema_v7.sql +0 -0
  55. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/appdb_schemas/schema_v8.sql +0 -0
  56. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/appdb_schemas/schema_v9.sql +0 -0
  57. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/application.py +0 -0
  58. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/backports/__init__.py +0 -0
  59. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/backups.py +0 -0
  60. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/config/__init__.py +0 -0
  61. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/config/defaults.py +0 -0
  62. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/config/validators.py +0 -0
  63. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/const.py +0 -0
  64. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/device.py +0 -0
  65. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/endpoint.py +0 -0
  66. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/event/__init__.py +0 -0
  67. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/event/event_base.py +0 -0
  68. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/exceptions.py +0 -0
  69. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/group.py +0 -0
  70. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/listeners.py +0 -0
  71. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/ota/__init__.py +0 -0
  72. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/ota/image.py +0 -0
  73. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/ota/json_schemas.py +0 -0
  74. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/ota/manager.py +0 -0
  75. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/ota/providers.py +0 -0
  76. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/ota/validators.py +0 -0
  77. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/profiles/__init__.py +0 -0
  78. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/profiles/zgp.py +0 -0
  79. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/profiles/zha.py +0 -0
  80. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/profiles/zll.py +0 -0
  81. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/py.typed +0 -0
  82. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/quirks/__init__.py +0 -0
  83. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/quirks/registry.py +0 -0
  84. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/quirks/v2/__init__.py +0 -0
  85. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/quirks/v2/homeassistant/__init__.py +0 -0
  86. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/quirks/v2/homeassistant/binary_sensor.py +0 -0
  87. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/quirks/v2/homeassistant/number.py +0 -0
  88. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/quirks/v2/homeassistant/sensor.py +0 -0
  89. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/serial.py +0 -0
  90. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/state.py +0 -0
  91. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/topology.py +0 -0
  92. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/types/__init__.py +0 -0
  93. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/types/basic.py +0 -0
  94. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/types/named.py +0 -0
  95. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/types/struct.py +0 -0
  96. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/typing.py +0 -0
  97. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/util.py +0 -0
  98. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zcl/clusters/__init__.py +0 -0
  99. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zcl/clusters/closures.py +0 -0
  100. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zcl/clusters/general.py +0 -0
  101. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zcl/clusters/general_const.py +0 -0
  102. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zcl/clusters/greenpower.py +0 -0
  103. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zcl/clusters/homeautomation.py +0 -0
  104. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zcl/clusters/hvac.py +0 -0
  105. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zcl/clusters/lighting.py +0 -0
  106. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zcl/clusters/lightlink.py +0 -0
  107. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zcl/clusters/manufacturer_specific.py +0 -0
  108. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zcl/clusters/measurement.py +0 -0
  109. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zcl/clusters/protocol.py +0 -0
  110. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zcl/clusters/security.py +0 -0
  111. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zcl/clusters/smartenergy.py +0 -0
  112. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zcl/clusters/wwah.py +0 -0
  113. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zcl/foundation.py +0 -0
  114. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zcl/helpers.py +0 -0
  115. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zdo/__init__.py +0 -0
  116. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zdo/types.py +0 -0
  117. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zgp/__init__.py +0 -0
  118. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy/zgp/types.py +0 -0
  119. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy.egg-info/SOURCES.txt +0 -0
  120. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy.egg-info/dependency_links.txt +0 -0
  121. {zigpy-2.0.0 → zigpy-2.0.1}/zigpy.egg-info/requires.txt +0 -0
  122. {zigpy-2.0.0 → zigpy-2.0.1}/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.0
3
+ Version: 2.0.1
4
4
  Summary: Library implementing a Zigbee stack
5
5
  Author-email: Russell Cloran <rcloran@gmail.com>
6
6
  License: GPL-3.0
@@ -274,6 +274,38 @@ async def test_dynamic_bounded_semaphore_cancellation():
274
274
  assert not sem.locked()
275
275
 
276
276
 
277
+ async def test_dynamic_bounded_semaphore_cancel_waiting_then_task_cancelled() -> None:
278
+ """Test that a cancelled waiter does not corrupt the active-request bookkeeping."""
279
+ sem = datastructures.PriorityDynamicBoundedSemaphore(1)
280
+
281
+ async def acquire():
282
+ async with sem:
283
+ await asyncio.sleep(60)
284
+
285
+ # Hold the only slot so the next acquire must wait
286
+ async with sem:
287
+ assert sem.value == 0
288
+
289
+ task = asyncio.create_task(acquire())
290
+ await asyncio.sleep(0) # Let the task start waiting
291
+ assert len(sem._waiters) == 1
292
+
293
+ # `cancel_waiting` resolves the future with an exception and the task is
294
+ # then cancelled: cancellation wins, so the acquire raises `CancelledError`
295
+ # even though no slot was ever granted.
296
+ sem.cancel_waiting(RuntimeError("rejoin"))
297
+ task.cancel()
298
+
299
+ with pytest.raises(asyncio.CancelledError):
300
+ await task
301
+
302
+ # The waiter never acquired a slot, so the active count is unchanged
303
+ assert sem.value == 0
304
+
305
+ # Releasing the outer slot must not trip the bookkeeping assertion
306
+ assert sem.value == 1
307
+
308
+
277
309
  async def test_priority_lock():
278
310
  """Test priority lock."""
279
311
 
@@ -709,6 +741,38 @@ async def test_request_limiter_cancel_waiting():
709
741
  await task2
710
742
 
711
743
 
744
+ async def test_request_limiter_cancel_waiting_then_task_cancelled() -> None:
745
+ """Test that a cancelled waiter does not corrupt the active-request bookkeeping."""
746
+ limiter = datastructures.RequestLimiter(1, {1: 1.0})
747
+
748
+ async def acquire():
749
+ async with limiter(priority=1):
750
+ await asyncio.sleep(60)
751
+
752
+ # Hold the only slot so the next acquire must wait
753
+ async with limiter(priority=1):
754
+ assert limiter.active_requests == 1
755
+
756
+ task = asyncio.create_task(acquire())
757
+ await asyncio.sleep(0) # Let the task start waiting
758
+ assert limiter.waiting_requests == 1
759
+
760
+ # `cancel_waiting` resolves the future with an exception and the task is
761
+ # then cancelled: cancellation wins, so the acquire raises `CancelledError`
762
+ # even though no slot was ever granted.
763
+ limiter.cancel_waiting(RuntimeError("rejoin"))
764
+ task.cancel()
765
+
766
+ with pytest.raises(asyncio.CancelledError):
767
+ await task
768
+
769
+ # The waiter never acquired a slot, so the active count is unchanged
770
+ assert limiter.active_requests == 1
771
+
772
+ # Releasing the outer slot must not trip the bookkeeping assertion
773
+ assert limiter.active_requests == 0
774
+
775
+
712
776
  async def test_request_limiter_backwards_compatibility() -> None:
713
777
  """Test `max_value` property proxying `max_concurrency`."""
714
778
  limiter = datastructures.RequestLimiter(5, {1: 1.0})
@@ -2639,6 +2639,211 @@ async def test_read_attributes_chunked_by_count(app_mock) -> None:
2639
2639
  }
2640
2640
 
2641
2641
 
2642
+ async def test_read_attributes_insufficient_space_retry_success(app_mock) -> None:
2643
+ """An INSUFFICIENT_SPACE record is re-read individually and can then succeed."""
2644
+
2645
+ class TestCluster(Basic):
2646
+ _skip_registry = True
2647
+
2648
+ class AttributeDefs(Basic.AttributeDefs):
2649
+ attr_0 = foundation.ZCLAttributeDef(id=0xFF00, type=t.uint8_t)
2650
+ attr_1 = foundation.ZCLAttributeDef(id=0xFF01, type=t.uint8_t)
2651
+ attr_2 = foundation.ZCLAttributeDef(id=0xFF02, type=t.uint8_t)
2652
+
2653
+ dev = add_initialized_device(app_mock, nwk=0x1234, ieee=make_ieee(1))
2654
+ cluster = TestCluster(dev.endpoints[1])
2655
+ dev.endpoints[1].add_input_cluster(TestCluster.cluster_id, cluster)
2656
+
2657
+ attrs = [
2658
+ TestCluster.AttributeDefs.attr_0,
2659
+ TestCluster.AttributeDefs.attr_1,
2660
+ TestCluster.AttributeDefs.attr_2,
2661
+ ]
2662
+
2663
+ supported = {
2664
+ TestCluster.AttributeDefs.attr_0: 10,
2665
+ # Runs out of space in the batched read, but fits when read alone
2666
+ TestCluster.AttributeDefs.attr_1: mock.Mock(
2667
+ side_effect=[foundation.Status.INSUFFICIENT_SPACE, 20]
2668
+ ),
2669
+ TestCluster.AttributeDefs.attr_2: 30,
2670
+ }
2671
+
2672
+ events = []
2673
+ cluster.on_event(AttributeReadEvent.event_type, events.append)
2674
+ cluster.on_event(AttributeUpdatedEvent.event_type, events.append)
2675
+
2676
+ with mock_attribute_reads(cluster, supported) as (mock_read, _):
2677
+ success, failure = await cluster.read_attributes(attrs)
2678
+
2679
+ assert success == {
2680
+ TestCluster.AttributeDefs.attr_0: 10,
2681
+ TestCluster.AttributeDefs.attr_1: 20,
2682
+ TestCluster.AttributeDefs.attr_2: 30,
2683
+ }
2684
+ assert failure == {}
2685
+
2686
+ # The batched read, then a solo re-read of the attribute that didn't fit
2687
+ chunks = [call_obj.args[0] for call_obj in mock_read.call_args_list]
2688
+ assert chunks == [[0xFF00, 0xFF01, 0xFF02], [0xFF01]]
2689
+
2690
+ assert events == [
2691
+ AttributeReadEvent(
2692
+ device_ieee=str(dev.ieee),
2693
+ endpoint_id=1,
2694
+ cluster_type=zcl.ClusterType.Server,
2695
+ cluster_id=TestCluster.cluster_id,
2696
+ attribute_name=TestCluster.AttributeDefs.attr_0.name,
2697
+ attribute_id=TestCluster.AttributeDefs.attr_0.id,
2698
+ manufacturer_code=None,
2699
+ raw_value=10,
2700
+ value=10,
2701
+ ),
2702
+ AttributeReadEvent(
2703
+ device_ieee=str(dev.ieee),
2704
+ endpoint_id=1,
2705
+ cluster_type=zcl.ClusterType.Server,
2706
+ cluster_id=TestCluster.cluster_id,
2707
+ attribute_name=TestCluster.AttributeDefs.attr_2.name,
2708
+ attribute_id=TestCluster.AttributeDefs.attr_2.id,
2709
+ manufacturer_code=None,
2710
+ raw_value=30,
2711
+ value=30,
2712
+ ),
2713
+ # No event for attr_1's INSUFFICIENT_SPACE record; the solo re-read then emits
2714
+ # its AttributeReadEvent last, after the two attributes that succeeded in the
2715
+ # batch
2716
+ AttributeReadEvent(
2717
+ device_ieee=str(dev.ieee),
2718
+ endpoint_id=1,
2719
+ cluster_type=zcl.ClusterType.Server,
2720
+ cluster_id=TestCluster.cluster_id,
2721
+ attribute_name=TestCluster.AttributeDefs.attr_1.name,
2722
+ attribute_id=TestCluster.AttributeDefs.attr_1.id,
2723
+ manufacturer_code=None,
2724
+ raw_value=20,
2725
+ value=20,
2726
+ ),
2727
+ ]
2728
+
2729
+
2730
+ async def test_read_attributes_insufficient_space_retry_persistent(app_mock) -> None:
2731
+ """An attribute that still doesn't fit when read alone is a terminal failure."""
2732
+
2733
+ class TestCluster(Basic):
2734
+ _skip_registry = True
2735
+
2736
+ class AttributeDefs(Basic.AttributeDefs):
2737
+ attr_0 = foundation.ZCLAttributeDef(id=0xFF00, type=t.uint8_t)
2738
+ attr_1 = foundation.ZCLAttributeDef(id=0xFF01, type=t.uint8_t)
2739
+
2740
+ dev = add_initialized_device(app_mock, nwk=0x1234, ieee=make_ieee(1))
2741
+ cluster = TestCluster(dev.endpoints[1])
2742
+ dev.endpoints[1].add_input_cluster(TestCluster.cluster_id, cluster)
2743
+
2744
+ attrs = [TestCluster.AttributeDefs.attr_0, TestCluster.AttributeDefs.attr_1]
2745
+
2746
+ supported = {
2747
+ TestCluster.AttributeDefs.attr_0: 10,
2748
+ # Never fits, even when read alone
2749
+ TestCluster.AttributeDefs.attr_1: mock.Mock(
2750
+ return_value=foundation.Status.INSUFFICIENT_SPACE
2751
+ ),
2752
+ }
2753
+
2754
+ with mock_attribute_reads(cluster, supported) as (mock_read, _):
2755
+ success, failure = await cluster.read_attributes(attrs)
2756
+
2757
+ assert success == {TestCluster.AttributeDefs.attr_0: 10}
2758
+ assert failure == {
2759
+ TestCluster.AttributeDefs.attr_1: foundation.Status.INSUFFICIENT_SPACE
2760
+ }
2761
+
2762
+ chunks = [call_obj.args[0] for call_obj in mock_read.call_args_list]
2763
+ assert chunks == [[0xFF00, 0xFF01], [0xFF01]]
2764
+
2765
+
2766
+ async def test_read_attributes_insufficient_space_single_chunk_no_retry(
2767
+ app_mock,
2768
+ ) -> None:
2769
+ """A single-attribute chunk is already isolated, so it is not re-read."""
2770
+
2771
+ class TestCluster(Basic):
2772
+ _skip_registry = True
2773
+
2774
+ class AttributeDefs(Basic.AttributeDefs):
2775
+ attr_0 = foundation.ZCLAttributeDef(id=0xFF00, type=t.uint8_t)
2776
+
2777
+ dev = add_initialized_device(app_mock, nwk=0x1234, ieee=make_ieee(1))
2778
+ cluster = TestCluster(dev.endpoints[1])
2779
+ dev.endpoints[1].add_input_cluster(TestCluster.cluster_id, cluster)
2780
+
2781
+ supported = {
2782
+ TestCluster.AttributeDefs.attr_0: mock.Mock(
2783
+ return_value=foundation.Status.INSUFFICIENT_SPACE
2784
+ ),
2785
+ }
2786
+
2787
+ with mock_attribute_reads(cluster, supported) as (mock_read, _):
2788
+ success, failure = await cluster.read_attributes(
2789
+ [TestCluster.AttributeDefs.attr_0]
2790
+ )
2791
+
2792
+ assert success == {}
2793
+ assert failure == {
2794
+ TestCluster.AttributeDefs.attr_0: foundation.Status.INSUFFICIENT_SPACE
2795
+ }
2796
+
2797
+ # Read exactly once: no redundant solo re-read of an already-isolated attribute
2798
+ chunks = [call_obj.args[0] for call_obj in mock_read.call_args_list]
2799
+ assert chunks == [[0xFF00]]
2800
+
2801
+
2802
+ @pytest.mark.parametrize("omitted_again", [False, True])
2803
+ async def test_read_attributes_omitted_record_retry(
2804
+ app_mock, omitted_again: bool
2805
+ ) -> None:
2806
+ """Records omitted from a response are re-read individually (ZCL R8 §2.5.2.3)."""
2807
+
2808
+ class TestCluster(Basic):
2809
+ _skip_registry = True
2810
+
2811
+ class AttributeDefs(Basic.AttributeDefs):
2812
+ attr_0 = foundation.ZCLAttributeDef(id=0xFF00, type=t.uint8_t)
2813
+ attr_1 = foundation.ZCLAttributeDef(id=0xFF01, type=t.uint8_t)
2814
+
2815
+ dev = add_initialized_device(app_mock, nwk=0x1234, ieee=make_ieee(1))
2816
+ cluster = TestCluster(dev.endpoints[1])
2817
+ dev.endpoints[1].add_input_cluster(TestCluster.cluster_id, cluster)
2818
+
2819
+ attrs = [TestCluster.AttributeDefs.attr_0, TestCluster.AttributeDefs.attr_1]
2820
+
2821
+ supported = {
2822
+ TestCluster.AttributeDefs.attr_0: 10,
2823
+ TestCluster.AttributeDefs.attr_1: mock.Mock(
2824
+ side_effect=[None, None] if omitted_again else [None, 20]
2825
+ ),
2826
+ }
2827
+
2828
+ with mock_attribute_reads(cluster, supported) as (mock_read, _):
2829
+ success, failure = await cluster.read_attributes(attrs)
2830
+
2831
+ if omitted_again:
2832
+ assert success == {TestCluster.AttributeDefs.attr_0: 10}
2833
+ assert failure == {
2834
+ TestCluster.AttributeDefs.attr_1: foundation.Status.INSUFFICIENT_SPACE
2835
+ }
2836
+ else:
2837
+ assert success == {
2838
+ TestCluster.AttributeDefs.attr_0: 10,
2839
+ TestCluster.AttributeDefs.attr_1: 20,
2840
+ }
2841
+ assert failure == {}
2842
+
2843
+ chunks = [call_obj.args[0] for call_obj in mock_read.call_args_list]
2844
+ assert chunks == [[0xFF00, 0xFF01], [0xFF01]]
2845
+
2846
+
2642
2847
  async def test_write_attributes_chunked_by_size(app_mock) -> None:
2643
2848
  """Write_attributes splits requests if a single one would exceed the limit."""
2644
2849
 
@@ -145,8 +145,10 @@ class PriorityDynamicBoundedSemaphore:
145
145
  finally:
146
146
  self._waiters.remove(obj)
147
147
  except asyncio.CancelledError:
148
- # Currently the only exception designed be able to occur here.
149
- if fut.done() and not fut.cancelled():
148
+ # Only undo the bookkeeping if the slot was actually granted. If the future
149
+ # instead carries an exception (e.g. from `cancel_waiting`), no slot was
150
+ # ever acquired and there is nothing to release.
151
+ if fut.done() and not fut.cancelled() and fut.exception() is None:
150
152
  # Our Future was successfully set to True via _wake_up_next(),
151
153
  # but we are not about to successfully acquire(). Therefore we
152
154
  # must undo the bookkeeping already done and attempt to wake
@@ -517,7 +519,10 @@ class RequestLimiter:
517
519
  self._waiters.remove(waiter_obj)
518
520
  heapq.heapify(self._waiters)
519
521
  except asyncio.CancelledError:
520
- if fut.done() and not fut.cancelled():
522
+ # Only undo the bookkeeping if the slot was actually granted. If the future
523
+ # instead carries an exception (e.g. from `cancel_waiting`), no slot was
524
+ # ever acquired and there is nothing to release.
525
+ if fut.done() and not fut.cancelled() and fut.exception() is None:
521
526
  self._active_requests_by_tier[effective_tier] -= 1
522
527
 
523
528
  raise
@@ -1169,6 +1169,8 @@ class Cluster(util.ListenableMixin, util.CatchingTaskMixin, EventBase):
1169
1169
 
1170
1170
  # Now, we can perform the reads for each manufacturer code group
1171
1171
  for manufacturer_code, attribute_group in reads_by_manuf_code.items():
1172
+ retry_attrs: list[foundation.ZCLAttributeDef] = []
1173
+
1172
1174
  for i in range(0, len(attribute_group), MAX_READ_ATTRIBUTES_PER_REQ):
1173
1175
  chunk = attribute_group[i : i + MAX_READ_ATTRIBUTES_PER_REQ]
1174
1176
  result = await self.read_attributes_raw(
@@ -1177,85 +1179,158 @@ class Cluster(util.ListenableMixin, util.CatchingTaskMixin, EventBase):
1177
1179
  **kwargs,
1178
1180
  )
1179
1181
 
1180
- # The read response should contain only these attributes
1181
- potential_attributes = {attr_def.id: attr_def for attr_def in chunk}
1182
+ retry_attrs.extend(
1183
+ self._process_read_attributes_response(
1184
+ result,
1185
+ chunk,
1186
+ attribute_map,
1187
+ manufacturer_code,
1188
+ success,
1189
+ failure,
1190
+ # A single-attribute chunk is already being read in isolation,
1191
+ # so there is nothing to gain from a solo re-read
1192
+ allow_retry=len(chunk) > 1,
1193
+ )
1194
+ )
1195
+
1196
+ # Attributes whose records did not fit in the response frame
1197
+ # (`INSUFFICIENT_SPACE`) or were omitted from it entirely are re-read one
1198
+ # at a time, giving each value the whole frame (ZCL R8 §2.5.2.3). An
1199
+ # attribute that still does not fit when read alone is a terminal failure.
1200
+ for attr_def in retry_attrs:
1201
+ result = await self.read_attributes_raw(
1202
+ [attr_def.id],
1203
+ manufacturer=manufacturer_code,
1204
+ **kwargs,
1205
+ )
1206
+
1207
+ self._process_read_attributes_response(
1208
+ result,
1209
+ [attr_def],
1210
+ attribute_map,
1211
+ manufacturer_code,
1212
+ success,
1213
+ failure,
1214
+ allow_retry=False,
1215
+ )
1182
1216
 
1183
- if not isinstance(result[0], list):
1184
- # If we get back a single response status, all reads failed
1185
- for attr_def in chunk:
1186
- failure[attribute_map[attr_def]] = result[0]
1217
+ return success, failure
1218
+
1219
+ def _process_read_attributes_response(
1220
+ self,
1221
+ result: Any,
1222
+ chunk: list[foundation.ZCLAttributeDef],
1223
+ attribute_map: dict[
1224
+ foundation.ZCLAttributeDef, int | str | foundation.ZCLAttributeDef
1225
+ ],
1226
+ manufacturer_code: int | None,
1227
+ success: dict,
1228
+ failure: dict,
1229
+ *,
1230
+ allow_retry: bool,
1231
+ ) -> list[foundation.ZCLAttributeDef]:
1232
+ """Process a Read Attributes Response, updating `success`/`failure` in place."""
1233
+
1234
+ # If we get back a single response status, all reads failed
1235
+ if not isinstance(result[0], list):
1236
+ for attr_def in chunk:
1237
+ failure[attribute_map[attr_def]] = result[0]
1238
+
1239
+ return []
1240
+
1241
+ # All reads in this chunk used the same manufacturer code
1242
+ seen_attr_ids: set[int] = set()
1243
+
1244
+ # The read response should contain only these attributes
1245
+ potential_attributes = {attr_def.id: attr_def for attr_def in chunk}
1246
+ insufficient_space_attrs: list[foundation.ZCLAttributeDef] = []
1247
+
1248
+ for record in result[0]:
1249
+ attr_def = potential_attributes[record.attrid]
1250
+ seen_attr_ids.add(record.attrid)
1251
+
1252
+ if record.status == foundation.Status.INSUFFICIENT_SPACE and allow_retry:
1253
+ # The value did not fit; re-read it alone with the full frame
1254
+ insufficient_space_attrs.append(attr_def)
1255
+ elif record.status == foundation.Status.SUCCESS:
1256
+ if record.value.value is None:
1257
+ # TODO: remove this workaround when `LocalDataCluster` and
1258
+ # `_VALID_ATTRIBUTES` are removed from quirks. There is no
1259
+ # way for `value` to actually be `None` when read from a
1260
+ # real device.
1261
+ value = None
1187
1262
  else:
1188
- for record in result[0]:
1189
- attr_def = potential_attributes[record.attrid]
1190
-
1191
- if record.status == foundation.Status.SUCCESS:
1192
- if record.value.value is None:
1193
- # TODO: remove this workaround when `LocalDataCluster` and
1194
- # `_VALID_ATTRIBUTES` are removed from quirks. There is no
1195
- # way for `value` to actually be `None` when read from a
1196
- # real device.
1197
- value = None
1198
- else:
1199
- value = attr_def.type(record.value.value)
1263
+ value = attr_def.type(record.value.value)
1200
1264
 
1201
- success[attribute_map[attr_def]] = value
1265
+ success[attribute_map[attr_def]] = value
1202
1266
 
1203
- cached_value = self._legacy_apply_quirk_attribute_update(
1204
- attr_def, value
1205
- )
1267
+ cached_value = self._legacy_apply_quirk_attribute_update(
1268
+ attr_def, value
1269
+ )
1206
1270
 
1207
- if cached_value is None:
1208
- # Quirk swallowed the attribute
1209
- continue
1210
- elif cached_value != value:
1211
- # Quirk transformed the value, emit AttributeUpdatedEvent
1212
- self.emit(
1213
- AttributeUpdatedEvent.event_type,
1214
- AttributeUpdatedEvent(
1215
- device_ieee=str(self.endpoint.device.ieee),
1216
- endpoint_id=self.endpoint.endpoint_id,
1217
- cluster_type=self._type,
1218
- cluster_id=self.cluster_id,
1219
- attribute_name=attr_def.name,
1220
- attribute_id=attr_def.id,
1221
- manufacturer_code=manufacturer_code,
1222
- value=cached_value,
1223
- ),
1224
- )
1225
- else:
1226
- # Value unchanged, emit AttributeReadEvent
1227
- self.emit(
1228
- AttributeReadEvent.event_type,
1229
- AttributeReadEvent(
1230
- device_ieee=str(self.endpoint.device.ieee),
1231
- endpoint_id=self.endpoint.endpoint_id,
1232
- cluster_type=self._type,
1233
- cluster_id=self.cluster_id,
1234
- attribute_name=attr_def.name,
1235
- attribute_id=attr_def.id,
1236
- manufacturer_code=manufacturer_code,
1237
- raw_value=record.value.value,
1238
- value=value,
1239
- ),
1240
- )
1241
- else:
1242
- if record.status == foundation.Status.UNSUPPORTED_ATTRIBUTE:
1243
- self.emit(
1244
- AttributeUnsupportedEvent.event_type,
1245
- AttributeUnsupportedEvent(
1246
- device_ieee=str(self.endpoint.device.ieee),
1247
- endpoint_id=self.endpoint.endpoint_id,
1248
- cluster_type=self._type,
1249
- cluster_id=self.cluster_id,
1250
- attribute_name=attr_def.name,
1251
- attribute_id=attr_def.id,
1252
- manufacturer_code=manufacturer_code,
1253
- ),
1254
- )
1271
+ if cached_value is None:
1272
+ # Quirk swallowed the attribute
1273
+ continue
1274
+ elif cached_value != value:
1275
+ # Quirk transformed the value, emit AttributeUpdatedEvent
1276
+ self.emit(
1277
+ AttributeUpdatedEvent.event_type,
1278
+ AttributeUpdatedEvent(
1279
+ device_ieee=str(self.endpoint.device.ieee),
1280
+ endpoint_id=self.endpoint.endpoint_id,
1281
+ cluster_type=self._type,
1282
+ cluster_id=self.cluster_id,
1283
+ attribute_name=attr_def.name,
1284
+ attribute_id=attr_def.id,
1285
+ manufacturer_code=manufacturer_code,
1286
+ value=cached_value,
1287
+ ),
1288
+ )
1289
+ else:
1290
+ # Value unchanged, emit AttributeReadEvent
1291
+ self.emit(
1292
+ AttributeReadEvent.event_type,
1293
+ AttributeReadEvent(
1294
+ device_ieee=str(self.endpoint.device.ieee),
1295
+ endpoint_id=self.endpoint.endpoint_id,
1296
+ cluster_type=self._type,
1297
+ cluster_id=self.cluster_id,
1298
+ attribute_name=attr_def.name,
1299
+ attribute_id=attr_def.id,
1300
+ manufacturer_code=manufacturer_code,
1301
+ raw_value=record.value.value,
1302
+ value=value,
1303
+ ),
1304
+ )
1305
+ else:
1306
+ if record.status == foundation.Status.UNSUPPORTED_ATTRIBUTE:
1307
+ self.emit(
1308
+ AttributeUnsupportedEvent.event_type,
1309
+ AttributeUnsupportedEvent(
1310
+ device_ieee=str(self.endpoint.device.ieee),
1311
+ endpoint_id=self.endpoint.endpoint_id,
1312
+ cluster_type=self._type,
1313
+ cluster_id=self.cluster_id,
1314
+ attribute_name=attr_def.name,
1315
+ attribute_id=attr_def.id,
1316
+ manufacturer_code=manufacturer_code,
1317
+ ),
1318
+ )
1255
1319
 
1256
- failure[attribute_map[attr_def]] = record.status
1320
+ failure[attribute_map[attr_def]] = record.status
1257
1321
 
1258
- return success, failure
1322
+ # Attributes omitted from the response entirely (ZCL R8 §2.5.2.3): re-read
1323
+ # them individually, or mark them failed if this was already a solo re-read.
1324
+ for attr_def in chunk:
1325
+ if attr_def.id in seen_attr_ids:
1326
+ continue
1327
+
1328
+ if allow_retry:
1329
+ insufficient_space_attrs.append(attr_def)
1330
+ else:
1331
+ failure[attribute_map[attr_def]] = foundation.Status.INSUFFICIENT_SPACE
1332
+
1333
+ return insufficient_space_attrs
1259
1334
 
1260
1335
  def _on_attribute_unsupported(self, event: AttributeUnsupportedEvent) -> None:
1261
1336
  """Handle an attribute being reported as unsupported by the device."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zigpy
3
- Version: 2.0.0
3
+ Version: 2.0.1
4
4
  Summary: Library implementing a Zigbee stack
5
5
  Author-email: Russell Cloran <rcloran@gmail.com>
6
6
  License: GPL-3.0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes