Skip to content

Commit

Permalink
Merge pull request #509 from puddly/rc
Browse files Browse the repository at this point in the history
0.34.3 Release
  • Loading branch information
puddly committed Nov 9, 2022
2 parents 45b0f81 + d26b1f2 commit 44b2937
Show file tree
Hide file tree
Showing 16 changed files with 278 additions and 940 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 = 34
PATCH_VERSION = "2"
PATCH_VERSION = "3"
__short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}"
__version__ = f"{__short_version__}.{PATCH_VERSION}"
16 changes: 16 additions & 0 deletions bellows/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import voluptuous as vol
from zigpy.config import ( # noqa: F401 pylint: disable=unused-import
CONF_DEVICE,
Expand All @@ -17,6 +19,7 @@
)

CONF_DEVICE_BAUDRATE = "baudrate"
CONF_USE_THREAD = "use_thread"
CONF_EZSP_CONFIG = "ezsp_config"
CONF_EZSP_POLICIES = "ezsp_policies"
CONF_PARAM_MAX_WATCHDOG_FAILURES = "max_watchdog_failures"
Expand All @@ -40,7 +43,20 @@
vol.Optional(CONF_EZSP_POLICIES, default={}): vol.Schema(
{vol.Optional(str): int}
),
vol.Optional(CONF_USE_THREAD, default=True): cv_boolean,
}
)

cv_uint16 = vol.All(int, vol.Range(min=0, max=65535))


def cv_optional_int(min: int | None = None, max: int | None = None) -> vol.All:
"""Voluptuous validator to create an optional integer validator."""

return vol.Maybe(vol.All(int, vol.Range(min=min, max=max)))


def extend_vol_schema(base: dict, changes: dict) -> dict:
"""Extend a Voluptuous schema. Simply overriding keys does not work."""

return {**{k: v for k, v in base.items() if k not in changes}, **changes}
32 changes: 16 additions & 16 deletions bellows/ezsp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@

import zigpy.config

from bellows.config import (
CONF_DEVICE,
CONF_DEVICE_BAUDRATE,
CONF_DEVICE_PATH,
SCHEMA_DEVICE,
)
import bellows.config as conf
from bellows.exception import EzspError
import bellows.types as t
import bellows.uart
Expand Down Expand Up @@ -55,15 +50,18 @@ def __init__(self, device_config: Dict):
@classmethod
async def probe(cls, device_config: Dict) -> bool | dict[str, int | str | bool]:
"""Probe port for the device presence."""
for config in ({**device_config, CONF_DEVICE_BAUDRATE: 115200}, device_config):
ezsp = cls(SCHEMA_DEVICE(config))
for config in (
{**device_config, conf.CONF_DEVICE_BAUDRATE: 115200},
device_config,
):
ezsp = cls(conf.SCHEMA_DEVICE(config))
try:
await asyncio.wait_for(ezsp._probe(), timeout=PROBE_TIMEOUT)
return config
except Exception as exc:
LOGGER.debug(
"Unsuccessful radio probe of '%s' port",
device_config[CONF_DEVICE_PATH],
device_config[conf.CONF_DEVICE_PATH],
exc_info=exc,
)
finally:
Expand All @@ -73,14 +71,14 @@ async def probe(cls, device_config: Dict) -> bool | dict[str, int | str | bool]:

async def _probe(self) -> None:
"""Open port and try sending a command"""
await self.connect()
await self.connect(use_thread=False)
await self._startup_reset()
await self.version()

async def _startup_reset(self):
"""Start EZSP and reset the stack."""
# `zigbeed` resets on startup
parsed_path = urllib.parse.urlparse(self._config[CONF_DEVICE_PATH])
parsed_path = urllib.parse.urlparse(self._config[conf.CONF_DEVICE_PATH])
if parsed_path.scheme == "socket":
try:
await asyncio.wait_for(
Expand All @@ -99,8 +97,8 @@ async def _startup_reset(self):
@classmethod
async def initialize(cls, zigpy_config: Dict) -> "EZSP":
"""Return initialized EZSP instance."""
ezsp = cls(zigpy_config[CONF_DEVICE])
await ezsp.connect()
ezsp = cls(zigpy_config[conf.CONF_DEVICE])
await ezsp.connect(use_thread=zigpy_config[conf.CONF_USE_THREAD])

try:
await ezsp._startup_reset()
Expand All @@ -115,9 +113,9 @@ async def initialize(cls, zigpy_config: Dict) -> "EZSP":

return ezsp

async def connect(self) -> None:
async def connect(self, *, use_thread: bool = True) -> None:
assert self._gw is None
self._gw = await bellows.uart.connect(self._config, self)
self._gw = await bellows.uart.connect(self._config, self, use_thread=use_thread)
self._protocol = v4.EZSPv4(self.handle_callback, self._gw)

async def reset(self):
Expand Down Expand Up @@ -241,7 +239,9 @@ def cb(frame_name: str, response: List) -> None:
def connection_lost(self, exc):
"""Lost serial connection."""
LOGGER.debug(
"%s connection lost unexpectedly: %s", self._config[CONF_DEVICE_PATH], exc
"%s connection lost unexpectedly: %s",
self._config[conf.CONF_DEVICE_PATH],
exc,
)
self.enter_failed_state(f"Serial connection loss: {exc!r}")

Expand Down
3 changes: 3 additions & 0 deletions bellows/ezsp/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def __init__(self, cb_handler: Callable, gateway: GatewayType) -> None:
self.tc_policy = 0

async def _cfg(self, config_id: int, value: Any) -> None:
if value is None:
return

(status,) = await self.setConfigurationValue(config_id, value)
if status != self.types.EmberStatus.SUCCESS:
LOGGER.warning(
Expand Down

0 comments on commit 44b2937

Please sign in to comment.