Skip to content

Commit 22f07a4

Browse files
authored
Add support for tcp forwarded serial ports (zigpy#176)
* Add support for tcp forwarded serial ports * Format code
1 parent b3aac2e commit 22f07a4

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

zigpy_deconz/uart.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import binascii
55
import logging
66
from typing import Callable, Dict
7+
import urllib.parse
78

89
import serial
910
import serial_asyncio
@@ -139,15 +140,21 @@ async def connect(config: Dict[str, str], api: Callable, loop=None) -> Gateway:
139140
connected_future = asyncio.Future()
140141
protocol = Gateway(api, connected_future)
141142

142-
_, protocol = await serial_asyncio.create_serial_connection(
143-
loop,
144-
lambda: protocol,
145-
url=config[CONF_DEVICE_PATH],
146-
baudrate=DECONZ_BAUDRATE,
147-
parity=serial.PARITY_NONE,
148-
stopbits=serial.STOPBITS_ONE,
149-
xonxoff=False,
150-
)
143+
parsed_path = urllib.parse.urlparse(config[CONF_DEVICE_PATH])
144+
if parsed_path.scheme == "tcp":
145+
_, protocol = await loop.create_connection(
146+
lambda: protocol, parsed_path.hostname, parsed_path.port
147+
)
148+
else:
149+
_, protocol = await serial_asyncio.create_serial_connection(
150+
loop,
151+
lambda: protocol,
152+
url=config[CONF_DEVICE_PATH],
153+
baudrate=DECONZ_BAUDRATE,
154+
parity=serial.PARITY_NONE,
155+
stopbits=serial.STOPBITS_ONE,
156+
xonxoff=False,
157+
)
151158

152159
await connected_future
153160

0 commit comments

Comments
 (0)