20
20
from adafruit_ble .advertising import Advertisement , LazyObjectField
21
21
from adafruit_ble .advertising .standard import ManufacturerData , ManufacturerDataField
22
22
23
+ try :
24
+ from typing import Optional
25
+ from _bleio import ScanEntry
26
+ except ImportError :
27
+ pass
28
+
23
29
__version__ = "0.0.0-auto.0"
24
30
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BLE_BroadcastNet.git"
25
31
26
32
_ble = adafruit_ble .BLERadio () # pylint: disable=invalid-name
27
33
_sequence_number = 0 # pylint: disable=invalid-name
28
34
29
35
30
- def broadcast (measurement , * , broadcast_time = 0.1 , extended = False ):
36
+ def broadcast (
37
+ measurement : "AdafruitSensorMeasurement" ,
38
+ * ,
39
+ broadcast_time : float = 0.1 ,
40
+ extended : bool = False
41
+ ) -> None :
31
42
"""Broadcasts the given measurement for the given broadcast time. If extended is False and the
32
- measurement would be too long, it will be split into multiple measurements for transmission.
43
+ measurement would be too long, it will be split into multiple measurements for transmission,
44
+ each with the given broadcast time.
33
45
"""
34
46
global _sequence_number # pylint: disable=global-statement,invalid-name
35
47
for submeasurement in measurement .split (252 if extended else 31 ):
@@ -149,13 +161,15 @@ class AdafruitSensorMeasurement(Advertisement):
149
161
"""Battery voltage in millivolts. Saves two bytes over voltage and is more readable in bare
150
162
packets."""
151
163
152
- def __init__ (self , * , entry = None , sequence_number = 0 ):
164
+ def __init__ (
165
+ self , * , entry : Optional [ScanEntry ] = None , sequence_number : int = 0
166
+ ) -> None :
153
167
super ().__init__ (entry = entry )
154
168
if entry :
155
169
return
156
170
self .sequence_number = sequence_number
157
171
158
- def __str__ (self ):
172
+ def __str__ (self ) -> str :
159
173
parts = []
160
174
for attr in dir (self .__class__ ):
161
175
attribute_instance = getattr (self .__class__ , attr )
@@ -165,7 +179,7 @@ def __str__(self):
165
179
parts .append ("{}={}" .format (attr , str (value )))
166
180
return "<{} {} >" .format (self .__class__ .__name__ , " " .join (parts ))
167
181
168
- def split (self , max_packet_size = 31 ):
182
+ def split (self , max_packet_size : int = 31 ) -> "AdafruitSensorMeasurement" :
169
183
"""Split the measurement into multiple measurements with the given max_packet_size. Yields
170
184
each submeasurement."""
171
185
current_size = 8 # baseline for mfg data and sequence number
0 commit comments