From 7ca2b64ef75c297d181f7753105d0cdc2ef0ad14 Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Thu, 13 Jun 2024 17:32:24 -0400 Subject: [PATCH 1/2] Remove all table size config for new adapters --- bellows/ezsp/config.py | 65 +++++++++++++++++++----------------------- tests/test_ezsp.py | 16 +++++------ 2 files changed, 38 insertions(+), 43 deletions(-) diff --git a/bellows/ezsp/config.py b/bellows/ezsp/config.py index 052e12e2..17357b03 100644 --- a/bellows/ezsp/config.py +++ b/bellows/ezsp/config.py @@ -31,39 +31,14 @@ class ValueConfig: config_id=types_v4.EzspConfigId.CONFIG_STACK_PROFILE, value=2, ), - RuntimeConfig( - config_id=types_v4.EzspConfigId.CONFIG_SUPPORTED_NETWORKS, - value=1, - minimum=True, - ), - RuntimeConfig( - config_id=types_v4.EzspConfigId.CONFIG_MULTICAST_TABLE_SIZE, - value=16, - minimum=True, - ), - RuntimeConfig( - config_id=types_v4.EzspConfigId.CONFIG_TRUST_CENTER_ADDRESS_CACHE_SIZE, - value=2, - minimum=True, - ), RuntimeConfig( config_id=types_v4.EzspConfigId.CONFIG_SECURITY_LEVEL, value=5, ), - RuntimeConfig( - config_id=types_v4.EzspConfigId.CONFIG_ADDRESS_TABLE_SIZE, - value=16, - minimum=True, - ), 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, @@ -76,11 +51,9 @@ class ValueConfig: | t.EmberZdoConfigurationFlags.APP_HANDLES_UNSUPPORTED_ZDO_REQUESTS ), ), - # Must be set last - RuntimeConfig(types_v4.EzspConfigId.CONFIG_PACKET_BUFFER_COUNT, value=0xFF), ] -DEFAULT_CONFIG_LEGACY = [ +DEFAULT_CONFIG_LEGACY = DEFAULT_CONFIG_COMMON + [ RuntimeConfig( config_id=types_v4.EzspConfigId.CONFIG_SOURCE_ROUTE_TABLE_SIZE, value=16, @@ -94,15 +67,37 @@ class ValueConfig: 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, + config_id=types_v4.EzspConfigId.CONFIG_SUPPORTED_NETWORKS, + value=1, + minimum=True, + ), + RuntimeConfig( + config_id=types_v4.EzspConfigId.CONFIG_MULTICAST_TABLE_SIZE, + value=16, + minimum=True, + ), + RuntimeConfig( + config_id=types_v4.EzspConfigId.CONFIG_TRUST_CENTER_ADDRESS_CACHE_SIZE, + value=2, + minimum=True, + ), + RuntimeConfig( + config_id=types_v4.EzspConfigId.CONFIG_ADDRESS_TABLE_SIZE, + value=16, + minimum=True, + ), + RuntimeConfig( + config_id=types_v4.EzspConfigId.CONFIG_KEY_TABLE_SIZE, + value=4, minimum=True, ), + # Must be set last + RuntimeConfig(types_v4.EzspConfigId.CONFIG_PACKET_BUFFER_COUNT, value=0xFF), +] + + +DEFAULT_CONFIG_NEW = DEFAULT_CONFIG_COMMON + [ RuntimeConfig( config_id=types_v6.EzspConfigId.CONFIG_END_DEVICE_POLL_TIMEOUT, value=8, @@ -117,7 +112,7 @@ class ValueConfig: value_id=types_v7.EzspValueId.VALUE_FORCE_TX_AFTER_FAILED_CCA_ATTEMPTS, value=t.uint8_t(1), ), -] + DEFAULT_CONFIG_COMMON +] DEFAULT_CONFIG = { diff --git a/tests/test_ezsp.py b/tests/test_ezsp.py index 0773a138..f6368ab1 100644 --- a/tests/test_ezsp.py +++ b/tests/test_ezsp.py @@ -735,18 +735,10 @@ async def test_config_initialize_husbzb1(ezsp_f): ezsp_f.networkState = AsyncMock(return_value=(t.EmberNetworkStatus.JOINED_NETWORK,)) expected_calls = [ - call(v4_t.EzspConfigId.CONFIG_SOURCE_ROUTE_TABLE_SIZE, 16), - call(v4_t.EzspConfigId.CONFIG_END_DEVICE_POLL_TIMEOUT, 60), - call(v4_t.EzspConfigId.CONFIG_END_DEVICE_POLL_TIMEOUT_SHIFT, 8), call(v4_t.EzspConfigId.CONFIG_INDIRECT_TRANSMISSION_TIMEOUT, 7680), call(v4_t.EzspConfigId.CONFIG_STACK_PROFILE, 2), - call(v4_t.EzspConfigId.CONFIG_SUPPORTED_NETWORKS, 1), - call(v4_t.EzspConfigId.CONFIG_MULTICAST_TABLE_SIZE, 16), - call(v4_t.EzspConfigId.CONFIG_TRUST_CENTER_ADDRESS_CACHE_SIZE, 2), call(v4_t.EzspConfigId.CONFIG_SECURITY_LEVEL, 5), - call(v4_t.EzspConfigId.CONFIG_ADDRESS_TABLE_SIZE, 16), call(v4_t.EzspConfigId.CONFIG_PAN_ID_CONFLICT_REPORT_THRESHOLD, 2), - call(v4_t.EzspConfigId.CONFIG_KEY_TABLE_SIZE, 4), call(v4_t.EzspConfigId.CONFIG_MAX_END_DEVICE_CHILDREN, 32), call( v4_t.EzspConfigId.CONFIG_APPLICATION_ZDO_FLAGS, @@ -755,6 +747,14 @@ async def test_config_initialize_husbzb1(ezsp_f): | v4_t.EmberZdoConfigurationFlags.APP_RECEIVES_SUPPORTED_ZDO_REQUESTS ), ), + call(v4_t.EzspConfigId.CONFIG_SOURCE_ROUTE_TABLE_SIZE, 16), + call(v4_t.EzspConfigId.CONFIG_END_DEVICE_POLL_TIMEOUT, 60), + call(v4_t.EzspConfigId.CONFIG_END_DEVICE_POLL_TIMEOUT_SHIFT, 8), + call(v4_t.EzspConfigId.CONFIG_SUPPORTED_NETWORKS, 1), + call(v4_t.EzspConfigId.CONFIG_MULTICAST_TABLE_SIZE, 16), + call(v4_t.EzspConfigId.CONFIG_TRUST_CENTER_ADDRESS_CACHE_SIZE, 2), + call(v4_t.EzspConfigId.CONFIG_ADDRESS_TABLE_SIZE, 16), + call(v4_t.EzspConfigId.CONFIG_KEY_TABLE_SIZE, 4), call(v4_t.EzspConfigId.CONFIG_PACKET_BUFFER_COUNT, 255), ] From 59ff4d335a4a99c1eeb3e70384735fd0fa8439bf Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Sun, 21 Jul 2024 19:21:34 -0400 Subject: [PATCH 2/2] Tie the runtime stack config to the EZSP object --- bellows/ezsp/__init__.py | 4 ++-- bellows/ezsp/config.py | 15 --------------- bellows/ezsp/v4/__init__.py | 2 ++ bellows/ezsp/v7/__init__.py | 2 ++ 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/bellows/ezsp/__init__.py b/bellows/ezsp/__init__.py index 5aeb0e73..509dbedd 100644 --- a/bellows/ezsp/__init__.py +++ b/bellows/ezsp/__init__.py @@ -23,7 +23,7 @@ import bellows.config as conf from bellows.exception import EzspError, InvalidCommandError -from bellows.ezsp.config import DEFAULT_CONFIG, RuntimeConfig, ValueConfig +from bellows.ezsp.config import RuntimeConfig, ValueConfig import bellows.types as t import bellows.uart @@ -543,7 +543,7 @@ async def write_config(self, config: dict) -> None: ezsp_config = {} ezsp_values = {} - for cfg in DEFAULT_CONFIG[self._ezsp_version]: + for cfg in self.CONFIG: if isinstance(cfg, RuntimeConfig): ezsp_config[cfg.config_id.name] = dataclasses.replace( cfg, config_id=t.EzspConfigId[cfg.config_id.name] diff --git a/bellows/ezsp/config.py b/bellows/ezsp/config.py index 5f34b4d0..a411638f 100644 --- a/bellows/ezsp/config.py +++ b/bellows/ezsp/config.py @@ -108,18 +108,3 @@ class ValueConfig: value=t.uint8_t(1), ), ] - - -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, - 11: DEFAULT_CONFIG_NEW, - 12: DEFAULT_CONFIG_NEW, - 13: DEFAULT_CONFIG_NEW, - 14: DEFAULT_CONFIG_NEW, -} diff --git a/bellows/ezsp/v4/__init__.py b/bellows/ezsp/v4/__init__.py index 8114f070..9922317d 100644 --- a/bellows/ezsp/v4/__init__.py +++ b/bellows/ezsp/v4/__init__.py @@ -8,6 +8,7 @@ import zigpy.state import bellows.config +from bellows.ezsp.config import DEFAULT_CONFIG_LEGACY import bellows.types as t from bellows.zigbee.util import ezsp_key_to_zigpy_key @@ -26,6 +27,7 @@ class EZSPv4(protocol.ProtocolHandler): bellows.config.CONF_EZSP_CONFIG: vol.Schema(config.EZSP_SCHEMA), bellows.config.CONF_EZSP_POLICIES: vol.Schema(config.EZSP_POLICIES_SCH), } + CONFIG = DEFAULT_CONFIG_LEGACY def _ezsp_frame_tx(self, name: str) -> bytes: """Serialize the frame id.""" diff --git a/bellows/ezsp/v7/__init__.py b/bellows/ezsp/v7/__init__.py index e5486c98..77a9b451 100644 --- a/bellows/ezsp/v7/__init__.py +++ b/bellows/ezsp/v7/__init__.py @@ -7,6 +7,7 @@ import voluptuous import bellows.config +from bellows.ezsp.config import DEFAULT_CONFIG_NEW import bellows.types as t from . import commands, config @@ -24,6 +25,7 @@ class EZSPv7(EZSPv6): bellows.config.CONF_EZSP_CONFIG: voluptuous.Schema(config.EZSP_SCHEMA), bellows.config.CONF_EZSP_POLICIES: voluptuous.Schema(config.EZSP_POLICIES_SCH), } + CONFIG = DEFAULT_CONFIG_NEW async def read_child_data( self,