10
10
object they are on.
11
11
12
12
"""
13
+
14
+ from __future__ import annotations
15
+
13
16
import _bleio
14
17
15
18
from . import Attribute
16
19
from . import Characteristic
17
20
from . import ComplexCharacteristic
18
21
22
+ try :
23
+ from typing import Optional , Union , TYPE_CHECKING
24
+
25
+ if TYPE_CHECKING :
26
+ from circuitpython_typing import ReadableBuffer
27
+ from adafruit_ble .characteristics import Characteristic
28
+ from adafruit_ble .uuid import UUID
29
+ from adafruit_ble .services import Service
30
+
31
+ except ImportError :
32
+ pass
33
+
19
34
__version__ = "0.0.0-auto.0"
20
35
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BLE.git"
21
36
22
37
23
38
class BoundWriteStream :
24
39
"""Writes data out to the peer."""
25
40
26
- def __init__ (self , bound_characteristic ) :
41
+ def __init__ (self , bound_characteristic : Characteristic ) -> None :
27
42
self .bound_characteristic = bound_characteristic
28
43
29
- def write (self , buf ) :
44
+ def write (self , buf : ReadableBuffer ) -> None :
30
45
"""Write data from buf out to the peer."""
31
46
# We can only write 20 bytes at a time.
32
47
offset = 0
@@ -41,20 +56,20 @@ class StreamOut(ComplexCharacteristic):
41
56
def __init__ (
42
57
self ,
43
58
* ,
44
- uuid = None ,
45
- timeout = 1.0 ,
46
- buffer_size = 64 ,
47
- properties = Characteristic .NOTIFY ,
48
- read_perm = Attribute .OPEN ,
49
- write_perm = Attribute .OPEN
50
- ):
59
+ uuid : Optional [ UUID ] = None ,
60
+ timeout : float = 1.0 ,
61
+ buffer_size : int = 64 ,
62
+ properties : int = Characteristic .NOTIFY ,
63
+ read_perm : int = Attribute .OPEN ,
64
+ write_perm : int = Attribute .OPEN ,
65
+ ) -> None :
51
66
self ._timeout = timeout
52
67
self ._buffer_size = buffer_size
53
68
super ().__init__ (
54
69
uuid = uuid , properties = properties , read_perm = read_perm , write_perm = write_perm
55
70
)
56
71
57
- def bind (self , service ) :
72
+ def bind (self , service : Service ) -> Union [ _bleio . Characteristic , BoundWriteStream ] :
58
73
"""Binds the characteristic to the given Service."""
59
74
bound_characteristic = super ().bind (service )
60
75
# If we're given a remote service then we're the client and need to buffer in.
@@ -74,12 +89,12 @@ class StreamIn(ComplexCharacteristic):
74
89
def __init__ (
75
90
self ,
76
91
* ,
77
- uuid = None ,
78
- timeout = 1.0 ,
79
- buffer_size = 64 ,
80
- properties = (Characteristic .WRITE | Characteristic .WRITE_NO_RESPONSE ),
81
- write_perm = Attribute .OPEN
82
- ):
92
+ uuid : Optional [ UUID ] = None ,
93
+ timeout : float = 1.0 ,
94
+ buffer_size : int = 64 ,
95
+ properties : int = (Characteristic .WRITE | Characteristic .WRITE_NO_RESPONSE ),
96
+ write_perm : int = Attribute .OPEN ,
97
+ ) -> None :
83
98
self ._timeout = timeout
84
99
self ._buffer_size = buffer_size
85
100
super ().__init__ (
@@ -89,7 +104,9 @@ def __init__(
89
104
write_perm = write_perm ,
90
105
)
91
106
92
- def bind (self , service ):
107
+ def bind (
108
+ self , service : Service
109
+ ) -> Union [_bleio .CharacteristicBuffer , BoundWriteStream ]:
93
110
"""Binds the characteristic to the given Service."""
94
111
bound_characteristic = super ().bind (service )
95
112
# If the service is remote need to write out.
0 commit comments