zigpy 2.1.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.
- {zigpy-2.1.0/zigpy.egg-info → zigpy-2.3.0}/PKG-INFO +1 -1
- {zigpy-2.1.0 → zigpy-2.3.0}/pyproject.toml +3 -4
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_appdb.py +73 -1
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_appdb_migration.py +1 -1
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_application.py +10 -7
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_backups.py +0 -1
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_device.py +163 -15
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_endpoint.py +3 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_struct.py +105 -1
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_topology.py +15 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_types.py +104 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_zcl.py +142 -51
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_zcl_foundation.py +10 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_zdo.py +12 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/appdb.py +19 -7
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/application.py +117 -41
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/device.py +357 -88
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/endpoint.py +8 -4
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/exceptions.py +4 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/ota/__init__.py +7 -4
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/ota/manager.py +5 -5
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/ota/providers.py +1 -1
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/quirks/v2/__init__.py +0 -1
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/topology.py +9 -11
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/types/basic.py +51 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/types/named.py +68 -1
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/types/struct.py +3 -2
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zcl/__init__.py +24 -2
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zcl/clusters/general.py +5 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zcl/clusters/greenpower.py +57 -33
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zcl/foundation.py +6 -3
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zdo/__init__.py +4 -0
- zigpy-2.3.0/zigpy/zgp/__init__.py +46 -0
- zigpy-2.3.0/zigpy/zgp/commands.py +465 -0
- zigpy-2.3.0/zigpy/zgp/tunneling.py +117 -0
- zigpy-2.3.0/zigpy/zgp/types.py +327 -0
- zigpy-2.3.0/zigpy/zgp/util.py +40 -0
- {zigpy-2.1.0 → zigpy-2.3.0/zigpy.egg-info}/PKG-INFO +1 -1
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy.egg-info/SOURCES.txt +4 -2
- zigpy-2.1.0/zigpy/zgp/__init__.py +0 -21
- zigpy-2.1.0/zigpy/zgp/frame.py +0 -145
- zigpy-2.1.0/zigpy/zgp/types.py +0 -181
- {zigpy-2.1.0 → zigpy-2.3.0}/COPYING +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/LICENSE +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/README.md +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/setup.cfg +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/setup.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_app_state.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_config.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_datastructures.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_datastructures_cpython.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_event.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_group.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_listeners.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_packet_callbacks.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_serial.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_zcl_clusters.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_zcl_helpers.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_zdo_types.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tests/test_zigbee_util.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tools/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/tools/regenerate_mypy_ignores.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/appdb_schemas/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v0.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v1.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v10.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v11.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v12.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v13.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v14.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v15.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v2.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v3.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v4.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v5.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v6.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v7.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v8.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/appdb_schemas/schema_v9.sql +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/backports/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/backups.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/config/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/config/defaults.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/config/validators.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/const.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/datastructures.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/event/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/event/event_base.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/group.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/listeners.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/ota/image.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/ota/json_schemas.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/ota/validators.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/profiles/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/profiles/zgp.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/profiles/zha.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/profiles/zll.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/py.typed +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/quirks/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/quirks/registry.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/quirks/v2/homeassistant/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/quirks/v2/homeassistant/binary_sensor.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/quirks/v2/homeassistant/number.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/quirks/v2/homeassistant/sensor.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/serial.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/state.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/types/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/typing.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/util.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zcl/clusters/__init__.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zcl/clusters/closures.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zcl/clusters/general_const.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zcl/clusters/homeautomation.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zcl/clusters/hvac.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zcl/clusters/lighting.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zcl/clusters/lightlink.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zcl/clusters/manufacturer_specific.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zcl/clusters/measurement.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zcl/clusters/protocol.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zcl/clusters/security.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zcl/clusters/smartenergy.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zcl/clusters/wwah.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zcl/helpers.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zdo/types.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy/zgp/crypto.py +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy.egg-info/dependency_links.txt +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy.egg-info/requires.txt +0 -0
- {zigpy-2.1.0 → zigpy-2.3.0}/zigpy.egg-info/top_level.txt +0 -0
|
@@ -239,7 +239,6 @@ ignore = [
|
|
|
239
239
|
|
|
240
240
|
[tool.ruff.lint.per-file-ignores]
|
|
241
241
|
"tests/*.py" = [
|
|
242
|
-
"F811", # Redefinition of unused name from line N
|
|
243
242
|
"PIE794", # Class field defined multiple times
|
|
244
243
|
"PLC0206", # Extracting value from dictionary without calling `.items()`
|
|
245
244
|
"PLC0415", # `import` should be at the top-level of a file
|
|
@@ -484,10 +483,10 @@ disable_error_code = [
|
|
|
484
483
|
]
|
|
485
484
|
|
|
486
485
|
[[tool.mypy.overrides]]
|
|
487
|
-
module = "zigpy.zgp.
|
|
486
|
+
module = "zigpy.zgp.commands"
|
|
488
487
|
disable_error_code = [
|
|
489
|
-
"assignment", #
|
|
490
|
-
"attr-defined", #
|
|
488
|
+
"assignment", # 22
|
|
489
|
+
"attr-defined", # 27
|
|
491
490
|
]
|
|
492
491
|
# Autogenerated mypy overrides: end
|
|
493
492
|
|
|
@@ -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()
|
|
@@ -8,7 +8,7 @@ from aiosqlite.context import contextmanager
|
|
|
8
8
|
import pytest
|
|
9
9
|
|
|
10
10
|
from tests.async_mock import AsyncMock, MagicMock, patch
|
|
11
|
-
from tests.conftest import
|
|
11
|
+
from tests.conftest import make_node_desc
|
|
12
12
|
from tests.test_appdb import make_app_with_db
|
|
13
13
|
import zigpy.appdb
|
|
14
14
|
import zigpy.appdb_schemas
|
|
@@ -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
|
|
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=
|
|
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 <
|
|
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 <
|
|
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
|
|
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
|
|
|
@@ -620,7 +620,9 @@ def test_bitstruct_misaligned():
|
|
|
620
620
|
baz: t.uint7_t
|
|
621
621
|
|
|
622
622
|
s = TestStruct(foo=0b1, bar=0b10101010, baz=0b1110111)
|
|
623
|
-
|
|
623
|
+
|
|
624
|
+
# The segment spans two bytes, so the first byte holds the first-declared fields
|
|
625
|
+
assert s.serialize() == bytes([0b0101010_1, 0b1110111_1])
|
|
624
626
|
|
|
625
627
|
s2, remaining = TestStruct.deserialize(s.serialize() + b"asd")
|
|
626
628
|
assert s == s2
|
|
@@ -629,6 +631,108 @@ def test_bitstruct_misaligned():
|
|
|
629
631
|
TestStruct.deserialize(b"\xff")
|
|
630
632
|
|
|
631
633
|
|
|
634
|
+
def test_bitstruct_multi_byte_segment():
|
|
635
|
+
"""A bitfield segment wider than one byte is little-endian."""
|
|
636
|
+
|
|
637
|
+
class TestStruct(t.Struct):
|
|
638
|
+
foo: t.uint3_t
|
|
639
|
+
bar: t.uint1_t
|
|
640
|
+
baz: t.uint2_t
|
|
641
|
+
# This field straddles the byte boundary, so the whole struct is one segment
|
|
642
|
+
qux: t.uint3_t
|
|
643
|
+
quux: t.uint7_t
|
|
644
|
+
|
|
645
|
+
s = TestStruct(foo=0b101, bar=0b1, baz=0b10, qux=0b111, quux=0b1010101)
|
|
646
|
+
value = 0b101 | (0b1 << 3) | (0b10 << 4) | (0b111 << 6) | (0b1010101 << 9)
|
|
647
|
+
|
|
648
|
+
# A segment is laid out exactly like the integer of the same width would be
|
|
649
|
+
assert s.serialize() == t.uint16_t(value).serialize()
|
|
650
|
+
assert TestStruct.deserialize(s.serialize() + b"asd") == (s, b"asd")
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
def test_bitstruct_multi_byte_segment_enums(expose_global):
|
|
654
|
+
"""Sub-byte enums and bitmaps pack like the plain integers they derive from."""
|
|
655
|
+
|
|
656
|
+
@expose_global
|
|
657
|
+
class TestEnum(t.enum3):
|
|
658
|
+
FOO = 0b101
|
|
659
|
+
|
|
660
|
+
@expose_global
|
|
661
|
+
class TestBitmap(t.bitmap6):
|
|
662
|
+
BAR = 0b000010
|
|
663
|
+
BAZ = 0b100000
|
|
664
|
+
|
|
665
|
+
class TestStruct(t.Struct):
|
|
666
|
+
first: TestEnum
|
|
667
|
+
second: t.uint4_t
|
|
668
|
+
# Straddles the byte boundary
|
|
669
|
+
third: TestBitmap
|
|
670
|
+
fourth: t.uint3_t
|
|
671
|
+
|
|
672
|
+
s = TestStruct(
|
|
673
|
+
first=TestEnum.FOO,
|
|
674
|
+
second=0b1001,
|
|
675
|
+
third=TestBitmap.BAR | TestBitmap.BAZ,
|
|
676
|
+
fourth=0b110,
|
|
677
|
+
)
|
|
678
|
+
value = 0b101 | (0b1001 << 3) | (0b100010 << 7) | (0b110 << 13)
|
|
679
|
+
|
|
680
|
+
assert s.serialize() == t.uint16_t(value).serialize()
|
|
681
|
+
assert TestStruct.deserialize(s.serialize() + b"asd") == (s, b"asd")
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
def test_bitstruct_three_byte_segment():
|
|
685
|
+
"""Segments wider than two bytes are little-endian as well."""
|
|
686
|
+
|
|
687
|
+
class TestStruct(t.Struct):
|
|
688
|
+
foo: t.uint7_t
|
|
689
|
+
# Byte-serializable but misaligned, like every field after it
|
|
690
|
+
bar: t.uint8_t
|
|
691
|
+
baz: t.uint4_t
|
|
692
|
+
qux: t.uint5_t
|
|
693
|
+
|
|
694
|
+
s = TestStruct(foo=0b1010101, bar=0b11110000, baz=0b1001, qux=0b11011)
|
|
695
|
+
value = 0b1010101 | (0b11110000 << 7) | (0b1001 << 15) | (0b11011 << 19)
|
|
696
|
+
|
|
697
|
+
assert s.serialize() == t.uint24_t(value).serialize()
|
|
698
|
+
assert TestStruct.deserialize(s.serialize() + b"asd") == (s, b"asd")
|
|
699
|
+
|
|
700
|
+
|
|
701
|
+
def test_bitstruct_gp_commissioning_notification_options() -> None:
|
|
702
|
+
"""The GP commissioning notification options round trip."""
|
|
703
|
+
|
|
704
|
+
class CommissioningNotificationOptions(t.Struct):
|
|
705
|
+
application_id: t.uint3_t
|
|
706
|
+
rx_after_tx: t.uint1_t
|
|
707
|
+
security_level: t.uint2_t
|
|
708
|
+
security_key_type: t.uint3_t
|
|
709
|
+
security_failed: t.uint1_t
|
|
710
|
+
bidirectional_cap: t.uint1_t
|
|
711
|
+
proxy_info_present: t.uint1_t
|
|
712
|
+
_reserved: t.uint4_t
|
|
713
|
+
|
|
714
|
+
options = CommissioningNotificationOptions(
|
|
715
|
+
application_id=0b010,
|
|
716
|
+
rx_after_tx=1,
|
|
717
|
+
security_level=0b11,
|
|
718
|
+
security_key_type=0b111,
|
|
719
|
+
security_failed=1,
|
|
720
|
+
bidirectional_cap=0,
|
|
721
|
+
proxy_info_present=1,
|
|
722
|
+
_reserved=0,
|
|
723
|
+
)
|
|
724
|
+
|
|
725
|
+
value = (
|
|
726
|
+
0b010 | (1 << 3) | (0b11 << 4) | (0b111 << 6) | (1 << 9) | (0 << 10) | (1 << 11)
|
|
727
|
+
)
|
|
728
|
+
assert value == 0x0BFA
|
|
729
|
+
assert options.serialize() == b"\xfa\x0b"
|
|
730
|
+
assert options.serialize() == t.uint16_t(value).serialize()
|
|
731
|
+
assert CommissioningNotificationOptions.deserialize(
|
|
732
|
+
options.serialize() + b"asd"
|
|
733
|
+
) == (options, b"asd")
|
|
734
|
+
|
|
735
|
+
|
|
632
736
|
def test_non_byte_sized_struct():
|
|
633
737
|
class TestStruct(t.Struct):
|
|
634
738
|
foo: t.uint1_t
|
|
@@ -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)
|