Skip to content

Commit 9e31738

Browse files
authored
Fix fallback logic when starting up with an unsupported EZSP version (#705)
* Fix config writing when an EZSP protocol version is not explicitly supported * Add a test
1 parent 5cd6678 commit 9e31738

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

bellows/ezsp/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,8 @@ async def write_config(self, config: dict) -> None:
639639
ezsp_config = {}
640640
ezsp_values = {}
641641

642-
for cfg in DEFAULT_CONFIG[self._ezsp_version]:
642+
# If a protocol version is not explicitly supported, use config for the latest
643+
for cfg in DEFAULT_CONFIG.get(self._ezsp_version, DEFAULT_CONFIG[EZSP_LATEST]):
643644
if isinstance(cfg, RuntimeConfig):
644645
ezsp_config[cfg.config_id.name] = dataclasses.replace(
645646
cfg, config_id=t.EzspConfigId[cfg.config_id.name]

tests/test_ezsp.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,32 @@ async def test_cfg_initialize_skip():
951951
)
952952

953953

954+
@pytest.mark.parametrize("unsupported_version", [15, 18, 99])
955+
async def test_unsupported_ezsp_version_startup(unsupported_version: int, caplog):
956+
"""Test that startup works with an unsupported EZSP version."""
957+
ezsp = make_ezsp(version=unsupported_version)
958+
959+
with patch("bellows.uart.connect"):
960+
await ezsp.connect()
961+
962+
# The EZSP version should be stored as the unsupported version
963+
assert ezsp._ezsp_version == unsupported_version
964+
965+
# But the protocol should fall back to the latest
966+
assert ezsp._protocol.VERSION == EZSP_LATEST
967+
968+
assert f"Protocol version {unsupported_version} is not supported" in caplog.text
969+
970+
ezsp.getConfigurationValue = AsyncMock(return_value=(t.EzspStatus.SUCCESS, 0))
971+
ezsp.setConfigurationValue = AsyncMock(return_value=(t.EzspStatus.SUCCESS,))
972+
ezsp.setValue = AsyncMock(return_value=(t.EzspStatus.SUCCESS,))
973+
ezsp.getValue = AsyncMock(return_value=(t.EzspStatus.SUCCESS, b"\xFF"))
974+
975+
# Startup should not fail
976+
await ezsp.write_config({})
977+
assert len(ezsp.setConfigurationValue.mock_calls) > 0
978+
979+
954980
async def test_reset_custom_eui64(ezsp_f):
955981
"""Test resetting custom EUI64."""
956982
# No NV3 interface

0 commit comments

Comments
 (0)