Skip to content

Commit

Permalink
Merge pull request #560 from puddly/rc
Browse files Browse the repository at this point in the history
0.35.5 Release
  • Loading branch information
puddly authored May 12, 2023
2 parents 74e61a7 + 37f3a3c commit a556c90
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 38 deletions.
2 changes: 1 addition & 1 deletion bellows/__init__.py
Original file line number Diff line number Diff line change
@@ -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}"
20 changes: 10 additions & 10 deletions bellows/ezsp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions bellows/ezsp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,5 @@ class RuntimeConfig:
8: DEFAULT_CONFIG_NEW,
9: DEFAULT_CONFIG_NEW,
10: DEFAULT_CONFIG_NEW,
11: DEFAULT_CONFIG_NEW,
}
4 changes: 2 additions & 2 deletions bellows/ezsp/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bellows/ezsp/v10/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions bellows/ezsp/v11/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion bellows/ezsp/v4/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion bellows/ezsp/v5/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion bellows/ezsp/v6/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion bellows/ezsp/v7/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion bellows/ezsp/v8/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion bellows/ezsp/v9/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
7 changes: 7 additions & 0 deletions tests/test_ezsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 16 additions & 16 deletions tests/test_ezsp_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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."""

Expand Down

0 comments on commit a556c90

Please sign in to comment.