Skip to content

Commit c01bab0

Browse files
authored
Merge pull request #45 from zigpy/dev
0.2.1
2 parents d49f85d + c8ba64e commit c01bab0

File tree

6 files changed

+51
-21
lines changed

6 files changed

+51
-21
lines changed

setup.py

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

33
from setuptools import find_packages, setup
44

5-
import zigpy_xbee.const as xbee_const
5+
import zigpy_xbee
66

77
setup(
88
name="zigpy-xbee-homeassistant",
9-
version=xbee_const.__version__,
9+
version=zigpy_xbee.__version__,
1010
description="A library which communicates with XBee radios for zigpy",
1111
url="http://github.com/zigpy/zigpy-xbee",
1212
author="Russell Cloran",
@@ -15,7 +15,7 @@
1515
packages=find_packages(exclude=['*.tests']),
1616
install_requires=[
1717
'pyserial-asyncio',
18-
'zigpy-homeassistant',
18+
'zigpy-homeassistant >= 0.3.3',
1919
],
2020
tests_require=[
2121
'pytest',

tests/test_application.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55

66
from zigpy.exceptions import DeliveryError
77
from zigpy.types import EUI64, uint16_t
8+
from zigpy.zdo.types import LogicalType
9+
810
from zigpy_xbee.api import ModemStatus, XBee
911
from zigpy_xbee.zigbee import application
1012

1113

1214
@pytest.fixture
1315
def app(monkeypatch, database_file=None):
1416
monkeypatch.setattr(application, 'TIMEOUT_TX_STATUS', 0.1)
17+
monkeypatch.setattr(application, 'TIMEOUT_REPLY', 0.1)
18+
monkeypatch.setattr(application, 'TIMEOUT_REPLY_EXTENDED', 0.1)
1519
return application.ControllerApplication(XBee(),
1620
database_file=database_file)
1721

@@ -438,11 +442,14 @@ async def test_permit(app):
438442

439443

440444
async def _test_request(app, do_reply=True, expect_reply=True,
441-
send_success=True, send_timeout=False, **kwargs):
445+
send_success=True, send_timeout=False,
446+
logical_type=None, **kwargs):
442447
seq = 123
443448
nwk = 0x2345
444449
ieee = EUI64(b'\x01\x02\x03\x04\x05\x06\x07\x08')
445-
app.add_device(ieee, nwk)
450+
dev = app.add_device(ieee, nwk)
451+
dev.node_desc = mock.MagicMock()
452+
dev.node_desc.logical_type = logical_type
446453

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

492499

500+
@pytest.mark.asyncio
501+
async def test_request_extended_timeout(app):
502+
lt = LogicalType.Router
503+
assert await _test_request(app, True, True, logical_type=lt) == mock.sentinel.reply_result
504+
assert app._api._command.call_count == 1
505+
assert app._api._command.call_args[0][8] & 0x40 == 0x00
506+
app._api._command.reset_mock()
507+
508+
lt = None
509+
assert await _test_request(app, True, True, logical_type=lt) == mock.sentinel.reply_result
510+
assert app._api._command.call_count == 1
511+
assert app._api._command.call_args[0][8] & 0x40 == 0x40
512+
app._api._command.reset_mock()
513+
514+
lt = LogicalType.EndDevice
515+
assert await _test_request(app, True, True, logical_type=lt) == mock.sentinel.reply_result
516+
assert app._api._command.call_count == 1
517+
assert app._api._command.call_args[0][8] & 0x40 == 0x40
518+
app._api._command.reset_mock()
519+
520+
493521
def _handle_reply(app, tsn):
494522
app.handle_message = mock.MagicMock()
495523
return app._handle_reply(

tests/test_const.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

zigpy_xbee/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
MAJOR_VERSION = 0
2+
MINOR_VERSION = 2
3+
PATCH_VERSION = '1'
4+
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
5+
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)

zigpy_xbee/const.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

zigpy_xbee/zigbee/application.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import zigpy.exceptions
77
import zigpy.types
88
import zigpy.util
9-
import zigpy.zdo.types
9+
from zigpy.zdo.types import LogicalType
1010

1111
from zigpy_xbee.types import UNKNOWN_IEEE
1212

@@ -16,6 +16,8 @@
1616
# end device poll timeout = 3 * SN * SP * 10ms
1717
CONF_POLL_TIMEOUT = 0x029b
1818
TIMEOUT_TX_STATUS = 120
19+
TIMEOUT_REPLY = 5
20+
TIMEOUT_REPLY_EXTENDED = 28
1921

2022

2123
LOGGER = logging.getLogger(__name__)
@@ -119,14 +121,21 @@ async def _get_association_state(self):
119121
return state
120122

121123
@zigpy.util.retryable_request
122-
async def request(self, nwk, profile, cluster, src_ep, dst_ep, sequence, data, expect_reply=True, timeout=10):
124+
async def request(self, nwk, profile, cluster, src_ep, dst_ep, sequence,
125+
data, expect_reply=True, timeout=TIMEOUT_REPLY):
123126
LOGGER.debug("Zigbee request seq %s", sequence)
124127
assert sequence not in self._pending
125128
if expect_reply:
126129
reply_fut = asyncio.Future()
127130
self._pending[sequence] = reply_fut
128131

129132
dev = self.get_device(nwk=nwk)
133+
if dev.node_desc.logical_type in (LogicalType.EndDevice, None):
134+
tx_opts = 0x60
135+
rx_timeout = TIMEOUT_REPLY_EXTENDED
136+
else:
137+
tx_opts = 0x20
138+
rx_timeout = timeout
130139
send_req = self._api.tx_explicit(
131140
dev.ieee,
132141
nwk,
@@ -135,7 +144,7 @@ async def request(self, nwk, profile, cluster, src_ep, dst_ep, sequence, data, e
135144
cluster,
136145
profile,
137146
0,
138-
0x20,
147+
tx_opts,
139148
data,
140149
)
141150

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

0 commit comments

Comments
 (0)