From daa58d048b857313779a3b7e2db47af875939d4e Mon Sep 17 00:00:00 2001 From: Alexei Chetroi Date: Tue, 15 Oct 2019 20:32:15 -0400 Subject: [PATCH 1/3] Refactor EUI64 class. (#55) * Refactor EUI64 class. * Update tests. --- setup.py | 2 +- tests/test_application.py | 6 +++--- tests/test_types.py | 4 ++-- zigpy_xbee/types.py | 2 +- zigpy_xbee/zigbee/application.py | 12 +++++++----- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/setup.py b/setup.py index b3bd9a8..afaa407 100644 --- a/setup.py +++ b/setup.py @@ -13,6 +13,6 @@ author_email="rcloran@gmail.com", license="GPL-3.0", packages=find_packages(exclude=["*.tests"]), - install_requires=["pyserial-asyncio", "zigpy-homeassistant >= 0.9.0"], + install_requires=["pyserial-asyncio", "zigpy-homeassistant >= 0.10.0"], tests_require=["pytest"], ) diff --git a/tests/test_application.py b/tests/test_application.py index 32ac829..d6e3917 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -91,7 +91,7 @@ def test_rx_unknown_device(app, device): app.devices[dev.ieee] = dev app.get_device = mock.MagicMock(side_effect=[KeyError, dev]) app.handle_rx( - b"\x01\x02\x03\x04\x05\x06\x07\x08", + b"\x08\x07\x06\x05\x04\x03\x02\x01", 0x3334, mock.sentinel.src_ep, mock.sentinel.dst_ep, @@ -300,8 +300,8 @@ async def _at_command_mock(cmd, *args): "NJ": mock.sentinel.at_nj, "OI": mock.sentinel.at_oi, "OP": mock.sentinel.at_op, - "SH": 0x01020304, - "SL": 0x05060708, + "SH": 0x08070605, + "SL": 0x04030201, "ZS": zs, }.get(cmd, None) diff --git a/tests/test_types.py b/tests/test_types.py index dc97ca8..e8dac42 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -11,7 +11,7 @@ def test_deserialize(): assert rest == extra assert result[0] == 0xFF assert result[1] == -2 - assert result[2] == t.EUI64((0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37)) + assert result[2] == t.EUI64((0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30)) def test_serialize(): @@ -19,7 +19,7 @@ def test_serialize(): schema = (t.uint8_t, t.int16s, t.EUI64) result = t.serialize(data, schema) - assert result == b"\xff\xff\xfe01234567" + assert result == b"\xff\xff\xfe76543210" def test_bytes_serialize(): diff --git a/zigpy_xbee/types.py b/zigpy_xbee/types.py index 077b7c8..956f01a 100644 --- a/zigpy_xbee/types.py +++ b/zigpy_xbee/types.py @@ -127,7 +127,7 @@ def deserialize(cls, data): def serialize(self): assert self._length == len(self) - return b"".join([i.serialize() for i in self]) + return super().serialize()[::-1] class UndefinedEnumMeta(enum.EnumMeta): diff --git a/zigpy_xbee/zigbee/application.py b/zigpy_xbee/zigbee/application.py index 1a6e8c5..6f620d0 100644 --- a/zigpy_xbee/zigbee/application.py +++ b/zigpy_xbee/zigbee/application.py @@ -11,7 +11,7 @@ from zigpy.zcl.clusters.general import Groups from zigpy.zdo.types import NodeDescriptor, ZDOCmd -from zigpy_xbee.types import TXStatus, UNKNOWN_IEEE, UNKNOWN_NWK +from zigpy_xbee.types import EUI64, TXStatus, UNKNOWN_IEEE, UNKNOWN_NWK # how long coordinator would hold message for an end device in 10ms units @@ -54,8 +54,10 @@ async def startup(self, auto_form=False): serial_high = await self._api._at_command("SH") serial_low = await self._api._at_command("SL") - as_bytes = serial_high.to_bytes(4, "big") + serial_low.to_bytes(4, "big") - self._ieee = zigpy.types.EUI64([zigpy.types.uint8_t(b) for b in as_bytes]) + ieee = EUI64.deserialize( + serial_high.to_bytes(4, "big") + serial_low.to_bytes(4, "big") + )[0] + self._ieee = zigpy.types.EUI64(ieee) LOGGER.debug("Read local IEEE address as %s", self._ieee) association_state = await self._get_association_state() @@ -277,10 +279,10 @@ async def broadcast( LOGGER.debug("Broadcast request seq %s", sequence) broadcast_as_bytes = [ - zigpy.types.uint8_t(b) for b in broadcast_address.to_bytes(8, "big") + zigpy.types.uint8_t(b) for b in broadcast_address.to_bytes(8, "little") ] request = self._api.tx_explicit( - zigpy.types.EUI64(broadcast_as_bytes), + EUI64(broadcast_as_bytes), broadcast_address, src_ep, dst_ep, From da6ba3bd736a7d40e348c315d43023a299063365 Mon Sep 17 00:00:00 2001 From: Alexei Chetroi Date: Tue, 15 Oct 2019 20:33:35 -0400 Subject: [PATCH 2/3] 0.6.0.dev0 version bump. --- zigpy_xbee/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zigpy_xbee/__init__.py b/zigpy_xbee/__init__.py index 7aac292..67b478c 100644 --- a/zigpy_xbee/__init__.py +++ b/zigpy_xbee/__init__.py @@ -1,5 +1,5 @@ MAJOR_VERSION = 0 -MINOR_VERSION = 5 -PATCH_VERSION = "0a3" +MINOR_VERSION = 6 +PATCH_VERSION = "0.dev0" __short_version__ = "{}.{}".format(MAJOR_VERSION, MINOR_VERSION) __version__ = "{}.{}".format(__short_version__, PATCH_VERSION) From 45ced8de0dba006918523978f7bd78e26fcc224d Mon Sep 17 00:00:00 2001 From: Alexei Chetroi Date: Tue, 15 Oct 2019 20:35:10 -0400 Subject: [PATCH 3/3] 0.6.0 Release. --- zigpy_xbee/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zigpy_xbee/__init__.py b/zigpy_xbee/__init__.py index 67b478c..4d28505 100644 --- a/zigpy_xbee/__init__.py +++ b/zigpy_xbee/__init__.py @@ -1,5 +1,5 @@ MAJOR_VERSION = 0 MINOR_VERSION = 6 -PATCH_VERSION = "0.dev0" +PATCH_VERSION = "0" __short_version__ = "{}.{}".format(MAJOR_VERSION, MINOR_VERSION) __version__ = "{}.{}".format(__short_version__, PATCH_VERSION)