diff --git a/bellows/__init__.py b/bellows/__init__.py index 085b76d9..b9e8f38f 100644 --- a/bellows/__init__.py +++ b/bellows/__init__.py @@ -1,5 +1,5 @@ MAJOR_VERSION = 0 MINOR_VERSION = 35 -PATCH_VERSION = "4" +PATCH_VERSION = "5" __short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}" __version__ = f"{__short_version__}.{PATCH_VERSION}" diff --git a/bellows/ezsp/__init__.py b/bellows/ezsp/__init__.py index 25378b2e..2faa1c08 100644 --- a/bellows/ezsp/__init__.py +++ b/bellows/ezsp/__init__.py @@ -25,7 +25,7 @@ from . import v4, v5, v6, v7, v8, v9, v10, v11 -EZSP_LATEST = v11.EZSP_VERSION +EZSP_LATEST = v11.EZSPv11.VERSION PROBE_TIMEOUT = 3 NETWORK_OPS_TIMEOUT = 10 LOGGER = logging.getLogger(__name__) @@ -39,21 +39,21 @@ class EZSP: _BY_VERSION = { - v4.EZSP_VERSION: v4.EZSPv4, - v5.EZSP_VERSION: v5.EZSPv5, - v6.EZSP_VERSION: v6.EZSPv6, - v7.EZSP_VERSION: v7.EZSPv7, - v8.EZSP_VERSION: v8.EZSPv8, - v9.EZSP_VERSION: v9.EZSPv9, - v10.EZSP_VERSION: v10.EZSPv10, - v11.EZSP_VERSION: v11.EZSPv11, + v4.EZSPv4.VERSION: v4.EZSPv4, + v5.EZSPv5.VERSION: v5.EZSPv5, + v6.EZSPv6.VERSION: v6.EZSPv6, + v7.EZSPv7.VERSION: v7.EZSPv7, + v8.EZSPv8.VERSION: v8.EZSPv8, + v9.EZSPv9.VERSION: v9.EZSPv9, + v10.EZSPv10.VERSION: v10.EZSPv10, + v11.EZSPv11.VERSION: v11.EZSPv11, } def __init__(self, device_config: dict): self._config = device_config self._callbacks = {} self._ezsp_event = asyncio.Event() - self._ezsp_version = v4.EZSP_VERSION + self._ezsp_version = v4.EZSPv4.VERSION self._gw = None self._protocol = None diff --git a/bellows/ezsp/config.py b/bellows/ezsp/config.py index 19ba2f29..750b1ab2 100644 --- a/bellows/ezsp/config.py +++ b/bellows/ezsp/config.py @@ -116,4 +116,5 @@ class RuntimeConfig: 8: DEFAULT_CONFIG_NEW, 9: DEFAULT_CONFIG_NEW, 10: DEFAULT_CONFIG_NEW, + 11: DEFAULT_CONFIG_NEW, } diff --git a/bellows/ezsp/protocol.py b/bellows/ezsp/protocol.py index 20360731..87fcb3e7 100644 --- a/bellows/ezsp/protocol.py +++ b/bellows/ezsp/protocol.py @@ -24,7 +24,7 @@ class ProtocolHandler(abc.ABC): """EZSP protocol specific handler.""" COMMANDS = {} - EZSP_VERSION = 4 + VERSION = None def __init__(self, cb_handler: Callable, gateway: GatewayType) -> None: self._handle_callback = cb_handler @@ -71,7 +71,7 @@ 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[self.EZSP_VERSION]: + for cfg in DEFAULT_CONFIG[self.VERSION]: config_id = self.types.EzspConfigId[cfg.config_id.name] ezsp_config[cfg.config_id.name] = dataclasses.replace( cfg, config_id=config_id diff --git a/bellows/ezsp/v10/__init__.py b/bellows/ezsp/v10/__init__.py index 92918dec..09bdab3d 100644 --- a/bellows/ezsp/v10/__init__.py +++ b/bellows/ezsp/v10/__init__.py @@ -10,13 +10,13 @@ from . import commands, config, types as v10_types from .. import protocol -EZSP_VERSION = 10 LOGGER = logging.getLogger(__name__) class EZSPv10(protocol.ProtocolHandler): """EZSP Version 10 Protocol version handler.""" + VERSION = 10 COMMANDS = commands.COMMANDS SCHEMAS = { bellows.config.CONF_EZSP_CONFIG: voluptuous.Schema(config.EZSP_SCHEMA), diff --git a/bellows/ezsp/v11/__init__.py b/bellows/ezsp/v11/__init__.py index 158f520e..bdbd7e2f 100644 --- a/bellows/ezsp/v11/__init__.py +++ b/bellows/ezsp/v11/__init__.py @@ -6,12 +6,11 @@ from . import commands, config, types as v11_types from ..v10 import EZSPv10 -EZSP_VERSION = 11 - class EZSPv11(EZSPv10): """EZSP Version 11 Protocol version handler.""" + VERSION = 11 COMMANDS = commands.COMMANDS SCHEMAS = { bellows.config.CONF_EZSP_CONFIG: vol.Schema(config.EZSP_SCHEMA), diff --git a/bellows/ezsp/v4/__init__.py b/bellows/ezsp/v4/__init__.py index 38d76c10..f786b76f 100644 --- a/bellows/ezsp/v4/__init__.py +++ b/bellows/ezsp/v4/__init__.py @@ -9,13 +9,13 @@ from . import commands, config, types as v4_types from .. import protocol -EZSP_VERSION = 4 LOGGER = logging.getLogger(__name__) class EZSPv4(protocol.ProtocolHandler): """EZSP Version 4 Protocol version handler.""" + VERSION = 4 COMMANDS = commands.COMMANDS SCHEMAS = { bellows.config.CONF_EZSP_CONFIG: voluptuous.Schema(config.EZSP_SCHEMA), diff --git a/bellows/ezsp/v5/__init__.py b/bellows/ezsp/v5/__init__.py index c4b7390b..e6856cd9 100644 --- a/bellows/ezsp/v5/__init__.py +++ b/bellows/ezsp/v5/__init__.py @@ -9,13 +9,13 @@ from . import commands, config, types as v5_types from ..v4 import EZSPv4 -EZSP_VERSION = 5 LOGGER = logging.getLogger(__name__) class EZSPv5(EZSPv4): """EZSP Version 5 Protocol version handler.""" + VERSION = 5 COMMANDS = commands.COMMANDS SCHEMAS = { bellows.config.CONF_EZSP_CONFIG: voluptuous.Schema(config.EZSP_SCHEMA), diff --git a/bellows/ezsp/v6/__init__.py b/bellows/ezsp/v6/__init__.py index bd9aea21..e15b4b0b 100644 --- a/bellows/ezsp/v6/__init__.py +++ b/bellows/ezsp/v6/__init__.py @@ -8,13 +8,13 @@ from . import commands, config, types as v6_types from ..v5 import EZSPv5 -EZSP_VERSION = 6 LOGGER = logging.getLogger(__name__) class EZSPv6(EZSPv5): """EZSP Version 6 Protocol version handler.""" + VERSION = 6 COMMANDS = commands.COMMANDS SCHEMAS = { bellows.config.CONF_EZSP_CONFIG: voluptuous.Schema(config.EZSP_SCHEMA), diff --git a/bellows/ezsp/v7/__init__.py b/bellows/ezsp/v7/__init__.py index e7f4f264..755711f8 100644 --- a/bellows/ezsp/v7/__init__.py +++ b/bellows/ezsp/v7/__init__.py @@ -8,13 +8,13 @@ from . import commands, config, types as v7_types from ..v5 import EZSPv5 -EZSP_VERSION = 7 LOGGER = logging.getLogger(__name__) class EZSPv7(EZSPv5): """EZSP Version 7 Protocol version handler.""" + VERSION = 7 COMMANDS = commands.COMMANDS SCHEMAS = { bellows.config.CONF_EZSP_CONFIG: voluptuous.Schema(config.EZSP_SCHEMA), diff --git a/bellows/ezsp/v8/__init__.py b/bellows/ezsp/v8/__init__.py index b645b73a..e731043e 100644 --- a/bellows/ezsp/v8/__init__.py +++ b/bellows/ezsp/v8/__init__.py @@ -10,13 +10,13 @@ from . import commands, config, types as v8_types from .. import protocol -EZSP_VERSION = 8 LOGGER = logging.getLogger(__name__) class EZSPv8(protocol.ProtocolHandler): """EZSP Version 8 Protocol version handler.""" + VERSION = 8 COMMANDS = commands.COMMANDS SCHEMAS = { bellows.config.CONF_EZSP_CONFIG: voluptuous.Schema(config.EZSP_SCHEMA), diff --git a/bellows/ezsp/v9/__init__.py b/bellows/ezsp/v9/__init__.py index 0c767ca4..dba7b3a6 100644 --- a/bellows/ezsp/v9/__init__.py +++ b/bellows/ezsp/v9/__init__.py @@ -10,13 +10,13 @@ from . import commands, config, types as v9_types from .. import protocol -EZSP_VERSION = 9 LOGGER = logging.getLogger(__name__) class EZSPv9(protocol.ProtocolHandler): """EZSP Version 9 Protocol version handler.""" + VERSION = 9 COMMANDS = commands.COMMANDS SCHEMAS = { bellows.config.CONF_EZSP_CONFIG: voluptuous.Schema(config.EZSP_SCHEMA), diff --git a/tests/test_ezsp.py b/tests/test_ezsp.py index b0700547..00784dee 100644 --- a/tests/test_ezsp.py +++ b/tests/test_ezsp.py @@ -599,3 +599,10 @@ async def test_wait_for_stack_status(ezsp_f): await stack_status assert not ezsp_f._stack_status_listeners[t.EmberStatus.NETWORK_DOWN] + + +def test_ezsp_versions(ezsp_f): + for version in range(4, ezsp.EZSP_LATEST + 1): + assert version in ezsp_f._BY_VERSION + assert ezsp_f._BY_VERSION[version].__name__ == f"EZSPv{version}" + assert ezsp_f._BY_VERSION[version].VERSION == version diff --git a/tests/test_ezsp_protocol.py b/tests/test_ezsp_protocol.py index 2d353ac9..4f25e469 100644 --- a/tests/test_ezsp_protocol.py +++ b/tests/test_ezsp_protocol.py @@ -3,28 +3,17 @@ import pytest +from bellows.ezsp import EZSP import bellows.ezsp.v4 import bellows.ezsp.v4.types as t from .async_mock import ANY, AsyncMock, MagicMock, call, patch -class _DummyProtocolHandler(bellows.ezsp.v4.EZSPv4): - """Protocol handler mock.""" - - @property - def gw_mock(self): - return self._gw - - @property - def cb_mock(self): - return self._handle_callback - - @pytest.fixture def prot_hndl(): """Protocol handler mock.""" - return _DummyProtocolHandler(MagicMock(), MagicMock()) + return bellows.ezsp.v4.EZSPv4(MagicMock(), MagicMock()) async def test_command(prot_hndl): @@ -46,7 +35,7 @@ def test_receive_reply(prot_hndl): assert callback_mock.set_exception.call_count == 0 assert callback_mock.set_result.call_count == 1 callback_mock.set_result.assert_called_once_with([4, 5, 6]) - assert prot_hndl.cb_mock.call_count == 0 + assert prot_hndl._handle_callback.call_count == 0 def test_receive_reply_after_timeout(prot_hndl): @@ -59,7 +48,7 @@ def test_receive_reply_after_timeout(prot_hndl): assert callback_mock.set_exception.call_count == 0 assert callback_mock.set_result.call_count == 1 callback_mock.set_result.assert_called_once_with([4, 5, 6]) - assert prot_hndl.cb_mock.call_count == 0 + assert prot_hndl._handle_callback.call_count == 0 def test_receive_reply_invalid_command(prot_hndl): @@ -70,7 +59,7 @@ def test_receive_reply_invalid_command(prot_hndl): assert 0 not in prot_hndl._awaiting assert callback_mock.set_exception.call_count == 1 assert callback_mock.set_result.call_count == 0 - assert prot_hndl.cb_mock.call_count == 0 + assert prot_hndl._handle_callback.call_count == 0 async def test_cfg_initialize(prot_hndl, caplog): @@ -127,6 +116,17 @@ async def test_config_initialize_husbzb1(prot_hndl): ) +@pytest.mark.parametrize("prot_hndl_cls", EZSP._BY_VERSION.values()) +async def test_config_initialize(prot_hndl_cls): + """Test config initialization for all protocol versions.""" + + prot_hndl = prot_hndl_cls(MagicMock(), MagicMock()) + 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": {}}) + + async def test_cfg_initialize_skip(prot_hndl): """Test initialization."""