Skip to content

Commit

Permalink
Handle empty EUI64 manufacturing tokens (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly authored Jun 30, 2023
1 parent a7173ca commit cb3d4f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion bellows/ezsp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ async def _get_nv3_restored_eui64_key(self) -> t.NV3KeyId | None:
async def _get_mfg_custom_eui_64(self) -> t.EmberEUI64 | None:
"""Get the custom EUI 64 manufacturing token, if it has a valid value."""
(data,) = await self.getMfgToken(t.EzspMfgTokenId.MFG_CUSTOM_EUI_64)

# Manufacturing tokens do not exist in RCP firmware: all reads are empty
if not data:
raise EzspError("Firmware does not support MFG_CUSTOM_EUI_64 token")

mfg_custom_eui64, _ = t.EmberEUI64.deserialize(data)

if mfg_custom_eui64 == t.EmberEUI64.convert("FF:FF:FF:FF:FF:FF:FF:FF"):
Expand All @@ -406,7 +411,10 @@ async def _get_mfg_custom_eui_64(self) -> t.EmberEUI64 | None:

async def can_burn_userdata_custom_eui64(self) -> bool:
"""Checks if the device EUI64 can be burned into USERDATA."""
return await self._get_mfg_custom_eui_64() is None
try:
return await self._get_mfg_custom_eui_64() is None
except EzspError:
return False

async def can_rewrite_custom_eui64(self) -> bool:
"""Checks if the device EUI64 can be written any number of times."""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ezsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ async def _mock_cmd(*args, **kwargs):

@pytest.mark.parametrize(
"value, expected_result",
[(b"\xFF" * 8, True), (bytes.fromhex("0846b8a11c004b1200"), False)],
[(b"\xFF" * 8, True), (bytes.fromhex("0846b8a11c004b1200"), False), (b"", False)],
)
async def test_can_burn_userdata_custom_eui64(ezsp_f, value, expected_result):
"""Test detecting if a custom EUI64 has been written."""
Expand Down

0 comments on commit cb3d4f8

Please sign in to comment.