10
10
11
11
"""
12
12
13
+ from __future__ import annotations
14
+
13
15
from . import Attribute
14
16
from . import Characteristic
15
17
18
+ try :
19
+ from typing import Optional , Type , Union , TYPE_CHECKING
20
+
21
+ if TYPE_CHECKING :
22
+ from circuitpython_typing import ReadableBuffer
23
+ from adafruit_ble .uuid import UUID
24
+ from adafruit_ble .services import Service
25
+
26
+ except ImportError :
27
+ pass
28
+
16
29
__version__ = "0.0.0-auto.0"
17
30
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BLE.git"
18
31
@@ -23,12 +36,12 @@ class StringCharacteristic(Characteristic):
23
36
def __init__ (
24
37
self ,
25
38
* ,
26
- uuid = None ,
27
- properties = Characteristic .READ ,
28
- read_perm = Attribute .OPEN ,
29
- write_perm = Attribute .OPEN ,
30
- initial_value = None
31
- ):
39
+ uuid : Optional [ UUID ] = None ,
40
+ properties : int = Characteristic .READ ,
41
+ read_perm : int = Attribute .OPEN ,
42
+ write_perm : int = Attribute .OPEN ,
43
+ initial_value : Optional [ ReadableBuffer ] = None ,
44
+ ) -> None :
32
45
super ().__init__ (
33
46
uuid = uuid ,
34
47
properties = properties ,
@@ -39,19 +52,23 @@ def __init__(
39
52
initial_value = initial_value ,
40
53
)
41
54
42
- def __get__ (self , obj , cls = None ):
55
+ def __get__ (
56
+ self , obj : Optional [Service ], cls : Optional [Type [Service ]] = None
57
+ ) -> Union [str , "StringCharacteristic" ]:
43
58
if obj is None :
44
59
return self
45
60
return str (super ().__get__ (obj , cls ), "utf-8" )
46
61
47
- def __set__ (self , obj , value ) :
62
+ def __set__ (self , obj : Service , value : str ) -> None :
48
63
super ().__set__ (obj , value .encode ("utf-8" ))
49
64
50
65
51
66
class FixedStringCharacteristic (Characteristic ):
52
67
"""Fixed strings are set once when bound and unchanged after."""
53
68
54
- def __init__ (self , * , uuid = None , read_perm = Attribute .OPEN ):
69
+ def __init__ (
70
+ self , * , uuid : Optional [UUID ] = None , read_perm : int = Attribute .OPEN
71
+ ) -> None :
55
72
super ().__init__ (
56
73
uuid = uuid ,
57
74
properties = Characteristic .READ ,
@@ -60,7 +77,9 @@ def __init__(self, *, uuid=None, read_perm=Attribute.OPEN):
60
77
fixed_length = True ,
61
78
)
62
79
63
- def __get__ (self , obj , cls = None ):
80
+ def __get__ (
81
+ self , obj : Service , cls : Optional [Type [Service ]] = None
82
+ ) -> Union [str , "FixedStringCharacteristic" ]:
64
83
if obj is None :
65
84
return self
66
85
return str (super ().__get__ (obj , cls ), "utf-8" )
0 commit comments