From 6c6fc0a58eb34fed159c010d20480d4aea12dbcd Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Tue, 13 Aug 2024 16:56:38 -0400 Subject: [PATCH] Fix up after rebase --- bellows/ezsp/__init__.py | 34 ++++++++++++---------------------- bellows/zigbee/application.py | 10 ++++++++-- tests/test_application.py | 1 - 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/bellows/ezsp/__init__.py b/bellows/ezsp/__init__.py index dcde8937..8ec1180d 100644 --- a/bellows/ezsp/__init__.py +++ b/bellows/ezsp/__init__.py @@ -358,32 +358,22 @@ async def get_board_info( ) -> tuple[str, str, str | None] | tuple[None, None, str | None]: """Return board info.""" - tokens = {} + tokens: dict[t.EzspMfgTokenId, str | None] = {} - for token in (t.EzspMfgTokenId.MFG_STRING, t.EzspMfgTokenId.MFG_BOARD_NAME): - value = await self.get_mfg_token(token) - raw_tokens[token].append(value) + for token_id in (t.EzspMfgTokenId.MFG_STRING, t.EzspMfgTokenId.MFG_BOARD_NAME): + value = await self.get_mfg_token(token_id) - # Try to parse them - tokens: dict[t.EzspMfgTokenId, str] = {} + # Tokens are fixed-length and initially filled with \xFF but also can end + # with \x00 + while value.endswith((b"\xFF", b"\x00")): + value = value.rstrip(b"\xFF").rstrip(b"\x00") - for token_id, values in raw_tokens.items(): - for value in values: - # Tokens are fixed-length and initially filled with \xFF but also can end - # with \x00 - while value.endswith((b"\xFF", b"\x00")): - value = value.rstrip(b"\xFF").rstrip(b"\x00") - - try: - result = value.decode("utf-8") - except UnicodeDecodeError: - result = "0x" + value.hex().upper() + try: + result = value.decode("utf-8") + except UnicodeDecodeError: + result = "0x" + value.hex().upper() - if result: - tokens[token_id] = result - break - else: - tokens[token_id] = None + tokens[token_id] = result or None (status, ver_info_bytes) = await self.getValue( valueId=t.EzspValueId.VALUE_VERSION_INFO diff --git a/bellows/zigbee/application.py b/bellows/zigbee/application.py index 43e21a22..adefb5f0 100644 --- a/bellows/zigbee/application.py +++ b/bellows/zigbee/application.py @@ -677,7 +677,7 @@ async def _reset_mfg_id(self, mfg_id: int) -> None: """Resets manufacturer id if was temporary overridden by a joining device.""" await self._ezsp.setManufacturerCode(code=mfg_id) await asyncio.sleep(MFG_ID_RESET_DELAY) - await self._ezsp.setManufacturerCode(DEFAULT_MFG_ID) + await self._ezsp.setManufacturerCode(code=DEFAULT_MFG_ID) async def energy_scan( self, channels: t.Channels, duration_exp: int, count: int @@ -762,7 +762,13 @@ async def send_packet(self, packet: zigpy.types.ZigbeePacket) -> None: ) if packet.source_route is not None: - if FirmwareFeatures.MANUAL_SOURCE_ROUTE in self._ezsp._xncp_features and self.config[CONF_BELLOWS_CONFIG][CONF_MANUAL_SOURCE_ROUTING]: + if ( + FirmwareFeatures.MANUAL_SOURCE_ROUTE + in self._ezsp._xncp_features + and self.config[CONF_BELLOWS_CONFIG][ + CONF_MANUAL_SOURCE_ROUTING + ] + ): await self._ezsp.xncp_set_manual_source_route( nwk=packet.dst.address, relays=packet.source_route, diff --git a/tests/test_application.py b/tests/test_application.py index 8a005bca..1e8cc264 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -15,7 +15,6 @@ import bellows.config as config from bellows.exception import ControllerError, EzspError import bellows.ezsp as ezsp -from bellows.ezsp.custom_commands import FirmwareFeatures from bellows.ezsp.v9.commands import GetTokenDataRsp from bellows.ezsp.xncp import FirmwareFeatures import bellows.types