diff --git a/bellows/__init__.py b/bellows/__init__.py index 62768259..085b76d9 100644 --- a/bellows/__init__.py +++ b/bellows/__init__.py @@ -1,5 +1,5 @@ MAJOR_VERSION = 0 MINOR_VERSION = 35 -PATCH_VERSION = "3" +PATCH_VERSION = "4" __short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}" __version__ = f"{__short_version__}.{PATCH_VERSION}" diff --git a/bellows/ezsp/config.py b/bellows/ezsp/config.py index 992f0ee3..19ba2f29 100644 --- a/bellows/ezsp/config.py +++ b/bellows/ezsp/config.py @@ -14,16 +14,7 @@ class RuntimeConfig: minimum: bool = False -DEFAULT_CONFIG = [ - RuntimeConfig( - config_id=types_v4.EzspConfigId.CONFIG_SOURCE_ROUTE_TABLE_SIZE, - value=200, - minimum=True, - ), - RuntimeConfig( - config_id=types_v4.EzspConfigId.CONFIG_END_DEVICE_POLL_TIMEOUT, - value=8, - ), +DEFAULT_CONFIG_COMMON = [ RuntimeConfig( config_id=types_v4.EzspConfigId.CONFIG_INDIRECT_TRANSMISSION_TIMEOUT, value=7680, @@ -56,14 +47,20 @@ class RuntimeConfig: value=16, minimum=True, ), - RuntimeConfig( - config_id=types_v6.EzspConfigId.CONFIG_TC_REJOINS_USING_WELL_KNOWN_KEY_TIMEOUT_S, - value=90, - ), RuntimeConfig( config_id=types_v4.EzspConfigId.CONFIG_PAN_ID_CONFLICT_REPORT_THRESHOLD, value=2, ), + RuntimeConfig( + config_id=types_v4.EzspConfigId.CONFIG_KEY_TABLE_SIZE, + value=4, + minimum=True, + ), + RuntimeConfig( + config_id=types_v4.EzspConfigId.CONFIG_MAX_END_DEVICE_CHILDREN, + value=32, + minimum=True, + ), RuntimeConfig( config_id=types_v4.EzspConfigId.CONFIG_APPLICATION_ZDO_FLAGS, value=( @@ -74,3 +71,49 @@ class RuntimeConfig: # Must be set last RuntimeConfig(types_v4.EzspConfigId.CONFIG_PACKET_BUFFER_COUNT, value=0xFF), ] + +DEFAULT_CONFIG_LEGACY = [ + RuntimeConfig( + config_id=types_v4.EzspConfigId.CONFIG_SOURCE_ROUTE_TABLE_SIZE, + value=16, + minimum=True, + ), + RuntimeConfig( + config_id=types_v4.EzspConfigId.CONFIG_END_DEVICE_POLL_TIMEOUT, + value=60, + ), + RuntimeConfig( + config_id=types_v4.EzspConfigId.CONFIG_END_DEVICE_POLL_TIMEOUT_SHIFT, + value=8, + ), +] + DEFAULT_CONFIG_COMMON + + +DEFAULT_CONFIG_NEW = [ + RuntimeConfig( + config_id=types_v6.EzspConfigId.CONFIG_SOURCE_ROUTE_TABLE_SIZE, + value=200, + minimum=True, + ), + RuntimeConfig( + config_id=types_v6.EzspConfigId.CONFIG_END_DEVICE_POLL_TIMEOUT, + value=8, + ), + RuntimeConfig( + config_id=( + types_v6.EzspConfigId.CONFIG_TC_REJOINS_USING_WELL_KNOWN_KEY_TIMEOUT_S + ), + value=90, + ), +] + DEFAULT_CONFIG_COMMON + + +DEFAULT_CONFIG = { + 4: DEFAULT_CONFIG_LEGACY, + 5: DEFAULT_CONFIG_LEGACY, + 6: DEFAULT_CONFIG_LEGACY, + 7: DEFAULT_CONFIG_NEW, + 8: DEFAULT_CONFIG_NEW, + 9: DEFAULT_CONFIG_NEW, + 10: DEFAULT_CONFIG_NEW, +} diff --git a/bellows/ezsp/protocol.py b/bellows/ezsp/protocol.py index 24644f6e..20360731 100644 --- a/bellows/ezsp/protocol.py +++ b/bellows/ezsp/protocol.py @@ -71,15 +71,11 @@ async def initialize(self, zigpy_config: Dict) -> None: # Not all config will be present in every EZSP version so only use valid keys ezsp_config = {} - for cfg in DEFAULT_CONFIG: - try: - config_id = self.types.EzspConfigId[cfg.config_id.name] - except KeyError: - pass - else: - ezsp_config[cfg.config_id.name] = dataclasses.replace( - cfg, config_id=config_id - ) + for cfg in DEFAULT_CONFIG[self.EZSP_VERSION]: + config_id = self.types.EzspConfigId[cfg.config_id.name] + ezsp_config[cfg.config_id.name] = dataclasses.replace( + cfg, config_id=config_id + ) # Override the defaults with user-specified values (or `None` for deletions) for name, value in self.SCHEMAS[CONF_EZSP_CONFIG]( diff --git a/tests/test_ezsp_protocol.py b/tests/test_ezsp_protocol.py index 6535324e..2d353ac9 100644 --- a/tests/test_ezsp_protocol.py +++ b/tests/test_ezsp_protocol.py @@ -6,7 +6,7 @@ import bellows.ezsp.v4 import bellows.ezsp.v4.types as t -from .async_mock import ANY, AsyncMock, MagicMock, patch +from .async_mock import ANY, AsyncMock, MagicMock, call, patch class _DummyProtocolHandler(bellows.ezsp.v4.EZSPv4): @@ -93,6 +93,40 @@ async def test_cfg_initialize(prot_hndl, caplog): assert "Couldn't set" in caplog.text +async def test_config_initialize_husbzb1(prot_hndl): + """Test timeouts are properly set for HUSBZB-1.""" + + prot_hndl.getConfigurationValue = AsyncMock(return_value=(t.EzspStatus.SUCCESS, 0)) + prot_hndl.setConfigurationValue = AsyncMock(return_value=(t.EzspStatus.SUCCESS,)) + + await prot_hndl.initialize({"ezsp_config": {}}) + prot_hndl.setConfigurationValue.assert_has_calls( + [ + call(t.EzspConfigId.CONFIG_SOURCE_ROUTE_TABLE_SIZE, 16), + call(t.EzspConfigId.CONFIG_END_DEVICE_POLL_TIMEOUT, 60), + call(t.EzspConfigId.CONFIG_END_DEVICE_POLL_TIMEOUT_SHIFT, 8), + call(t.EzspConfigId.CONFIG_INDIRECT_TRANSMISSION_TIMEOUT, 7680), + call(t.EzspConfigId.CONFIG_STACK_PROFILE, 2), + call(t.EzspConfigId.CONFIG_SUPPORTED_NETWORKS, 1), + call(t.EzspConfigId.CONFIG_MULTICAST_TABLE_SIZE, 16), + call(t.EzspConfigId.CONFIG_TRUST_CENTER_ADDRESS_CACHE_SIZE, 2), + call(t.EzspConfigId.CONFIG_SECURITY_LEVEL, 5), + call(t.EzspConfigId.CONFIG_ADDRESS_TABLE_SIZE, 16), + call(t.EzspConfigId.CONFIG_PAN_ID_CONFLICT_REPORT_THRESHOLD, 2), + call(t.EzspConfigId.CONFIG_KEY_TABLE_SIZE, 4), + call(t.EzspConfigId.CONFIG_MAX_END_DEVICE_CHILDREN, 32), + call( + t.EzspConfigId.CONFIG_APPLICATION_ZDO_FLAGS, + ( + t.EmberZdoConfigurationFlags.APP_HANDLES_UNSUPPORTED_ZDO_REQUESTS + | t.EmberZdoConfigurationFlags.APP_RECEIVES_SUPPORTED_ZDO_REQUESTS + ), + ), + call(t.EzspConfigId.CONFIG_PACKET_BUFFER_COUNT, 255), + ] + ) + + async def test_cfg_initialize_skip(prot_hndl): """Test initialization."""