From acd2aa5331f3fb10fae6328f57a005b807e0182a Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Sat, 7 Dec 2024 15:23:19 -0500 Subject: [PATCH] Disable XNCP `MEMBER_OF_ALL_GROUPS` on current firmwares (#658) * Disable XNCP group feature for now * Add a unit test --- bellows/ezsp/__init__.py | 10 ++++++++- tests/test_xncp.py | 45 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/bellows/ezsp/__init__.py b/bellows/ezsp/__init__.py index 2991e77a..8b9763a2 100644 --- a/bellows/ezsp/__init__.py +++ b/bellows/ezsp/__init__.py @@ -179,13 +179,21 @@ async def version(self): ver, ) - async def get_xncp_features(self) -> None: + async def get_xncp_features(self) -> xncp.FirmwareFeatures: try: self._xncp_features = await self.xncp_get_supported_firmware_features() except InvalidCommandError: self._xncp_features = xncp.FirmwareFeatures.NONE + # Disable the XNCP feature flag, it doesn't seem to work correctly + if FirmwareFeatures.MEMBER_OF_ALL_GROUPS in self._xncp_features: + _, _, version = await self.get_board_info() + + if version == "7.4.4.0 build 0": + self._xncp_features &= ~FirmwareFeatures.MEMBER_OF_ALL_GROUPS + LOGGER.debug("XNCP features: %s", self._xncp_features) + return self._xncp_features async def disconnect(self): self.stop_ezsp() diff --git a/tests/test_xncp.py b/tests/test_xncp.py index 23aa846c..ab337107 100644 --- a/tests/test_xncp.py +++ b/tests/test_xncp.py @@ -1,6 +1,6 @@ from __future__ import annotations -from unittest.mock import AsyncMock, call +from unittest.mock import AsyncMock, call, patch import pytest @@ -181,3 +181,46 @@ async def test_xncp_get_flow_control_type(ezsp_f: EZSP) -> None: assert customFrame.mock_calls == [ call(xncp.XncpCommand.from_payload(xncp.GetFlowControlTypeReq()).serialize()) ] + + +async def test_xncp_get_xncp_features_fixes(ezsp_f: EZSP) -> None: + """Test XNCP `get_xncp_features`, with fixes.""" + ezsp_f._mock_commands["customFrame"] = customFrame = AsyncMock( + return_value=[ + t.EmberStatus.SUCCESS, + xncp.XncpCommand.from_payload( + xncp.GetSupportedFeaturesRsp( + features=( + xncp.FirmwareFeatures.MANUAL_SOURCE_ROUTE + | xncp.FirmwareFeatures.MEMBER_OF_ALL_GROUPS + ) + ) + ).serialize(), + ] + ) + + # In 7.4.4.0, it's broken + with patch.object( + ezsp_f, + "get_board_info", + return_value=("Model", "Manufacturer", "7.4.4.0 build 0"), + ): + assert ( + await ezsp_f.get_xncp_features() + ) == xncp.FirmwareFeatures.MANUAL_SOURCE_ROUTE + + # In a hypothetical new release, it's not + with patch.object( + ezsp_f, + "get_board_info", + return_value=("Model", "Manufacturer", "7.4.4.0 build 1"), + ): + assert (await ezsp_f.get_xncp_features()) == ( + xncp.FirmwareFeatures.MANUAL_SOURCE_ROUTE + | xncp.FirmwareFeatures.MEMBER_OF_ALL_GROUPS + ) + + assert customFrame.mock_calls == [ + call(xncp.XncpCommand.from_payload(xncp.GetSupportedFeaturesReq()).serialize()), + call(xncp.XncpCommand.from_payload(xncp.GetSupportedFeaturesReq()).serialize()), + ]