Skip to content

Commit

Permalink
Fix up after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed Aug 13, 2024
1 parent 7f85c8f commit 6c6fc0a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
34 changes: 12 additions & 22 deletions bellows/ezsp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions bellows/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6c6fc0a

Please sign in to comment.