From 5d7a6c5ec56c60a3d91a52c27265050bb440237b Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Tue, 28 Mar 2023 18:18:56 -0400 Subject: [PATCH 1/5] Triple the energy scan results so that the maximum is 255 --- zigpy_deconz/zigbee/application.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/zigpy_deconz/zigbee/application.py b/zigpy_deconz/zigbee/application.py index 9379b35..ff789f4 100644 --- a/zigpy_deconz/zigbee/application.py +++ b/zigpy_deconz/zigbee/application.py @@ -332,6 +332,14 @@ async def force_remove(self, dev): """Forcibly remove device from NCP.""" pass + async def energy_scan( + self, channels: t.Channels.ALL_CHANNELS, duration_exp: int, count: int + ) -> dict[int, float]: + results = await super().energy_scan(channels=channels, duration_exp=duration_exp, count=count) + + # The Conbee seems to max out at an LQI of 85, which is exactly 255/3 + return {c: v * 3 for c, v in results.items()} + async def add_endpoint(self, descriptor: zdo_t.SimpleDescriptor) -> None: """Register an endpoint on the device, replacing any with conflicting IDs.""" From d13ba8e228963404561d548fb1c1b76a4c6dc749 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Tue, 28 Mar 2023 18:19:05 -0400 Subject: [PATCH 2/5] Bump pre-commit deps to fix CI --- .pre-commit-config.yaml | 8 ++++---- zigpy_deconz/zigbee/application.py | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5b16775..f5bdfe2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 23.1.0 hooks: - id: black args: @@ -8,7 +8,7 @@ repos: - --quiet - repo: https://github.com/pycqa/flake8 - rev: 3.8.4 + rev: 6.0.0 hooks: - id: flake8 additional_dependencies: @@ -16,12 +16,12 @@ repos: - pydocstyle==5.1.1 - repo: https://github.com/PyCQA/isort - rev: 5.10.1 + rev: 5.12.0 hooks: - id: isort - repo: https://github.com/codespell-project/codespell - rev: v1.17.1 + rev: v2.2.4 hooks: - id: codespell args: diff --git a/zigpy_deconz/zigbee/application.py b/zigpy_deconz/zigbee/application.py index ff789f4..b4c7211 100644 --- a/zigpy_deconz/zigbee/application.py +++ b/zigpy_deconz/zigbee/application.py @@ -335,7 +335,9 @@ async def force_remove(self, dev): async def energy_scan( self, channels: t.Channels.ALL_CHANNELS, duration_exp: int, count: int ) -> dict[int, float]: - results = await super().energy_scan(channels=channels, duration_exp=duration_exp, count=count) + results = await super().energy_scan( + channels=channels, duration_exp=duration_exp, count=count + ) # The Conbee seems to max out at an LQI of 85, which is exactly 255/3 return {c: v * 3 for c, v in results.items()} From 5f3e66a6b249931f4efe0b03af38227d9bc782a1 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Wed, 29 Mar 2023 22:01:17 -0400 Subject: [PATCH 3/5] Bump minimum zigpy version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 3856070..5363f17 100644 --- a/setup.py +++ b/setup.py @@ -21,6 +21,6 @@ author_email="schmidt.d@aon.at", license="GPL-3.0", packages=find_packages(exclude=["tests"]), - install_requires=["zigpy>=0.52.1"], + install_requires=["zigpy>=0.54.0"], tests_require=["pytest", "asynctest"], ) From 1b788a63dec39839715351fc81c632948d337454 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Wed, 29 Mar 2023 22:07:09 -0400 Subject: [PATCH 4/5] In CI, ensure pre-commit stage uses same version as base stage --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a7c571..d920974 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: env: CACHE_VERSION: 1 - DEFAULT_PYTHON: 3.8 + DEFAULT_PYTHON: 3.8.16 PRE_COMMIT_HOME: ~/.cache/pre-commit jobs: @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.8.14', '3.9.15', '3.10.8', '3.11.0'] + python-version: ['3.8.16', '3.9.15', '3.10.8', '3.11.0'] steps: - name: Check out code from GitHub uses: actions/checkout@v2 From aeb9eda6423b94a95144edc0854c5ba4fbcf08c4 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Wed, 29 Mar 2023 22:24:45 -0400 Subject: [PATCH 5/5] Add a unit test --- tests/test_application.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/test_application.py b/tests/test_application.py index e3c6267..d7ca6f6 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -2,11 +2,13 @@ import asyncio import logging +from unittest import mock import pytest +import zigpy.application import zigpy.config import zigpy.device -from zigpy.types import EUI64 +from zigpy.types import EUI64, Channels import zigpy.zdo.types as zdo_t from zigpy_deconz import types as t @@ -569,3 +571,16 @@ async def test_reset_network_info(app): await app.reset_network_info() app.form_network.assert_called_once() + + +async def test_energy_scan(app): + with mock.patch.object( + zigpy.application.ControllerApplication, + "energy_scan", + return_value={c: c for c in Channels.ALL_CHANNELS}, + ): + results = await app.energy_scan( + channels=Channels.ALL_CHANNELS, duration_exp=0, count=1 + ) + + assert results == {c: c * 3 for c in Channels.ALL_CHANNELS}