Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable XNCP MEMBER_OF_ALL_GROUPS on current firmwares #658

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()),
]
Loading