1
+ from __future__ import annotations
2
+
1
3
import typing
2
4
import asyncio
3
5
import logging
4
- import warnings
5
6
6
- import serial
7
+ import zigpy . serial
7
8
8
9
import zigpy_znp .config as conf
9
10
import zigpy_znp .frames as frames
10
11
import zigpy_znp .logger as log
11
12
from zigpy_znp .types import Bytes
12
13
from zigpy_znp .exceptions import InvalidFrame
13
14
14
- with warnings .catch_warnings ():
15
- warnings .filterwarnings (
16
- action = "ignore" ,
17
- module = "serial_asyncio" ,
18
- message = '"@coroutine" decorator is deprecated' ,
19
- category = DeprecationWarning ,
20
- )
21
- import serial_asyncio # noqa: E402
22
-
23
-
24
15
LOGGER = logging .getLogger (__name__ )
25
16
26
17
@@ -29,12 +20,14 @@ class BufferTooShort(Exception):
29
20
30
21
31
22
class ZnpMtProtocol (asyncio .Protocol ):
32
- def __init__ (self , api ) :
23
+ def __init__ (self , api , * , url : str | None = None ) -> None :
33
24
self ._buffer = bytearray ()
34
25
self ._api = api
35
26
self ._transport = None
36
27
self ._connected_event = asyncio .Event ()
37
28
29
+ self .url = url
30
+
38
31
def close (self ) -> None :
39
32
"""Closes the port."""
40
33
@@ -47,7 +40,7 @@ def close(self) -> None:
47
40
self ._transport .close ()
48
41
self ._transport = None
49
42
50
- def connection_lost (self , exc : typing . Optional [ Exception ] ) -> None :
43
+ def connection_lost (self , exc : Exception | None ) -> None :
51
44
"""Connection lost."""
52
45
53
46
if exc is not None :
@@ -56,7 +49,7 @@ def connection_lost(self, exc: typing.Optional[Exception]) -> None:
56
49
if self ._api is not None :
57
50
self ._api .connection_lost (exc )
58
51
59
- def connection_made (self , transport : serial_asyncio . SerialTransport ) -> None :
52
+ def connection_made (self , transport : asyncio . BaseTransport ) -> None :
60
53
"""Opened serial port."""
61
54
self ._transport = transport
62
55
LOGGER .debug ("Opened %s serial port" , transport .serial .name )
@@ -179,13 +172,11 @@ async def connect(config: conf.ConfigType, api) -> ZnpMtProtocol:
179
172
180
173
LOGGER .debug ("Connecting to %s at %s baud" , port , baudrate )
181
174
182
- _ , protocol = await serial_asyncio .create_serial_connection (
175
+ _ , protocol = await zigpy . serial .create_serial_connection (
183
176
loop = loop ,
184
177
protocol_factory = lambda : ZnpMtProtocol (api ),
185
178
url = port ,
186
179
baudrate = baudrate ,
187
- parity = serial .PARITY_NONE ,
188
- stopbits = serial .STOPBITS_ONE ,
189
180
xonxoff = (flow_control == "software" ),
190
181
rtscts = (flow_control == "hardware" ),
191
182
)
0 commit comments