Skip to content

Commit e8037c4

Browse files
authored
Merge pull request #218 from puddly/rc
0.20.0 Release
2 parents 05a5023 + b934680 commit e8037c4

File tree

6 files changed

+64
-27
lines changed

6 files changed

+64
-27
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
env:
99
CACHE_VERSION: 1
10-
DEFAULT_PYTHON: 3.8
10+
DEFAULT_PYTHON: 3.8.16
1111
PRE_COMMIT_HOME: ~/.cache/pre-commit
1212

1313
jobs:
@@ -18,7 +18,7 @@ jobs:
1818
runs-on: ubuntu-latest
1919
strategy:
2020
matrix:
21-
python-version: ['3.8.14', '3.9.15', '3.10.8', '3.11.0']
21+
python-version: ['3.8.16', '3.9.15', '3.10.8', '3.11.0']
2222
steps:
2323
- name: Check out code from GitHub
2424
uses: actions/checkout@v2
@@ -271,7 +271,7 @@ jobs:
271271
needs: prepare-base
272272
strategy:
273273
matrix:
274-
python-version: ['3.8.14', '3.9.15', '3.10.8', '3.11.0']
274+
python-version: ['3.8.16', '3.9.15', '3.10.8', '3.11.0']
275275
name: >-
276276
Run tests Python ${{ matrix.python-version }}
277277
steps:
@@ -311,7 +311,7 @@ jobs:
311311
. venv/bin/activate
312312
pytest \
313313
-qq \
314-
--timeout=9 \
314+
--timeout=15 \
315315
--durations=10 \
316316
--cov zigpy_deconz \
317317
--cov-report=term-missing \

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: 22.3.0
3+
rev: 23.1.0
44
hooks:
55
- id: black
66
args:
77
- --safe
88
- --quiet
99

1010
- repo: https://github.com/pycqa/flake8
11-
rev: 3.8.4
11+
rev: 6.0.0
1212
hooks:
1313
- id: flake8
1414
additional_dependencies:
1515
- flake8-docstrings==1.5.0
1616
- pydocstyle==5.1.1
1717

1818
- repo: https://github.com/PyCQA/isort
19-
rev: 5.10.1
19+
rev: 5.12.0
2020
hooks:
2121
- id: isort
2222

2323
- repo: https://github.com/codespell-project/codespell
24-
rev: v1.17.1
24+
rev: v2.2.4
2525
hooks:
2626
- id: codespell
2727
args:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
author_email="schmidt.d@aon.at",
2222
license="GPL-3.0",
2323
packages=find_packages(exclude=["tests"]),
24-
install_requires=["zigpy>=0.52.1"],
24+
install_requires=["zigpy>=0.54.0"],
2525
tests_require=["pytest", "asynctest"],
2626
)

tests/test_application.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
import asyncio
44
import logging
5+
from unittest import mock
56

67
import pytest
8+
import zigpy.application
79
import zigpy.config
810
import zigpy.device
9-
from zigpy.types import EUI64
11+
from zigpy.types import EUI64, Channels
1012
import zigpy.zdo.types as zdo_t
1113

1214
from zigpy_deconz import types as t
@@ -110,28 +112,32 @@ def addr_nwk_and_ieee(nwk, ieee):
110112
return addr
111113

112114

115+
@patch("zigpy_deconz.zigbee.application.CHANGE_NETWORK_WAIT", 0.001)
113116
@pytest.mark.parametrize(
114-
"proto_ver, nwk_state, error",
117+
"proto_ver, target_state, returned_state",
115118
[
116-
(0x0107, deconz_api.NetworkState.CONNECTED, None),
117-
(0x0106, deconz_api.NetworkState.CONNECTED, None),
118-
(0x0107, deconz_api.NetworkState.OFFLINE, None),
119-
(0x0107, deconz_api.NetworkState.OFFLINE, asyncio.TimeoutError()),
119+
(0x0107, deconz_api.NetworkState.CONNECTED, deconz_api.NetworkState.CONNECTED),
120+
(0x0106, deconz_api.NetworkState.CONNECTED, deconz_api.NetworkState.CONNECTED),
121+
(0x0107, deconz_api.NetworkState.OFFLINE, deconz_api.NetworkState.CONNECTED),
122+
(0x0107, deconz_api.NetworkState.CONNECTED, deconz_api.NetworkState.OFFLINE),
120123
],
121124
)
122-
async def test_start_network(app, proto_ver, nwk_state, error):
125+
async def test_start_network(app, proto_ver, target_state, returned_state):
123126
app.load_network_info = AsyncMock()
124127
app.restore_neighbours = AsyncMock()
125128
app.add_endpoint = AsyncMock()
126-
app._change_network_state = AsyncMock(side_effect=error)
127129

128130
app._api.device_state = AsyncMock(
129-
return_value=(deconz_api.DeviceState(nwk_state), 0, 0)
131+
return_value=(deconz_api.DeviceState(returned_state), 0, 0)
130132
)
133+
131134
app._api._proto_ver = proto_ver
132135
app._api.protocol_version = proto_ver
133136

134-
if nwk_state != deconz_api.NetworkState.CONNECTED and error is not None:
137+
if (
138+
target_state == deconz_api.NetworkState.CONNECTED
139+
and returned_state != deconz_api.NetworkState.CONNECTED
140+
):
135141
with pytest.raises(zigpy.exceptions.FormationFailure):
136142
await app.start_network()
137143

@@ -569,3 +575,16 @@ async def test_reset_network_info(app):
569575
await app.reset_network_info()
570576

571577
app.form_network.assert_called_once()
578+
579+
580+
async def test_energy_scan(app):
581+
with mock.patch.object(
582+
zigpy.application.ControllerApplication,
583+
"energy_scan",
584+
return_value={c: c for c in Channels.ALL_CHANNELS},
585+
):
586+
results = await app.energy_scan(
587+
channels=Channels.ALL_CHANNELS, duration_exp=0, count=1
588+
)
589+
590+
assert results == {c: c * 3 for c in Channels.ALL_CHANNELS}

zigpy_deconz/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# coding: utf-8
44
MAJOR_VERSION = 0
5-
MINOR_VERSION = 19
6-
PATCH_VERSION = "2"
5+
MINOR_VERSION = 20
6+
PATCH_VERSION = "0"
77
__short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}"
88
__version__ = f"{__short_version__}.{PATCH_VERSION}"

zigpy_deconz/zigbee/application.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,7 @@ async def permit_with_key(self, node: t.EUI64, code: bytes, time_s=60):
111111
async def start_network(self):
112112
await self.register_endpoints()
113113
await self.load_network_info(load_devices=False)
114-
115-
try:
116-
await self._change_network_state(NetworkState.CONNECTED)
117-
except asyncio.TimeoutError as e:
118-
raise FormationFailure() from e
114+
await self._change_network_state(NetworkState.CONNECTED)
119115

120116
coordinator = await DeconzDevice.new(
121117
self,
@@ -141,7 +137,19 @@ async def change_loop():
141137
await asyncio.sleep(CHANGE_NETWORK_WAIT)
142138

143139
await self._api.change_network_state(target_state)
144-
await asyncio.wait_for(change_loop(), timeout=timeout)
140+
141+
try:
142+
await asyncio.wait_for(change_loop(), timeout=timeout)
143+
except asyncio.TimeoutError:
144+
if target_state != NetworkState.CONNECTED:
145+
raise
146+
147+
raise FormationFailure(
148+
"Network formation refused: there is likely too much RF interference."
149+
" Make sure your coordinator is on a USB 2.0 extension cable and"
150+
" away from any sources of interference, like USB 3.0 ports, SSDs,"
151+
" 2.4GHz routers, motherboards, etc."
152+
)
145153

146154
if self._api.protocol_version < PROTO_VER_WATCHDOG:
147155
return
@@ -332,6 +340,16 @@ async def force_remove(self, dev):
332340
"""Forcibly remove device from NCP."""
333341
pass
334342

343+
async def energy_scan(
344+
self, channels: t.Channels.ALL_CHANNELS, duration_exp: int, count: int
345+
) -> dict[int, float]:
346+
results = await super().energy_scan(
347+
channels=channels, duration_exp=duration_exp, count=count
348+
)
349+
350+
# The Conbee seems to max out at an LQI of 85, which is exactly 255/3
351+
return {c: v * 3 for c, v in results.items()}
352+
335353
async def add_endpoint(self, descriptor: zdo_t.SimpleDescriptor) -> None:
336354
"""Register an endpoint on the device, replacing any with conflicting IDs."""
337355

0 commit comments

Comments
 (0)