Skip to content

Commit ab46574

Browse files
authored
Implement the new zigpy radio API (#117)
* Begin implementing the new radio API * Use the correct signature for `load_network_info` * Use command and response IDs * Parse ZiGate logging messages * Implement `Status` type * Erase PDM when writing new settings * Handle responses and status callbacks in any order * Implement `GET_DEVICES_LIST` * Rename `ADDRESS_MODE` to `AddressMode` * Initialize the ZiGate device on startup * Only permit joins via the coordinator in `permit_ncp` * Use `schedule_initialize` to prevent double initialization * Add unhandled `NODE_DESCRIPTOR_RSP` response * Add a stub for `add_endpoint` * Set the TCLK's partner IEEE * Set the network information `source` and `metadata` * Fix unit tests * Bump minimum required zigpy version to 0.47.0
1 parent efc0c3c commit ab46574

File tree

7 files changed

+554
-215
lines changed

7 files changed

+554
-215
lines changed

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def is_raspberry_pi(raise_on_errors=False):
5353
'pyserial-asyncio>=0.5; platform_system!="Windows"',
5454
'pyserial-asyncio!=0.5; platform_system=="Windows"', # 0.5 broke writesv
5555
'pyusb>=1.1.0',
56-
'zigpy>=0.22.2',
56+
'zigpy>=0.47.0',
5757
]
5858

5959
if is_raspberry_pi():

Diff for: tests/test_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ async def test_probe_fail(mock_connect, mock_raw_mode, exception):
103103

104104

105105
@pytest.mark.asyncio
106-
@patch.object(asyncio, "wait_for", side_effect=asyncio.TimeoutError)
106+
@patch.object(asyncio, "wait", return_value=([], []))
107107
async def test_api_command(mock_command, api):
108108
"""Test command method."""
109109
try:

Diff for: tests/test_application.py

+34-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55
import zigpy.types as zigpy_types
6+
import zigpy.exceptions
67

78
import zigpy_zigate.config as config
89
import zigpy_zigate.types as t
@@ -31,7 +32,7 @@ def test_zigpy_ieee(app):
3132
data = b"\x01\x02\x03\x04\x05\x06\x07\x08"
3233

3334
zigate_ieee, _ = t.EUI64.deserialize(data)
34-
app._ieee = zigpy_types.EUI64(zigate_ieee)
35+
app.state.node_info.ieee = zigpy_types.EUI64(zigate_ieee)
3536

3637
dst_addr = app.get_dst_address(cluster)
3738
assert dst_addr.serialize() == b"\x03" + data[::-1] + b"\x01"
@@ -44,28 +45,54 @@ def test_model_detection(app):
4445

4546
@pytest.mark.asyncio
4647
async def test_form_network_success(app):
48+
app._api.erase_persistent_data = AsyncMock()
4749
app._api.set_channel = AsyncMock()
50+
app._api.set_extended_panid = AsyncMock()
4851
app._api.reset = AsyncMock()
52+
4953
async def mock_start_network():
5054
return [[0x00, 0x1234, 0x0123456789abcdef], 0]
5155
app._api.start_network = mock_start_network
56+
57+
async def mock_get_network_state():
58+
return [
59+
[
60+
0x0000,
61+
t.EUI64([0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0x01]),
62+
0x1234,
63+
0x1234abcdef012345,
64+
0x11,
65+
],
66+
0,
67+
]
68+
69+
app._api.get_network_state = mock_get_network_state
70+
5271
await app.form_network()
53-
assert app._nwk == 0x1234
54-
assert app._ieee == 0x0123456789abcdef
72+
await app.load_network_info()
73+
assert app.state.node_info.nwk == 0x0000
74+
assert app.state.node_info.ieee == zigpy.types.EUI64.convert(
75+
"01:23:45:67:89:ab:cd:ef"
76+
)
77+
assert app.state.network_info.pan_id == 0x1234
78+
assert app.state.network_info.extended_pan_id == zigpy.types.ExtendedPanId.convert(
79+
"12:34:ab:cd:ef:01:23:45"
80+
)
5581
assert app._api.reset.call_count == 0
5682

5783

5884
@pytest.mark.asyncio
5985
async def test_form_network_failed(app):
86+
app._api.erase_persistent_data = AsyncMock()
6087
app._api.set_channel = AsyncMock()
88+
app._api.set_extended_panid = AsyncMock()
6189
app._api.reset = AsyncMock()
6290
async def mock_start_network():
6391
return [[0x06], 0]
6492
app._api.start_network = mock_start_network
6593
async def mock_get_network_state():
6694
return [[0xffff, 0x0123456789abcdef, 0x1234, 0, 0x11], 0]
6795
app._api.get_network_state = mock_get_network_state
68-
await app.form_network()
69-
assert app._nwk == 0
70-
assert app._ieee == 0
71-
assert app._api.reset.call_count == 1
96+
97+
with pytest.raises(zigpy.exceptions.FormationFailure):
98+
await app.form_network()

Diff for: tests/test_types.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def test_deserialize():
2323
assert result[2] == 0x0001
2424
assert result[3] == 0x01
2525
assert result[4] == 0x01
26-
assert result[5] == t.Address(address_mode=t.ADDRESS_MODE.NWK, address=t.NWK(0x1234))
27-
assert result[6] == t.Address(address_mode=t.ADDRESS_MODE.NWK, address=t.NWK(0xabcd))
26+
assert result[5] == t.Address(address_mode=t.AddressMode.NWK, address=t.NWK(0x1234))
27+
assert result[6] == t.Address(address_mode=t.AddressMode.NWK, address=t.NWK(0xabcd))
2828
assert result[7] == b'\x01\x00\xBE\xEF'
2929
assert rest == b''
3030

@@ -34,7 +34,7 @@ def test_deserialize():
3434
assert result[0] == 0x00
3535
assert result[1] == 0x01
3636
assert result[2] == 0x01
37-
assert result[3] == t.Address(address_mode=t.ADDRESS_MODE.NWK, address=t.NWK(0x1234))
37+
assert result[3] == t.Address(address_mode=t.AddressMode.NWK, address=t.NWK(0x1234))
3838
assert result[4] == 0xff
3939

4040
data = b'\x00\x01\x01\x03\x12\x34\x56\x78\x9a\xbc\xde\xf0\xff'
@@ -43,7 +43,7 @@ def test_deserialize():
4343
assert result[0] == 0x00
4444
assert result[1] == 0x01
4545
assert result[2] == 0x01
46-
assert result[3] == t.Address(address_mode=t.ADDRESS_MODE.IEEE,
46+
assert result[3] == t.Address(address_mode=t.AddressMode.IEEE,
4747
address=t.EUI64.deserialize(b'\x12\x34\x56\x78\x9a\xbc\xde\xf0')[0])
4848
assert result[4] == 0xff
4949

@@ -73,7 +73,7 @@ def test_deserialize():
7373
assert result[0] == 0x00
7474
assert result[1] == 0x01
7575
assert result[2] == 0x01
76-
assert result[3] == t.Address(address_mode=t.ADDRESS_MODE.NWK,
76+
assert result[3] == t.Address(address_mode=t.AddressMode.NWK,
7777
address=t.NWK.deserialize(b'\xbc\x8c')[0])
7878
assert result[4] == 0x73
7979
assert len(result) == 5

0 commit comments

Comments
 (0)