Skip to content

Commit

Permalink
added a Baudrate Variable to config for Baudrate selection (#229)
Browse files Browse the repository at this point in the history
* added a Baudrate Variable to config for Baudrate selection

* changed default baudrate for backw. compatibility

* ran pre-commit

* Include baudrate in unit tests

---------

Co-authored-by: puddly <32534428+puddly@users.noreply.github.com>
  • Loading branch information
Haerteleric and puddly authored Nov 10, 2023
1 parent dc4a1d3 commit 3c82aed
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 4 additions & 1 deletion tests/test_uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import zigpy.serial

from zigpy_deconz import uart
from zigpy_deconz.config import CONF_DEVICE_BAUDRATE


@pytest.fixture
Expand All @@ -27,7 +28,9 @@ async def mock_conn(loop, protocol_factory, **kwargs):

monkeypatch.setattr(zigpy.serial, "create_serial_connection", mock_conn)

await uart.connect({CONF_DEVICE_PATH: "/dev/null"}, api)
await uart.connect(
{CONF_DEVICE_PATH: "/dev/null", CONF_DEVICE_BAUDRATE: 115200}, api
)


def test_send(gw):
Expand Down
7 changes: 7 additions & 0 deletions zigpy_deconz/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@
CONF_WATCHDOG_TTL = "watchdog_ttl"
CONF_WATCHDOG_TTL_DEFAULT = 600

CONF_DEVICE_BAUDRATE = "baudrate"

SCHEMA_DEVICE = SCHEMA_DEVICE.extend(
{vol.Optional(CONF_DEVICE_BAUDRATE, default=38400): int}
)

CONFIG_SCHEMA = CONFIG_SCHEMA.extend(
{
vol.Required(CONF_DEVICE): SCHEMA_DEVICE,
vol.Optional(CONF_WATCHDOG_TTL, default=CONF_WATCHDOG_TTL_DEFAULT): vol.All(
int, vol.Range(min=180)
),
Expand Down
10 changes: 4 additions & 6 deletions zigpy_deconz/uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
import logging
from typing import Callable, Dict

from zigpy.config import CONF_DEVICE_PATH
import zigpy.serial

LOGGER = logging.getLogger(__name__)

from zigpy_deconz.config import CONF_DEVICE_BAUDRATE, CONF_DEVICE_PATH

DECONZ_BAUDRATE = 38400
LOGGER = logging.getLogger(__name__)


class Gateway(asyncio.Protocol):
Expand Down Expand Up @@ -124,7 +122,7 @@ def _checksum(self, data):
return bytes(ret)


async def connect(config: Dict[str, str], api: Callable) -> Gateway:
async def connect(config: Dict[str, any], api: Callable) -> Gateway:
loop = asyncio.get_running_loop()
connected_future = loop.create_future()
protocol = Gateway(api, connected_future)
Expand All @@ -135,7 +133,7 @@ async def connect(config: Dict[str, str], api: Callable) -> Gateway:
loop=loop,
protocol_factory=lambda: protocol,
url=config[CONF_DEVICE_PATH],
baudrate=DECONZ_BAUDRATE,
baudrate=config[CONF_DEVICE_BAUDRATE],
xonxoff=False,
)

Expand Down

0 comments on commit 3c82aed

Please sign in to comment.