10
10
11
11
"""
12
12
13
+ from __future__ import annotations
14
+
13
15
from . import Attribute
14
16
from . import StructCharacteristic
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
@@ -22,16 +35,16 @@ class IntCharacteristic(StructCharacteristic):
22
35
23
36
def __init__ (
24
37
self ,
25
- format_string ,
26
- min_value ,
27
- max_value ,
38
+ format_string : str ,
39
+ min_value : int ,
40
+ max_value : int ,
28
41
* ,
29
- uuid = None ,
30
- properties = 0 ,
31
- read_perm = Attribute .OPEN ,
32
- write_perm = Attribute .OPEN ,
33
- initial_value = None
34
- ):
42
+ uuid : Optional [ UUID ] = None ,
43
+ properties : int = 0 ,
44
+ read_perm : int = Attribute .OPEN ,
45
+ write_perm : int = Attribute .OPEN ,
46
+ initial_value : Optional [ ReadableBuffer ] = None ,
47
+ ) -> None :
35
48
self ._min_value = min_value
36
49
self ._max_value = max_value
37
50
if initial_value is not None :
@@ -48,12 +61,14 @@ def __init__(
48
61
initial_value = initial_value ,
49
62
)
50
63
51
- def __get__ (self , obj , cls = None ):
64
+ def __get__ (
65
+ self , obj : Optional [Service ], cls : Optional [Type [Service ]] = None
66
+ ) -> Union [int , "IntCharacteristic" ]:
52
67
if obj is None :
53
68
return self
54
69
return super ().__get__ (obj )[0 ]
55
70
56
- def __set__ (self , obj , value ) :
71
+ def __set__ (self , obj : Service , value : int ) -> None :
57
72
if not self ._min_value <= value <= self ._max_value :
58
73
raise ValueError ("out of range" )
59
74
super ().__set__ (obj , (value ,))
@@ -63,45 +78,55 @@ class Int8Characteristic(IntCharacteristic):
63
78
"""Int8 number."""
64
79
65
80
# pylint: disable=too-few-public-methods
66
- def __init__ (self , * , min_value = - 128 , max_value = 127 , ** kwargs ):
81
+ def __init__ (
82
+ self , * , min_value : int = - 128 , max_value : int = 127 , ** kwargs
83
+ ) -> None :
67
84
super ().__init__ ("<b" , min_value , max_value , ** kwargs )
68
85
69
86
70
87
class Uint8Characteristic (IntCharacteristic ):
71
88
"""Uint8 number."""
72
89
73
90
# pylint: disable=too-few-public-methods
74
- def __init__ (self , * , min_value = 0 , max_value = 0xFF , ** kwargs ):
91
+ def __init__ (self , * , min_value : int = 0 , max_value : int = 0xFF , ** kwargs ) -> None :
75
92
super ().__init__ ("<B" , min_value , max_value , ** kwargs )
76
93
77
94
78
95
class Int16Characteristic (IntCharacteristic ):
79
96
"""Int16 number."""
80
97
81
98
# pylint: disable=too-few-public-methods
82
- def __init__ (self , * , min_value = - 32768 , max_value = 32767 , ** kwargs ):
99
+ def __init__ (
100
+ self , * , min_value : int = - 32768 , max_value : int = 32767 , ** kwargs
101
+ ) -> None :
83
102
super ().__init__ ("<h" , min_value , max_value , ** kwargs )
84
103
85
104
86
105
class Uint16Characteristic (IntCharacteristic ):
87
106
"""Uint16 number."""
88
107
89
108
# pylint: disable=too-few-public-methods
90
- def __init__ (self , * , min_value = 0 , max_value = 0xFFFF , ** kwargs ):
109
+ def __init__ (
110
+ self , * , min_value : int = 0 , max_value : int = 0xFFFF , ** kwargs
111
+ ) -> None :
91
112
super ().__init__ ("<H" , min_value , max_value , ** kwargs )
92
113
93
114
94
115
class Int32Characteristic (IntCharacteristic ):
95
116
"""Int32 number."""
96
117
97
118
# pylint: disable=too-few-public-methods
98
- def __init__ (self , * , min_value = - 2147483648 , max_value = 2147483647 , ** kwargs ):
119
+ def __init__ (
120
+ self , * , min_value : int = - 2147483648 , max_value : int = 2147483647 , ** kwargs
121
+ ) -> None :
99
122
super ().__init__ ("<i" , min_value , max_value , ** kwargs )
100
123
101
124
102
125
class Uint32Characteristic (IntCharacteristic ):
103
126
"""Uint32 number."""
104
127
105
128
# pylint: disable=too-few-public-methods
106
- def __init__ (self , * , min_value = 0 , max_value = 0xFFFFFFFF , ** kwargs ):
129
+ def __init__ (
130
+ self , * , min_value : int = 0 , max_value : int = 0xFFFFFFFF , ** kwargs
131
+ ) -> None :
107
132
super ().__init__ ("<I" , min_value , max_value , ** kwargs )
0 commit comments