10
10
This module provides Services used by MicroChip
11
11
12
12
"""
13
+
13
14
from adafruit_ble import Service
14
15
from adafruit_ble .uuid import VendorUUID
15
16
from adafruit_ble .characteristics .stream import StreamOut , StreamIn
16
17
17
18
try :
18
- from typing import Union
19
+ from typing import Optional
19
20
except ImportError :
20
21
pass
22
+ from circuitpython_typing import ReadableBuffer
21
23
22
24
__version__ = "0.0.0-auto.0"
23
25
__repo__ = (
@@ -48,7 +50,7 @@ class TransparentUARTService(Service):
48
50
buffer_size = 64 ,
49
51
)
50
52
51
- def __init__ (self , service : Union [Service , None ] = None ):
53
+ def __init__ (self , service : Optional [Service ] = None ):
52
54
super ().__init__ (service = service )
53
55
self .connectable = True
54
56
if not service :
@@ -59,7 +61,7 @@ def __init__(self, service: Union[Service, None] = None):
59
61
self ._tx = self ._server_rx
60
62
self ._rx = self ._server_tx
61
63
62
- def read (self , nbytes : Union [bytes , None ] = None ) -> Union [bytes , None ]:
64
+ def read (self , nbytes : Optional [bytes ] = None ) -> Optional [bytes ]:
63
65
"""
64
66
Read characters. If ``nbytes`` is specified then read at most that many bytes.
65
67
Otherwise, read everything that arrives until the connection times out.
@@ -70,9 +72,7 @@ def read(self, nbytes: Union[bytes, None] = None) -> Union[bytes, None]:
70
72
"""
71
73
return self ._rx .read (nbytes )
72
74
73
- def readinto (
74
- self , buf : bytes , nbytes : Union [bytes , None ] = None
75
- ) -> Union [int , None ]:
75
+ def readinto (self , buf : bytes , nbytes : Optional [bytes ] = None ) -> Optional [int ]:
76
76
"""
77
77
Read bytes into the ``buf``. If ``nbytes`` is specified then read at most
78
78
that many bytes. Otherwise, read at most ``len(buf)`` bytes.
@@ -82,7 +82,7 @@ def readinto(
82
82
"""
83
83
return self ._rx .readinto (buf , nbytes )
84
84
85
- def readline (self ) -> Union [ int , None ]:
85
+ def readline (self ) -> Optional [ bytes ]:
86
86
"""
87
87
Read a line, ending in a newline character.
88
88
@@ -100,6 +100,6 @@ def reset_input_buffer(self) -> None:
100
100
"""Discard any unread characters in the input buffer."""
101
101
self ._rx .reset_input_buffer ()
102
102
103
- def write (self , buf : bytes ) -> None :
103
+ def write (self , buf : ReadableBuffer ) -> None :
104
104
"""Write a buffer of bytes."""
105
105
self ._tx .write (buf )
0 commit comments