Skip to content

Commit

Permalink
Merge pull request #128 from puddly/rc
Browse files Browse the repository at this point in the history
0.16.0 Release
  • Loading branch information
puddly authored Oct 3, 2022
2 parents 81cff21 + 93f588a commit b2e2b9d
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 185 deletions.
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:
version: 3.7
version: 3.8
- name: Install wheel
run: >-
pip install wheel
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
author="Russell Cloran",
author_email="rcloran@gmail.com",
license="GPL-3.0",
packages=find_packages(exclude=["*.tests"]),
install_requires=["pyserial-asyncio", "zigpy>=0.47.0"],
packages=find_packages(exclude=["tests", "tests.*"]),
install_requires=["zigpy>=0.51.0"],
tests_require=["pytest", "asynctest", "pytest-asyncio"],
)
88 changes: 49 additions & 39 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,18 @@ async def test_broadcast(app):
assert app._api._command.call_args[0][9] == data

app._api._command.return_value = xbee_t.TXStatus.ADDRESS_NOT_FOUND
r = await app.broadcast(profile, cluster, src_ep, dst_ep, grpid, radius, tsn, data)
assert r[0] != xbee_t.TXStatus.SUCCESS

with pytest.raises(zigpy.exceptions.DeliveryError):
r = await app.broadcast(
profile, cluster, src_ep, dst_ep, grpid, radius, tsn, data
)

app._api._command.side_effect = asyncio.TimeoutError
r = await app.broadcast(profile, cluster, src_ep, dst_ep, grpid, radius, tsn, data)
assert r[0] != xbee_t.TXStatus.SUCCESS

with pytest.raises(zigpy.exceptions.DeliveryError):
r = await app.broadcast(
profile, cluster, src_ep, dst_ep, grpid, radius, tsn, data
)


async def test_get_association_state(app):
Expand All @@ -242,6 +248,14 @@ async def test_form_network(app):
async def mock_at_command(cmd, *args):
if cmd == "MY":
return 0x0000
if cmd == "OI":
return 0x1234
elif cmd == "ID":
return 0x1234567812345678
elif cmd == "SL":
return 0x11223344
elif cmd == "SH":
return 0x55667788
elif cmd == "WR":
app._api.coordinator_started_event.set()
elif cmd == "CE" and legacy_module:
Expand Down Expand Up @@ -393,25 +407,13 @@ async def test_permit(app):


async def _test_request(
app,
expect_reply=True,
send_success=True,
send_timeout=False,
is_end_device=True,
node_desc=True,
**kwargs
app, expect_reply=True, send_success=True, send_timeout=False, **kwargs
):
seq = 123
nwk = 0x2345
ieee = t.EUI64(b"\x01\x02\x03\x04\x05\x06\x07\x08")
dev = app.add_device(ieee, nwk)

if node_desc:
dev.node_desc = mock.MagicMock()
dev.node_desc.is_end_device = is_end_device
else:
dev.node_desc = None

def _mock_command(
cmdname, ieee, nwk, src_ep, dst_ep, cluster, profile, radius, options, data
):
Expand All @@ -437,42 +439,34 @@ def _mock_command(
)


async def test_request_with_reply(app):
r = await _test_request(app, expect_reply=True, send_success=True)
async def test_request_with_ieee(app):
r = await _test_request(app, use_ieee=True, send_success=True)
assert r[0] == 0


async def test_request_without_node_desc(app):
r = await _test_request(app, expect_reply=True, send_success=True, node_desc=False)
async def test_request_with_reply(app):
r = await _test_request(app, expect_reply=True, send_success=True)
assert r[0] == 0


async def test_request_send_timeout(app):
r = await _test_request(app, send_timeout=True)
assert r[0] != 0
with pytest.raises(zigpy.exceptions.DeliveryError):
await _test_request(app, send_timeout=True)


async def test_request_send_fail(app):
r = await _test_request(app, send_success=False)
assert r[0] != 0
with pytest.raises(zigpy.exceptions.DeliveryError):
await _test_request(app, send_success=False)


async def test_request_extended_timeout(app):
is_end_device = False
r = await _test_request(app, True, True, is_end_device=is_end_device)
r = await _test_request(app, True, True, extended_timeout=False)
assert r[0] == xbee_t.TXStatus.SUCCESS
assert app._api._command.call_count == 1
assert app._api._command.call_args[0][8] & 0x40 == 0x00
app._api._command.reset_mock()

r = await _test_request(app, True, True, node_desc=False)
assert r[0] == xbee_t.TXStatus.SUCCESS
assert app._api._command.call_count == 1
assert app._api._command.call_args[0][8] & 0x40 == 0x40
app._api._command.reset_mock()

is_end_device = True
r = await _test_request(app, True, True, is_end_device=is_end_device)
r = await _test_request(app, True, True, extended_timeout=True)
assert r[0] == xbee_t.TXStatus.SUCCESS
assert app._api._command.call_count == 1
assert app._api._command.call_args[0][8] & 0x40 == 0x40
Expand Down Expand Up @@ -570,10 +564,26 @@ async def test_mrequest_with_reply(app):


async def test_mrequest_send_timeout(app):
r = await _test_mrequest(app, send_timeout=True)
assert r[0] != 0
with pytest.raises(zigpy.exceptions.DeliveryError):
await _test_mrequest(app, send_timeout=True)


async def test_mrequest_send_fail(app):
r = await _test_mrequest(app, send_success=False)
assert r[0] != 0
with pytest.raises(zigpy.exceptions.DeliveryError):
await _test_mrequest(app, send_success=False)


async def test_reset_network_info(app):
async def mock_at_command(cmd, *args):
if cmd == "NR":
return 0x00

return None

app._api._at_command = mock.MagicMock(
spec=XBee._at_command, side_effect=mock_at_command
)

await app.reset_network_info()

app._api._at_command.assert_called_once_with("NR", 0)
2 changes: 1 addition & 1 deletion zigpy_xbee/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MAJOR_VERSION = 0
MINOR_VERSION = 15
MINOR_VERSION = 16
PATCH_VERSION = "0"
__short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}"
__version__ = f"{__short_version__}.{PATCH_VERSION}"
8 changes: 8 additions & 0 deletions zigpy_xbee/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,11 @@ class DiscoveryStatus(uint8_t, UndefinedEnum):
ADDRESS_AND_ROUTE = 0x03
EXTENDED_TIMEOUT = 0x40
_UNDEFINED = 0x00


class TXOptions(zigpy.types.bitmap8):
NONE = 0x00

Disable_Retries_and_Route_Repair = 0x01
Enable_APS_Encryption = 0x20
Use_Extended_TX_Timeout = 0x40
7 changes: 2 additions & 5 deletions zigpy_xbee/uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import logging
from typing import Any, Dict

import serial
import serial_asyncio
import zigpy.serial

from zigpy_xbee.config import CONF_DEVICE_BAUDRATE, CONF_DEVICE_PATH

Expand Down Expand Up @@ -169,13 +168,11 @@ async def connect(device_config: Dict[str, Any], api, loop=None) -> Gateway:
connected_future = asyncio.Future()
protocol = Gateway(api, connected_future)

transport, protocol = await serial_asyncio.create_serial_connection(
transport, protocol = await zigpy.serial.create_serial_connection(
loop,
lambda: protocol,
url=device_config[CONF_DEVICE_PATH],
baudrate=device_config[CONF_DEVICE_BAUDRATE],
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
xonxoff=False,
)

Expand Down
Loading

0 comments on commit b2e2b9d

Please sign in to comment.