Skip to content

Commit

Permalink
Disable XNCP MEMBER_OF_ALL_GROUPS on current firmwares (#658)
Browse files Browse the repository at this point in the history
* Disable XNCP group feature for now

* Add a unit test
  • Loading branch information
puddly authored Dec 7, 2024
1 parent a81bbd4 commit acd2aa5
Show file tree
Hide file tree
Showing 2 changed files with 53 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 @@ -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()
Expand Down
45 changes: 44 additions & 1 deletion tests/test_xncp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from unittest.mock import AsyncMock, call
from unittest.mock import AsyncMock, call, patch

import pytest

Expand Down Expand Up @@ -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()),
]

0 comments on commit acd2aa5

Please sign in to comment.