zigpy 2.2.0__tar.gz → 2.3.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.2.0/zigpy.egg-info → zigpy-2.3.0}/PKG-INFO +1 -1
  2. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_appdb.py +73 -1
  3. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_application.py +10 -7
  4. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_device.py +163 -15
  5. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_endpoint.py +3 -0
  6. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_topology.py +15 -0
  7. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_zcl.py +1 -0
  8. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_zcl_foundation.py +10 -0
  9. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_zdo.py +12 -0
  10. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/appdb.py +19 -7
  11. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/application.py +117 -41
  12. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/device.py +357 -88
  13. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/endpoint.py +8 -4
  14. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/exceptions.py +4 -0
  15. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/ota/__init__.py +7 -4
  16. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/ota/manager.py +5 -5
  17. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/ota/providers.py +1 -1
  18. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/topology.py +9 -11
  19. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/types/named.py +68 -1
  20. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zcl/__init__.py +5 -0
  21. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zcl/clusters/general.py +5 -0
  22. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zcl/clusters/greenpower.py +53 -29
  23. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zcl/foundation.py +6 -3
  24. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zdo/__init__.py +4 -0
  25. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zgp/__init__.py +1 -0
  26. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zgp/commands.py +14 -8
  27. zigpy-2.3.0/zigpy/zgp/tunneling.py +117 -0
  28. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zgp/types.py +121 -4
  29. zigpy-2.3.0/zigpy/zgp/util.py +40 -0
  30. {zigpy-2.2.0 → zigpy-2.3.0/zigpy.egg-info}/PKG-INFO +1 -1
  31. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy.egg-info/SOURCES.txt +3 -1
  32. {zigpy-2.2.0 → zigpy-2.3.0}/COPYING +0 -0
  33. {zigpy-2.2.0 → zigpy-2.3.0}/LICENSE +0 -0
  34. {zigpy-2.2.0 → zigpy-2.3.0}/README.md +0 -0
  35. {zigpy-2.2.0 → zigpy-2.3.0}/pyproject.toml +0 -0
  36. {zigpy-2.2.0 → zigpy-2.3.0}/setup.cfg +0 -0
  37. {zigpy-2.2.0 → zigpy-2.3.0}/setup.py +0 -0
  38. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_app_state.py +0 -0
  39. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_appdb_migration.py +0 -0
  40. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_backups.py +0 -0
  41. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_config.py +0 -0
  42. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_datastructures.py +0 -0
  43. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_datastructures_cpython.py +0 -0
  44. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_event.py +0 -0
  45. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_group.py +0 -0
  46. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_listeners.py +0 -0
  47. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_packet_callbacks.py +0 -0
  48. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_serial.py +0 -0
  49. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_struct.py +0 -0
  50. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_types.py +0 -0
  51. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_zcl_clusters.py +0 -0
  52. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_zcl_helpers.py +0 -0
  53. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_zdo_types.py +0 -0
  54. {zigpy-2.2.0 → zigpy-2.3.0}/tests/test_zigbee_util.py +0 -0
  55. {zigpy-2.2.0 → zigpy-2.3.0}/tools/__init__.py +0 -0
  56. {zigpy-2.2.0 → zigpy-2.3.0}/tools/regenerate_mypy_ignores.py +0 -0
  57. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/__init__.py +0 -0
  58. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/appdb_schemas/__init__.py +0 -0
  59. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v0.sql +0 -0
  60. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v1.sql +0 -0
  61. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v10.sql +0 -0
  62. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v11.sql +0 -0
  63. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v12.sql +0 -0
  64. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v13.sql +0 -0
  65. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v14.sql +0 -0
  66. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v15.sql +0 -0
  67. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v2.sql +0 -0
  68. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v3.sql +0 -0
  69. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v4.sql +0 -0
  70. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v5.sql +0 -0
  71. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v6.sql +0 -0
  72. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v7.sql +0 -0
  73. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v8.sql +0 -0
  74. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v9.sql +0 -0
  75. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/backports/__init__.py +0 -0
  76. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/backups.py +0 -0
  77. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/config/__init__.py +0 -0
  78. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/config/defaults.py +0 -0
  79. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/config/validators.py +0 -0
  80. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/const.py +0 -0
  81. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/datastructures.py +0 -0
  82. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/event/__init__.py +0 -0
  83. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/event/event_base.py +0 -0
  84. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/group.py +0 -0
  85. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/listeners.py +0 -0
  86. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/ota/image.py +0 -0
  87. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/ota/json_schemas.py +0 -0
  88. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/ota/validators.py +0 -0
  89. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/profiles/__init__.py +0 -0
  90. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/profiles/zgp.py +0 -0
  91. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/profiles/zha.py +0 -0
  92. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/profiles/zll.py +0 -0
  93. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/py.typed +0 -0
  94. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/quirks/__init__.py +0 -0
  95. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/quirks/registry.py +0 -0
  96. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/quirks/v2/__init__.py +0 -0
  97. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/quirks/v2/homeassistant/__init__.py +0 -0
  98. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/quirks/v2/homeassistant/binary_sensor.py +0 -0
  99. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/quirks/v2/homeassistant/number.py +0 -0
  100. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/quirks/v2/homeassistant/sensor.py +0 -0
  101. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/serial.py +0 -0
  102. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/state.py +0 -0
  103. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/types/__init__.py +0 -0
  104. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/types/basic.py +0 -0
  105. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/types/struct.py +0 -0
  106. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/typing.py +0 -0
  107. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/util.py +0 -0
  108. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zcl/clusters/__init__.py +0 -0
  109. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zcl/clusters/closures.py +0 -0
  110. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zcl/clusters/general_const.py +0 -0
  111. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zcl/clusters/homeautomation.py +0 -0
  112. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zcl/clusters/hvac.py +0 -0
  113. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zcl/clusters/lighting.py +0 -0
  114. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zcl/clusters/lightlink.py +0 -0
  115. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zcl/clusters/manufacturer_specific.py +0 -0
  116. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zcl/clusters/measurement.py +0 -0
  117. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zcl/clusters/protocol.py +0 -0
  118. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zcl/clusters/security.py +0 -0
  119. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zcl/clusters/smartenergy.py +0 -0
  120. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zcl/clusters/wwah.py +0 -0
  121. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zcl/helpers.py +0 -0
  122. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zdo/types.py +0 -0
  123. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy/zgp/crypto.py +0 -0
  124. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy.egg-info/dependency_links.txt +0 -0
  125. {zigpy-2.2.0 → zigpy-2.3.0}/zigpy.egg-info/requires.txt +0 -0
  126. {zigpy-2.2.0 → zigpy-2.3.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.2.0
3
+ Version: 2.3.0
4
4
  Summary: Library implementing a Zigbee stack
5
5
  Author-email: Russell Cloran <rcloran@gmail.com>
6
6
  License: GPL-3.0
@@ -32,7 +32,7 @@ from zigpy.const import (
32
32
  SIG_MODEL,
33
33
  SIG_NODE_DESC,
34
34
  )
35
- from zigpy.device import Device, Status
35
+ from zigpy.device import Device, GreenPowerDevice, Status
36
36
  import zigpy.endpoint
37
37
  import zigpy.ota
38
38
  import zigpy.types as t
@@ -45,6 +45,7 @@ from zigpy.zcl import (
45
45
  from zigpy.zcl.clusters.general import Basic, Identify, OnOff, Ota
46
46
  from zigpy.zcl.foundation import Status as ZCLStatus, ZCLAttributeDef
47
47
  from zigpy.zdo import types as zdo_t
48
+ from zigpy.zgp.types import ApplicationID, SrcID
48
49
 
49
50
  pytestmark = pytest.mark.usefixtures("auto_kill_aiosqlite")
50
51
 
@@ -1485,6 +1486,61 @@ async def test_quirk_virtual_endpoints_not_persisted(tmp_path) -> None:
1485
1486
  await app2.shutdown()
1486
1487
 
1487
1488
 
1489
+ async def test_inactive_endpoints_round_trip(tmp_path) -> None:
1490
+ """A device listing inactive endpoints is persisted and reloads intact."""
1491
+
1492
+ db = tmp_path / "test.db"
1493
+ app = await make_app_with_db(db)
1494
+
1495
+ ieee = t.EUI64.convert("aa:bb:cc:dd:11:22:33:44")
1496
+ dev = app.add_device(nwk=0x1234, ieee=ieee)
1497
+ dev.node_desc = make_node_desc()
1498
+
1499
+ # Endpoint 2 is listed as active but has no simple descriptor, zigpy/zigpy#1894
1500
+ async def mock_active_ep_req(nwk):
1501
+ return [zdo_t.Status.SUCCESS, nwk, [1, 2]]
1502
+
1503
+ async def mock_simple_desc_req(nwk, endpoint_id):
1504
+ if endpoint_id == 2:
1505
+ return [zdo_t.Status.NOT_ACTIVE, nwk, None]
1506
+
1507
+ return [
1508
+ zdo_t.Status.SUCCESS,
1509
+ nwk,
1510
+ zdo_t.SizePrefixedSimpleDescriptor(
1511
+ endpoint=1,
1512
+ profile=profiles.zha.PROFILE_ID,
1513
+ device_type=profiles.zha.DeviceType.ON_OFF_SWITCH,
1514
+ device_version=1,
1515
+ input_clusters=[Basic.cluster_id],
1516
+ output_clusters=[OnOff.cluster_id],
1517
+ ),
1518
+ ]
1519
+
1520
+ dev.zdo.Active_EP_req = mock_active_ep_req
1521
+ dev.zdo.Simple_Desc_req = mock_simple_desc_req
1522
+
1523
+ with patch(
1524
+ "zigpy.endpoint.Endpoint.get_model_info",
1525
+ AsyncMock(return_value=("Model", "Manufacturer")),
1526
+ ):
1527
+ await dev.initialize()
1528
+
1529
+ assert dev.is_initialized
1530
+ await app.shutdown()
1531
+
1532
+ app2 = await make_app_with_db(db)
1533
+ dev2 = app2.get_device(ieee)
1534
+
1535
+ assert list(dev2.original_signature[SIG_ENDPOINTS]) == [1]
1536
+ assert dev2.endpoints[1].profile_id == profiles.zha.PROFILE_ID
1537
+ assert dev2.endpoints[1].device_type == profiles.zha.DeviceType.ON_OFF_SWITCH
1538
+ assert list(dev2.endpoints[1].in_clusters) == [Basic.cluster_id]
1539
+ assert list(dev2.endpoints[1].out_clusters) == [OnOff.cluster_id]
1540
+
1541
+ await app2.shutdown()
1542
+
1543
+
1488
1544
  async def test_reinterview_changed_signature_round_trip(tmp_path) -> None:
1489
1545
  """A reinterview that changes the device's whole signature is persisted cleanly."""
1490
1546
 
@@ -2083,3 +2139,19 @@ async def test_get_last_ota_query_cmd_returns_none(tmp_path):
2083
2139
  assert dev.get_last_ota_query_cmd() is None
2084
2140
 
2085
2141
  await app.shutdown()
2142
+
2143
+
2144
+ async def test_load_with_green_power_device(tmp_path):
2145
+ """A GPD in `app.devices` has no endpoints whose attribute cache needs clearing."""
2146
+ db = tmp_path / "test.db"
2147
+ app = make_app({conf.CONF_DATABASE: str(db)})
2148
+ gpd = GreenPowerDevice(
2149
+ app, application_id=ApplicationID.SrcID, src_id=SrcID(0x12345678)
2150
+ )
2151
+ app.devices[gpd.ieee] = gpd
2152
+
2153
+ await app._load_db()
2154
+
2155
+ assert app.devices[gpd.ieee] is gpd
2156
+
2157
+ await app.shutdown()
@@ -121,8 +121,10 @@ async def _remove(
121
121
  else:
122
122
  raise TimeoutError
123
123
 
124
- device = MagicMock()
124
+ device = MagicMock(spec=zigpy.device.ZigbeeDevice)
125
125
  device.ieee = ieee
126
+ device.nwk = 0x1234
127
+ device.zdo = MagicMock()
126
128
  device.zdo.leave.side_effect = leave
127
129
 
128
130
  if has_node_desc:
@@ -805,9 +807,10 @@ async def test_request_concurrency():
805
807
 
806
808
  @pytest.fixture
807
809
  def device():
808
- device = MagicMock()
810
+ device = MagicMock(spec=zigpy.device.ZigbeeDevice)
809
811
  device.nwk = 0xABCD
810
812
  device.ieee = t.EUI64.convert("aa:bb:cc:dd:11:22:33:44")
813
+ device._concurrent_requests_semaphore = MagicMock()
811
814
 
812
815
  return device
813
816
 
@@ -946,11 +949,11 @@ async def test_force_route_discovery(app, device, packet) -> None:
946
949
  ]
947
950
 
948
951
 
949
- async def test_request_zigbee_direct_aps_encryption(app, device, packet) -> None:
952
+ async def test_request_aps_encryption(app, device, packet) -> None:
950
953
  await app.request(
951
954
  device=device,
952
955
  profile=0x1234,
953
- cluster=clusters.general.ZigbeeDirectConfiguration.cluster_id,
956
+ cluster=0x0006,
954
957
  src_ep=0x9A,
955
958
  dst_ep=0xBC,
956
959
  sequence=0xDE,
@@ -958,12 +961,12 @@ async def test_request_zigbee_direct_aps_encryption(app, device, packet) -> None
958
961
  expect_reply=True,
959
962
  use_ieee=False,
960
963
  extended_timeout=False,
964
+ aps_encryption=True,
961
965
  )
962
966
 
963
967
  assert app.send_packet.mock_calls == [
964
968
  call(
965
969
  packet.replace(
966
- cluster_id=clusters.general.ZigbeeDirectConfiguration.cluster_id,
967
970
  tx_options=packet.tx_options | t.TransmitOptions.APS_Encryption,
968
971
  priority=t.PacketPriority.NORMAL,
969
972
  )
@@ -1778,7 +1781,7 @@ async def test_callback_wrapping(
1778
1781
  "zigpy.application",
1779
1782
  logging.WARNING,
1780
1783
  (
1781
- "Device <Device model=None manuf=None nwk=0x1234 "
1784
+ "Device <ZigbeeDevice model=None manuf=None nwk=0x1234 "
1782
1785
  "ieee=07:06:05:04:03:02:01:00 is_initialized=False> "
1783
1786
  "callback failed - ValueError('Boom!')"
1784
1787
  ),
@@ -1807,7 +1810,7 @@ async def test_callback_wrapping_async(
1807
1810
  "zigpy.application",
1808
1811
  logging.WARNING,
1809
1812
  (
1810
- "Device <Device model=None manuf=None nwk=0x1234 "
1813
+ "Device <ZigbeeDevice model=None manuf=None nwk=0x1234 "
1811
1814
  "ieee=07:06:05:04:03:02:01:00 is_initialized=False> "
1812
1815
  "callback failed - ValueError('Boom!')"
1813
1816
  ),
@@ -19,7 +19,14 @@ import zigpy.state
19
19
  import zigpy.types as t
20
20
  import zigpy.util
21
21
  from zigpy.zcl import ClusterType, OtaQueryCacheClearedEvent, foundation
22
- from zigpy.zcl.clusters.general import Basic, OnOff, Ota, PollControl
22
+ from zigpy.zcl.clusters.general import (
23
+ Basic,
24
+ KeepAlive,
25
+ OnOff,
26
+ Ota,
27
+ PollControl,
28
+ ZigbeeDirectConfiguration,
29
+ )
23
30
  from zigpy.zdo import types as zdo_t
24
31
 
25
32
  from .async_mock import AsyncMock, MagicMock, patch, sentinel
@@ -211,6 +218,53 @@ async def test_initialize_ep_failed(monkeypatch, dev):
211
218
  assert dev.application.listener_event.call_args[0][0] == "device_init_failure"
212
219
 
213
220
 
221
+ @pytest.mark.parametrize(
222
+ ("active_eps", "inactive_eps"),
223
+ [
224
+ # Aqara H1 remote, zigpy/zigpy#1894
225
+ ([1, 2, 3, 4], [5, 6]),
226
+ ([1, 3], [2]),
227
+ ],
228
+ )
229
+ async def test_initialize_removes_inactive_endpoints(
230
+ monkeypatch, dev, active_eps: list[int], inactive_eps: list[int]
231
+ ) -> None:
232
+ """Endpoints listed as active but without a simple descriptor are removed."""
233
+
234
+ async def mock_active_ep_req(nwk):
235
+ return [zdo_t.Status.SUCCESS, nwk, sorted(active_eps + inactive_eps)]
236
+
237
+ async def mock_simple_desc_req(nwk, endpoint_id):
238
+ if endpoint_id in inactive_eps:
239
+ return [zdo_t.Status.NOT_ACTIVE, nwk, None]
240
+
241
+ return [
242
+ zdo_t.Status.SUCCESS,
243
+ nwk,
244
+ zdo_t.SizePrefixedSimpleDescriptor(
245
+ endpoint=endpoint_id,
246
+ profile=zha.PROFILE_ID,
247
+ device_type=zha.DeviceType.ON_OFF_SWITCH,
248
+ device_version=1,
249
+ input_clusters=[Basic.cluster_id],
250
+ output_clusters=[OnOff.cluster_id],
251
+ ),
252
+ ]
253
+
254
+ async def mock_ep_get_model_info(self):
255
+ return "Model", "Manufacturer"
256
+
257
+ monkeypatch.setattr(endpoint.Endpoint, "get_model_info", mock_ep_get_model_info)
258
+ dev.zdo.Active_EP_req = mock_active_ep_req
259
+ dev.zdo.Simple_Desc_req = mock_simple_desc_req
260
+
261
+ await dev.initialize()
262
+
263
+ assert dev.is_initialized
264
+ assert [ep.endpoint_id for ep in dev.non_zdo_endpoints] == active_eps
265
+ assert all(ep.status == endpoint.Status.ZDO_INIT for ep in dev.non_zdo_endpoints)
266
+
267
+
214
268
  async def test_failed_request(dev):
215
269
  assert dev.last_seen is None
216
270
  dev._application.send_packet = AsyncMock(
@@ -227,20 +281,6 @@ def test_skip_configuration(dev):
227
281
  assert dev.skip_configuration is True
228
282
 
229
283
 
230
- def test_radio_details(dev):
231
- dev.radio_details(1, 2)
232
- assert dev.lqi == 1
233
- assert dev.rssi == 2
234
-
235
- dev.radio_details(lqi=3)
236
- assert dev.lqi == 3
237
- assert dev.rssi == 2
238
-
239
- dev.radio_details(rssi=4)
240
- assert dev.lqi == 3
241
- assert dev.rssi == 4
242
-
243
-
244
284
  async def test_handle_message_deserialize_error(dev):
245
285
  ep = dev.add_endpoint(3)
246
286
  ep.deserialize = MagicMock(side_effect=ValueError)
@@ -501,6 +541,84 @@ async def test_handle_unknown_cluster(dev, caplog) -> None:
501
541
  assert "Ignoring message on unknown cluster: 0x9999" in caplog.text
502
542
 
503
543
 
544
+ @pytest.mark.parametrize(
545
+ "tx_options", [t.TransmitOptions.NONE, t.TransmitOptions.APS_Encryption]
546
+ )
547
+ async def test_keep_alive_reply_aps_encryption(dev, app_mock, tx_options) -> None:
548
+ """Keep-Alive replies are APS encrypted regardless of the request."""
549
+ dev.add_endpoint(1).add_output_cluster(KeepAlive.cluster_id)
550
+
551
+ req_hdr = foundation.ZCLHeader(
552
+ frame_control=foundation.FrameControl(
553
+ frame_type=foundation.FrameType.GLOBAL_COMMAND,
554
+ is_manufacturer_specific=False,
555
+ direction=foundation.Direction.Client_to_Server,
556
+ disable_default_response=True,
557
+ reserved=0,
558
+ ),
559
+ tsn=8,
560
+ command_id=foundation.GeneralCommand.Read_Attributes,
561
+ )
562
+ req_cmd = foundation.GENERAL_COMMANDS[
563
+ foundation.GeneralCommand.Read_Attributes
564
+ ].schema(
565
+ attribute_ids=[
566
+ KeepAlive.AttributeDefs.tc_keep_alive_base.id,
567
+ KeepAlive.AttributeDefs.tc_keep_alive_jitter.id,
568
+ ]
569
+ )
570
+
571
+ dev.packet_received(
572
+ t.ZigbeePacket(
573
+ profile_id=zha.PROFILE_ID,
574
+ cluster_id=KeepAlive.cluster_id,
575
+ src_ep=1,
576
+ dst_ep=1,
577
+ tsn=req_hdr.tsn,
578
+ data=t.SerializableBytes(req_hdr.serialize() + req_cmd.serialize()),
579
+ src=t.AddrModeAddress(addr_mode=t.AddrMode.NWK, address=dev.nwk),
580
+ dst=t.AddrModeAddress(addr_mode=t.AddrMode.NWK, address=0x0000),
581
+ tx_options=tx_options,
582
+ )
583
+ )
584
+ await asyncio.sleep(0.01)
585
+
586
+ assert len(app_mock.send_packet.mock_calls) == 1
587
+ packet = app_mock.send_packet.mock_calls[0].args[0]
588
+ assert packet.dst.address == dev.nwk
589
+ assert packet.cluster_id == KeepAlive.cluster_id
590
+ assert packet.tsn == req_hdr.tsn
591
+ assert t.TransmitOptions.APS_Encryption in packet.tx_options
592
+
593
+
594
+ @pytest.mark.parametrize(
595
+ ("cluster", "encrypted"),
596
+ [
597
+ (OnOff, False),
598
+ (KeepAlive, True),
599
+ (ZigbeeDirectConfiguration, True),
600
+ ],
601
+ )
602
+ async def test_cluster_request_aps_encryption(
603
+ dev, app_mock, cluster, encrypted
604
+ ) -> None:
605
+ """Requests on clusters that require APS encryption set the transmit option."""
606
+ zcl_cluster = dev.add_endpoint(1).add_input_cluster(cluster.cluster_id)
607
+
608
+ await zcl_cluster.request(
609
+ True,
610
+ foundation.GeneralCommand.Read_Attributes,
611
+ foundation.GENERAL_COMMANDS[foundation.GeneralCommand.Read_Attributes].schema,
612
+ attribute_ids=[0x0000],
613
+ expect_reply=False,
614
+ )
615
+
616
+ assert len(app_mock.send_packet.mock_calls) == 1
617
+ packet = app_mock.send_packet.mock_calls[0].args[0]
618
+ assert packet.cluster_id == cluster.cluster_id
619
+ assert (t.TransmitOptions.APS_Encryption in packet.tx_options) == encrypted
620
+
621
+
504
622
  async def test_update_device_firmware_no_ota_cluster(dev):
505
623
  """Test that device firmware updates fails: no ota cluster."""
506
624
  mock_image = MagicMock()
@@ -2179,6 +2297,7 @@ async def test_reinterview_during_ota(dev):
2179
2297
  dev._application._device_reinterviewed.assert_not_called()
2180
2298
 
2181
2299
 
2300
+ @patch("zigpy.device.AFTER_OTA_ATTR_READ_DELAY", 0.01)
2182
2301
  async def test_update_firmware_triggers_reinterview(monkeypatch, dev):
2183
2302
  """Test that successful OTA triggers reinterview."""
2184
2303
  ep = dev.add_endpoint(1)
@@ -2475,3 +2594,32 @@ async def test_request_retry_delay_releases_concurrency(app) -> None:
2475
2594
  # Tear down the still-pending requests so the task group can exit
2476
2595
  for task in tasks:
2477
2596
  task.cancel()
2597
+
2598
+
2599
+ async def test_radio_details_deprecated(dev) -> None:
2600
+ with pytest.deprecated_call():
2601
+ dev.radio_details(lqi=120, rssi=-45)
2602
+
2603
+ assert dev.lqi == 120
2604
+ assert dev.rssi == -45
2605
+
2606
+ with pytest.deprecated_call():
2607
+ dev.radio_details(lqi=99)
2608
+
2609
+ assert dev.lqi == 99
2610
+ assert dev.rssi == -45
2611
+
2612
+ with pytest.deprecated_call():
2613
+ dev.radio_details(rssi=-80)
2614
+
2615
+ assert dev.lqi == 99
2616
+ assert dev.rssi == -80
2617
+
2618
+
2619
+ async def test_update_last_seen_deprecated(dev) -> None:
2620
+ assert dev.last_seen is None
2621
+
2622
+ with pytest.deprecated_call():
2623
+ dev.update_last_seen()
2624
+
2625
+ assert dev.last_seen is not None
@@ -177,6 +177,7 @@ async def test_reply_change_profile_id(ep):
177
177
  priority=None,
178
178
  retries=None,
179
179
  retry_delay=None,
180
+ aps_encryption=False,
180
181
  )
181
182
  ]
182
183
 
@@ -197,6 +198,7 @@ async def test_reply_change_profile_id(ep):
197
198
  priority=None,
198
199
  retries=None,
199
200
  retry_delay=None,
201
+ aps_encryption=False,
200
202
  )
201
203
  ]
202
204
 
@@ -218,6 +220,7 @@ async def test_reply_change_profile_id(ep):
218
220
  priority=None,
219
221
  retries=None,
220
222
  retry_delay=None,
223
+ aps_encryption=False,
221
224
  )
222
225
  ]
223
226
 
@@ -9,11 +9,13 @@ import pytest
9
9
  from tests.conftest import App, make_ieee, make_neighbor, make_route
10
10
  import zigpy.config as conf
11
11
  import zigpy.device
12
+ from zigpy.device import GreenPowerDevice
12
13
  import zigpy.endpoint
13
14
  import zigpy.profiles
14
15
  import zigpy.topology
15
16
  import zigpy.types as t
16
17
  import zigpy.zdo.types as zdo_t
18
+ from zigpy.zgp.types import ApplicationID, SrcID
17
19
 
18
20
 
19
21
  @pytest.fixture(autouse=True)
@@ -205,6 +207,19 @@ async def test_scan_end_device(topology, make_initialized_device) -> None:
205
207
  assert len(dev.zdo.Mgmt_Rtg_req.mock_calls) == 0
206
208
 
207
209
 
210
+ async def test_scan_skips_gp_device(topology) -> None:
211
+ app = topology._app
212
+ gpd = GreenPowerDevice(
213
+ app, application_id=ApplicationID.SrcID, src_id=SrcID(0x12345678)
214
+ )
215
+ app.devices[gpd.ieee] = gpd
216
+
217
+ await topology.scan()
218
+
219
+ assert gpd.ieee not in topology.neighbors
220
+ assert gpd.ieee not in topology.routes
221
+
222
+
208
223
  async def test_scan_explicit_device(topology, make_initialized_device) -> None:
209
224
  dev1 = make_initialized_device(topology._app)
210
225
  dev2 = make_initialized_device(topology._app)
@@ -1743,6 +1743,7 @@ async def test_received_onoff_toggle_generates_default_response():
1743
1743
  priority=t.PacketPriority.LOW,
1744
1744
  retries=None,
1745
1745
  retry_delay=None,
1746
+ aps_encryption=False,
1746
1747
  )
1747
1748
  ]
1748
1749
 
@@ -478,6 +478,16 @@ def test_ptype_to_datatype_notype():
478
478
  assert foundation.DataType.from_python_type(ZigpyUnknown) == foundation.DataType.unk
479
479
 
480
480
 
481
+ def test_datatype_from_unknown_type_id():
482
+ """Test an unmapped ZCL data type ID raises ValueError, not KeyError."""
483
+
484
+ with pytest.raises(ValueError, match="Unknown ZCL data type ID: 0x8A"):
485
+ foundation.DataType.from_type_id(0x8A)
486
+
487
+ with pytest.raises(ValueError):
488
+ foundation.Attribute.deserialize(b"\x01\x00\x8a\x05")
489
+
490
+
481
491
  def test_write_attrs_response_deserialize():
482
492
  """Test deserialization."""
483
493
 
@@ -200,6 +200,18 @@ async def test_reply(zdo_f):
200
200
  assert zdo_f.device.request.call_count == 1
201
201
 
202
202
 
203
+ @pytest.mark.parametrize("aps_encryption", [False, True])
204
+ async def test_request_aps_encryption(zdo_f, aps_encryption):
205
+ await zdo_f.request(2, 65535, aps_encryption=aps_encryption)
206
+ assert zdo_f.device.request.mock_calls[0].kwargs["aps_encryption"] is aps_encryption
207
+
208
+
209
+ @pytest.mark.parametrize("aps_encryption", [False, True])
210
+ async def test_reply_aps_encryption(zdo_f, aps_encryption):
211
+ await zdo_f.reply(0x8002, aps_encryption=aps_encryption)
212
+ assert zdo_f.device.request.mock_calls[0].kwargs["aps_encryption"] is aps_encryption
213
+
214
+
203
215
  def test_get_attr_error(zdo_f):
204
216
  with pytest.raises(AttributeError):
205
217
  zdo_f.no_such_attribute()
@@ -783,6 +783,10 @@ class PersistingListener(zigpy.util.CatchingTaskMixin):
783
783
 
784
784
  # Clear the attribute cache to ensure the quirked state is correct
785
785
  for device in self._application.devices.values():
786
+ # Only Zigbee devices have endpoints with an attribute cache
787
+ if not isinstance(device, Device):
788
+ continue
789
+
786
790
  for ep in device.non_zdo_endpoints:
787
791
  for cluster in ep.in_clusters.values():
788
792
  cluster._attr_cache.clear()
@@ -808,6 +812,14 @@ class PersistingListener(zigpy.util.CatchingTaskMixin):
808
812
 
809
813
  await self._register_device_listeners()
810
814
 
815
+ def _get_zigbee_device(self, ieee: t.EUI64) -> Device:
816
+ device = self._application.get_device(ieee)
817
+
818
+ if not isinstance(device, Device):
819
+ raise TypeError(f"Device {device} is not a Zigbee device")
820
+
821
+ return device
822
+
811
823
  async def _populate_attribute_cache(
812
824
  self,
813
825
  rows: list[AttributeCacheRow],
@@ -821,7 +833,7 @@ class PersistingListener(zigpy.util.CatchingTaskMixin):
821
833
  updated to match.
822
834
  """
823
835
  for row in rows:
824
- dev = self._application.get_device(row.ieee)
836
+ dev = self._get_zigbee_device(row.ieee)
825
837
 
826
838
  LOGGER.debug(
827
839
  "[0x%04x:%s:0x%04x] Loading attribute %s=%r status=%r mfg_code=%r",
@@ -1032,14 +1044,14 @@ class PersistingListener(zigpy.util.CatchingTaskMixin):
1032
1044
  async def _load_node_descriptors(self) -> None:
1033
1045
  async with self.execute(f"SELECT * FROM node_descriptors{DB_V}") as cursor:
1034
1046
  async for ieee, *fields in cursor:
1035
- dev = self._application.get_device(ieee)
1047
+ dev = self._get_zigbee_device(ieee)
1036
1048
  dev.node_desc = zdo_t.NodeDescriptor(*fields)
1037
1049
  assert dev.node_desc.is_valid
1038
1050
 
1039
1051
  async def _load_endpoints(self) -> None:
1040
1052
  async with self.execute(f"SELECT * FROM endpoints{DB_V}") as cursor:
1041
1053
  async for ieee, epid, profile_id, device_type, status in cursor:
1042
- dev = self._application.get_device(ieee)
1054
+ dev = self._get_zigbee_device(ieee)
1043
1055
  ep = dev.add_endpoint(epid)
1044
1056
  ep.profile_id = profile_id
1045
1057
  ep.status = EndpointStatus(status)
@@ -1054,7 +1066,7 @@ class PersistingListener(zigpy.util.CatchingTaskMixin):
1054
1066
  async def _load_clusters(self) -> None:
1055
1067
  async with self.execute(f"SELECT * FROM clusters{DB_V}") as cursor:
1056
1068
  async for ieee, endpoint_id, cluster_type, cluster_id in cursor:
1057
- dev = self._application.get_device(ieee)
1069
+ dev = self._get_zigbee_device(ieee)
1058
1070
  ep = dev.endpoints[endpoint_id]
1059
1071
 
1060
1072
  if ClusterType(cluster_type) == ClusterType.Server:
@@ -1070,14 +1082,14 @@ class PersistingListener(zigpy.util.CatchingTaskMixin):
1070
1082
  async def _load_group_members(self) -> None:
1071
1083
  async with self.execute(f"SELECT * FROM group_members{DB_V}") as cursor:
1072
1084
  async for group_id, ieee, ep_id in cursor:
1073
- dev = self._application.get_device(ieee)
1085
+ dev = self._get_zigbee_device(ieee)
1074
1086
  group = self._application.groups[group_id]
1075
1087
  group.add_member(dev.endpoints[ep_id], suppress_event=True)
1076
1088
 
1077
1089
  async def _load_relays(self) -> None:
1078
1090
  async with self.execute(f"SELECT * FROM relays{DB_V}") as cursor:
1079
1091
  async for ieee, value in cursor:
1080
- dev = self._application.get_device(ieee)
1092
+ dev = self._get_zigbee_device(ieee)
1081
1093
  relays, _ = t.Relays.deserialize(value)
1082
1094
  dev.relays = zigpy.util.filter_relays(relays)
1083
1095
 
@@ -1122,7 +1134,7 @@ class PersistingListener(zigpy.util.CatchingTaskMixin):
1122
1134
  _last_updated,
1123
1135
  ) in cursor:
1124
1136
  try:
1125
- dev = self._application.get_device(ieee)
1137
+ dev = self._get_zigbee_device(ieee)
1126
1138
  ep = dev.endpoints[endpoint_id]
1127
1139
  except KeyError:
1128
1140
  # Quirks or firmware updates can remove endpoints/clusters