11
11
12
12
"""
13
13
14
+ from __future__ import annotations
15
+
14
16
from . import Service
15
17
from ..uuid import VendorUUID
16
18
from ..characteristics .stream import StreamOut , StreamIn
17
19
20
+ try :
21
+ from typing import Optional , TYPE_CHECKING
22
+
23
+ if TYPE_CHECKING :
24
+ from circuitpython_typing import WriteableBuffer , ReadableBuffer
25
+ import _bleio
26
+
27
+ except ImportError :
28
+ pass
29
+
18
30
__version__ = "0.0.0-auto.0"
19
31
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BLE.git"
20
32
@@ -39,7 +51,7 @@ class UARTService(Service):
39
51
buffer_size = 64 ,
40
52
)
41
53
42
- def __init__ (self , service = None ):
54
+ def __init__ (self , service : Optional [ _bleio . Service ] = None ) -> None :
43
55
super ().__init__ (service = service )
44
56
self .connectable = True
45
57
if not service :
@@ -50,7 +62,7 @@ def __init__(self, service=None):
50
62
self ._tx = self ._server_rx
51
63
self ._rx = self ._server_tx
52
64
53
- def read (self , nbytes = None ):
65
+ def read (self , nbytes : Optional [ int ] = None ) -> Optional [ bytes ] :
54
66
"""
55
67
Read characters. If ``nbytes`` is specified then read at most that many bytes.
56
68
Otherwise, read everything that arrives until the connection times out.
@@ -61,7 +73,9 @@ def read(self, nbytes=None):
61
73
"""
62
74
return self ._rx .read (nbytes )
63
75
64
- def readinto (self , buf , nbytes = None ):
76
+ def readinto (
77
+ self , buf : WriteableBuffer , nbytes : Optional [int ] = None
78
+ ) -> Optional [int ]:
65
79
"""
66
80
Read bytes into the ``buf``. If ``nbytes`` is specified then read at most
67
81
that many bytes. Otherwise, read at most ``len(buf)`` bytes.
@@ -71,7 +85,7 @@ def readinto(self, buf, nbytes=None):
71
85
"""
72
86
return self ._rx .readinto (buf , nbytes )
73
87
74
- def readline (self ):
88
+ def readline (self ) -> Optional [ bytes ] :
75
89
"""
76
90
Read a line, ending in a newline character.
77
91
@@ -81,14 +95,14 @@ def readline(self):
81
95
return self ._rx .readline ()
82
96
83
97
@property
84
- def in_waiting (self ):
98
+ def in_waiting (self ) -> int :
85
99
"""The number of bytes in the input buffer, available to be read."""
86
100
return self ._rx .in_waiting
87
101
88
- def reset_input_buffer (self ):
102
+ def reset_input_buffer (self ) -> None :
89
103
"""Discard any unread characters in the input buffer."""
90
104
self ._rx .reset_input_buffer ()
91
105
92
- def write (self , buf ) :
106
+ def write (self , buf : ReadableBuffer ) -> None :
93
107
"""Write a buffer of bytes."""
94
108
self ._tx .write (buf )
0 commit comments