Skip to content
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
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

from setuptools import find_packages, setup

import zigpy_xbee.const as xbee_const
import zigpy_xbee

setup(
name="zigpy-xbee-homeassistant",
version=xbee_const.__version__,
version=zigpy_xbee.__version__,
description="A library which communicates with XBee radios for zigpy",
url="http://github.com/zigpy/zigpy-xbee",
author="Russell Cloran",
Expand All @@ -15,7 +15,7 @@
packages=find_packages(exclude=['*.tests']),
install_requires=[
'pyserial-asyncio',
'zigpy-homeassistant',
'zigpy-homeassistant >= 0.3.3',
],
tests_require=[
'pytest',
Expand Down
32 changes: 30 additions & 2 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@

from zigpy.exceptions import DeliveryError
from zigpy.types import EUI64, uint16_t
from zigpy.zdo.types import LogicalType

from zigpy_xbee.api import ModemStatus, XBee
from zigpy_xbee.zigbee import application


@pytest.fixture
def app(monkeypatch, database_file=None):
monkeypatch.setattr(application, 'TIMEOUT_TX_STATUS', 0.1)
monkeypatch.setattr(application, 'TIMEOUT_REPLY', 0.1)
monkeypatch.setattr(application, 'TIMEOUT_REPLY_EXTENDED', 0.1)
return application.ControllerApplication(XBee(),
database_file=database_file)

Expand Down Expand Up @@ -438,11 +442,14 @@ async def test_permit(app):


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

def _mock_command(cmdname, ieee, nwk, src_ep, dst_ep, cluster,
profile, radius, options, data):
Expand Down Expand Up @@ -490,6 +497,27 @@ async def test_request_send_fail(app):
await _test_request(app, False, True, send_success=False, tries=2, timeout=0.1)


@pytest.mark.asyncio
async def test_request_extended_timeout(app):
lt = LogicalType.Router
assert await _test_request(app, True, True, logical_type=lt) == mock.sentinel.reply_result
assert app._api._command.call_count == 1
assert app._api._command.call_args[0][8] & 0x40 == 0x00
app._api._command.reset_mock()

lt = None
assert await _test_request(app, True, True, logical_type=lt) == mock.sentinel.reply_result
assert app._api._command.call_count == 1
assert app._api._command.call_args[0][8] & 0x40 == 0x40
app._api._command.reset_mock()

lt = LogicalType.EndDevice
assert await _test_request(app, True, True, logical_type=lt) == mock.sentinel.reply_result
assert app._api._command.call_count == 1
assert app._api._command.call_args[0][8] & 0x40 == 0x40
app._api._command.reset_mock()


def _handle_reply(app, tsn):
app.handle_message = mock.MagicMock()
return app._handle_reply(
Expand Down
6 changes: 0 additions & 6 deletions tests/test_const.py

This file was deleted.

5 changes: 5 additions & 0 deletions zigpy_xbee/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MAJOR_VERSION = 0
MINOR_VERSION = 2
PATCH_VERSION = '1'
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
6 changes: 0 additions & 6 deletions zigpy_xbee/const.py

This file was deleted.

17 changes: 13 additions & 4 deletions zigpy_xbee/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import zigpy.exceptions
import zigpy.types
import zigpy.util
import zigpy.zdo.types
from zigpy.zdo.types import LogicalType

from zigpy_xbee.types import UNKNOWN_IEEE

Expand All @@ -16,6 +16,8 @@
# end device poll timeout = 3 * SN * SP * 10ms
CONF_POLL_TIMEOUT = 0x029b
TIMEOUT_TX_STATUS = 120
TIMEOUT_REPLY = 5
TIMEOUT_REPLY_EXTENDED = 28


LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -119,14 +121,21 @@ async def _get_association_state(self):
return state

@zigpy.util.retryable_request
async def request(self, nwk, profile, cluster, src_ep, dst_ep, sequence, data, expect_reply=True, timeout=10):
async def request(self, nwk, profile, cluster, src_ep, dst_ep, sequence,
data, expect_reply=True, timeout=TIMEOUT_REPLY):
LOGGER.debug("Zigbee request seq %s", sequence)
assert sequence not in self._pending
if expect_reply:
reply_fut = asyncio.Future()
self._pending[sequence] = reply_fut

dev = self.get_device(nwk=nwk)
if dev.node_desc.logical_type in (LogicalType.EndDevice, None):
tx_opts = 0x60
rx_timeout = TIMEOUT_REPLY_EXTENDED
else:
tx_opts = 0x20
rx_timeout = timeout
send_req = self._api.tx_explicit(
dev.ieee,
nwk,
Expand All @@ -135,7 +144,7 @@ async def request(self, nwk, profile, cluster, src_ep, dst_ep, sequence, data, e
cluster,
profile,
0,
0x20,
tx_opts,
data,
)

Expand All @@ -151,7 +160,7 @@ async def request(self, nwk, profile, cluster, src_ep, dst_ep, sequence, data, e
cluster))
if expect_reply:
try:
return await asyncio.wait_for(reply_fut, timeout)
return await asyncio.wait_for(reply_fut, rx_timeout)
except asyncio.TimeoutError as ex:
LOGGER.debug("[0x%04x:%s:0x%04x]: no reply: %s",
nwk, dst_ep, cluster, ex)
Expand Down