Skip to content

Implement new zigpy packet API #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.8, 3.9, "3.10"]
steps:
- name: Check out code from GitHub
uses: actions/checkout@v2
Expand Down Expand Up @@ -224,7 +224,7 @@ jobs:
needs: prepare-base
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.8, 3.9, "3.10"]
name: >-
Run tests Python ${{ matrix.python-version }}
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python 3.7
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.7
python-version: 3.8
- name: Install wheel
run: >-
pip install wheel
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ Below are the defaults with the top-level Home Assistant `zha:` key.
zha:
zigpy_config:
znp_config:
# "auto" picks the largest value that keeps the device's transmit buffer from getting full
max_concurrent_requests: auto

# Only if your stick has a built-in power amplifier (i.e. CC1352P and CC2592)
# If set, must be between:
# * CC1352/2652: -22 and 19
Expand Down
4 changes: 1 addition & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ license = GPL-3.0
packages = find:
python_requires = >=3.7
install_requires =
pyserial-asyncio; platform_system!="Windows"
pyserial-asyncio!=0.5; platform_system=="Windows" # 0.5 broke writes
zigpy>=0.50.0
zigpy>=0.51.0
async_timeout
voluptuous
coloredlogs
Expand Down
104 changes: 0 additions & 104 deletions tests/application/test_joining.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,107 +333,3 @@ async def test_on_zdo_device_join_and_announce_slow(device, make_application, mo
assert app.handle_join.call_count == 2

await app.shutdown()


@pytest.mark.parametrize("device", FORMED_DEVICES)
async def test_unknown_device_discovery(device, make_application, mocker):
app, znp_server = await make_application(server_cls=device)
await app.startup(auto_form=False)

mocker.spy(app, "handle_join")

# Existing devices do not need to be discovered
existing_nwk = 0x1234
existing_ieee = t.EUI64(range(8))
device = app.add_initialized_device(ieee=existing_ieee, nwk=existing_nwk)

assert (await app._get_or_discover_device(nwk=existing_nwk)) is device
assert app.handle_join.call_count == 0

# If the device changes its NWK but doesn't tell zigpy, it will be re-discovered
did_ieee_addr_req1 = znp_server.reply_once_to(
request=c.ZDO.IEEEAddrReq.Req(
NWK=existing_nwk + 1,
RequestType=c.zdo.AddrRequestType.SINGLE,
StartIndex=0,
),
responses=[
c.ZDO.IEEEAddrReq.Rsp(Status=t.Status.SUCCESS),
c.ZDO.IEEEAddrRsp.Callback(
Status=t.ZDOStatus.SUCCESS,
IEEE=existing_ieee,
NWK=existing_nwk + 1,
NumAssoc=0,
Index=0,
Devices=[],
),
],
)

# The same device is discovered and its NWK was updated. Handles concurrency.
devices = await asyncio.gather(
app._get_or_discover_device(nwk=existing_nwk + 1),
app._get_or_discover_device(nwk=existing_nwk + 1),
app._get_or_discover_device(nwk=existing_nwk + 1),
app._get_or_discover_device(nwk=existing_nwk + 1),
app._get_or_discover_device(nwk=existing_nwk + 1),
)

assert devices == [device] * 5

# Only a single request is sent, since the coroutines are grouped
await did_ieee_addr_req1
assert device.nwk == existing_nwk + 1
assert app.handle_join.call_count == 1

# If a completely unknown device joins the network, it will be treated as a new join
new_nwk = 0x5678
new_ieee = t.EUI64(range(1, 9))

did_ieee_addr_req2 = znp_server.reply_once_to(
request=c.ZDO.IEEEAddrReq.Req(
NWK=new_nwk,
RequestType=c.zdo.AddrRequestType.SINGLE,
StartIndex=0,
),
responses=[
c.ZDO.IEEEAddrReq.Rsp(Status=t.Status.SUCCESS),
c.ZDO.IEEEAddrRsp.Callback(
Status=t.ZDOStatus.SUCCESS,
IEEE=new_ieee,
NWK=new_nwk,
NumAssoc=0,
Index=0,
Devices=[],
),
],
)

new_dev = await app._get_or_discover_device(nwk=new_nwk)
await did_ieee_addr_req2
assert app.handle_join.call_count == 2
assert new_dev.nwk == new_nwk
assert new_dev.ieee == new_ieee

await app.shutdown()


@pytest.mark.parametrize("device", FORMED_DEVICES)
async def test_unknown_device_discovery_failure(device, make_application, mocker):
mocker.patch("zigpy_znp.zigbee.application.IEEE_ADDR_DISCOVERY_TIMEOUT", new=0.1)

app, znp_server = await make_application(server_cls=device)
await app.startup(auto_form=False)

znp_server.reply_once_to(
request=c.ZDO.IEEEAddrReq.Req(partial=True),
responses=[
c.ZDO.IEEEAddrReq.Rsp(Status=t.Status.SUCCESS),
],
)

# Discovery will throw an exception when the device cannot be found
with pytest.raises(KeyError):
await app._get_or_discover_device(nwk=0x3456)

await app.shutdown()
Loading