Skip to content

Commit ae974c8

Browse files
committed
Reduce pyserial-specific code to work with SocketTransport
1 parent 5d61994 commit ae974c8

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

setup.cfg

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ license = GPL-3.0
1313
packages = find:
1414
python_requires = >=3.7
1515
install_requires =
16-
pyserial-asyncio; platform_system!="Windows"
17-
pyserial-asyncio!=0.5; platform_system=="Windows" # 0.5 broke writes
1816
zigpy>=0.51.0
1917
async_timeout
2018
voluptuous

zigpy_znp/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ async def connect(self, *, test_port=True) -> None:
703703
self.close()
704704
raise
705705

706-
LOGGER.debug("Connected to %s at %s baud", self._uart.name, self._uart.baudrate)
706+
LOGGER.debug("Connected to %s", self._uart.url)
707707

708708
def connection_made(self) -> None:
709709
"""

zigpy_znp/uart.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def connection_lost(self, exc: Exception | None) -> None:
5252
def connection_made(self, transport: asyncio.BaseTransport) -> None:
5353
"""Opened serial port."""
5454
self._transport = transport
55-
LOGGER.debug("Opened %s serial port", transport.serial.name)
55+
LOGGER.debug("Opened %s serial port", self.url)
5656

5757
self._connected_event.set()
5858

@@ -91,19 +91,15 @@ def write(self, data: bytes) -> None:
9191
self._transport.write(data)
9292

9393
def set_dtr_rts(self, *, dtr: bool, rts: bool) -> None:
94+
# TCP transport does not have DTR or RTS pins
95+
if not hasattr(self._transport, "serial"):
96+
return
97+
9498
LOGGER.debug("Setting serial pin states: DTR=%s, RTS=%s", dtr, rts)
9599

96100
self._transport.serial.dtr = dtr
97101
self._transport.serial.rts = rts
98102

99-
@property
100-
def name(self) -> str:
101-
return self._transport.serial.name
102-
103-
@property
104-
def baudrate(self) -> int:
105-
return self._transport.serial.baudrate
106-
107103
def _extract_frames(self) -> typing.Iterator[frames.TransportFrame]:
108104
"""Extracts frames from the buffer until it is exhausted."""
109105
while True:
@@ -156,8 +152,7 @@ def _extract_frame(self) -> frames.TransportFrame:
156152
def __repr__(self) -> str:
157153
return (
158154
f"<"
159-
f"{type(self).__name__} connected to {self.name!r}"
160-
f" at {self.baudrate} baud"
155+
f"{type(self).__name__} connected to {self.url!r}"
161156
f" (api: {self._api})"
162157
f">"
163158
)
@@ -174,7 +169,7 @@ async def connect(config: conf.ConfigType, api) -> ZnpMtProtocol:
174169

175170
_, protocol = await zigpy.serial.create_serial_connection(
176171
loop=loop,
177-
protocol_factory=lambda: ZnpMtProtocol(api),
172+
protocol_factory=lambda: ZnpMtProtocol(api, url=port),
178173
url=port,
179174
baudrate=baudrate,
180175
xonxoff=(flow_control == "software"),

0 commit comments

Comments
 (0)