From cb3d4f8cc9c36cdb9fbe6723beeee59929680282 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Thu, 29 Jun 2023 22:15:57 -0400 Subject: [PATCH] Handle empty EUI64 manufacturing tokens (#570) --- bellows/ezsp/__init__.py | 10 +++++++++- tests/test_ezsp.py | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bellows/ezsp/__init__.py b/bellows/ezsp/__init__.py index d042f97a..4b53fdad 100644 --- a/bellows/ezsp/__init__.py +++ b/bellows/ezsp/__init__.py @@ -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"): @@ -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.""" diff --git a/tests/test_ezsp.py b/tests/test_ezsp.py index b5f03e00..22820c96 100644 --- a/tests/test_ezsp.py +++ b/tests/test_ezsp.py @@ -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."""