Skip to content

Commit 3c82aed

Browse files
Haertelericpuddly
andauthored
added a Baudrate Variable to config for Baudrate selection (#229)
* 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 <[email protected]>
1 parent dc4a1d3 commit 3c82aed

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

tests/test_uart.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import zigpy.serial
99

1010
from zigpy_deconz import uart
11+
from zigpy_deconz.config import CONF_DEVICE_BAUDRATE
1112

1213

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

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

30-
await uart.connect({CONF_DEVICE_PATH: "/dev/null"}, api)
31+
await uart.connect(
32+
{CONF_DEVICE_PATH: "/dev/null", CONF_DEVICE_BAUDRATE: 115200}, api
33+
)
3134

3235

3336
def test_send(gw):

zigpy_deconz/config.py

+7
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,15 @@
2626
CONF_WATCHDOG_TTL = "watchdog_ttl"
2727
CONF_WATCHDOG_TTL_DEFAULT = 600
2828

29+
CONF_DEVICE_BAUDRATE = "baudrate"
30+
31+
SCHEMA_DEVICE = SCHEMA_DEVICE.extend(
32+
{vol.Optional(CONF_DEVICE_BAUDRATE, default=38400): int}
33+
)
34+
2935
CONFIG_SCHEMA = CONFIG_SCHEMA.extend(
3036
{
37+
vol.Required(CONF_DEVICE): SCHEMA_DEVICE,
3138
vol.Optional(CONF_WATCHDOG_TTL, default=CONF_WATCHDOG_TTL_DEFAULT): vol.All(
3239
int, vol.Range(min=180)
3340
),

zigpy_deconz/uart.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
import logging
66
from typing import Callable, Dict
77

8-
from zigpy.config import CONF_DEVICE_PATH
98
import zigpy.serial
109

11-
LOGGER = logging.getLogger(__name__)
12-
10+
from zigpy_deconz.config import CONF_DEVICE_BAUDRATE, CONF_DEVICE_PATH
1311

14-
DECONZ_BAUDRATE = 38400
12+
LOGGER = logging.getLogger(__name__)
1513

1614

1715
class Gateway(asyncio.Protocol):
@@ -124,7 +122,7 @@ def _checksum(self, data):
124122
return bytes(ret)
125123

126124

127-
async def connect(config: Dict[str, str], api: Callable) -> Gateway:
125+
async def connect(config: Dict[str, any], api: Callable) -> Gateway:
128126
loop = asyncio.get_running_loop()
129127
connected_future = loop.create_future()
130128
protocol = Gateway(api, connected_future)
@@ -135,7 +133,7 @@ async def connect(config: Dict[str, str], api: Callable) -> Gateway:
135133
loop=loop,
136134
protocol_factory=lambda: protocol,
137135
url=config[CONF_DEVICE_PATH],
138-
baudrate=DECONZ_BAUDRATE,
136+
baudrate=config[CONF_DEVICE_BAUDRATE],
139137
xonxoff=False,
140138
)
141139

0 commit comments

Comments
 (0)