22
22
https://github.com/adafruit/circuitpython/releases
23
23
24
24
"""
25
+ try :
26
+ from typing import Optional , Tuple
27
+ import _bleio
28
+ from circuitpython_typing import ReadableBuffer
29
+ except ImportError :
30
+ pass
31
+
32
+
25
33
import time
26
34
import struct
27
35
from micropython import const
@@ -60,7 +68,7 @@ class _RadioAdvertisement(Advertisement):
60
68
)
61
69
62
70
@classmethod
63
- def matches (cls , entry ) :
71
+ def matches (cls , entry : _bleio . ScanEntry ) -> bool :
64
72
"""Checks for ID matches"""
65
73
if len (entry .advertisement_bytes ) < 6 :
66
74
return False
@@ -71,14 +79,14 @@ def matches(cls, entry):
71
79
)
72
80
73
81
@property
74
- def msg (self ):
82
+ def msg (self ) -> ReadableBuffer :
75
83
"""Raw radio data"""
76
84
if _RADIO_DATA_ID not in self .manufacturer_data .data :
77
85
return b""
78
86
return self .manufacturer_data .data [_RADIO_DATA_ID ]
79
87
80
88
@msg .setter
81
- def msg (self , value ) :
89
+ def msg (self , value : ReadableBuffer ) -> None :
82
90
self .manufacturer_data .data [_RADIO_DATA_ID ] = value
83
91
84
92
@@ -104,7 +112,7 @@ def __init__(self, **args):
104
112
# Handle user related configuration.
105
113
self .configure (** args )
106
114
107
- def configure (self , channel = 42 ):
115
+ def configure (self , channel : int = 42 ) -> None :
108
116
"""
109
117
Set configuration values for the radio.
110
118
@@ -116,7 +124,7 @@ def configure(self, channel=42):
116
124
else :
117
125
raise ValueError ("Channel must be in range 0-255" )
118
126
119
- def send (self , message ) :
127
+ def send (self , message : str ) -> None :
120
128
"""
121
129
Send a message string on the channel to which the radio is
122
130
broadcasting.
@@ -125,7 +133,7 @@ def send(self, message):
125
133
"""
126
134
return self .send_bytes (message .encode ("utf-8" ))
127
135
128
- def send_bytes (self , message ) :
136
+ def send_bytes (self , message : bytes ) -> None :
129
137
"""
130
138
Send bytes on the channel to which the radio is broadcasting.
131
139
@@ -144,7 +152,7 @@ def send_bytes(self, message):
144
152
time .sleep (AD_DURATION )
145
153
self .ble .stop_advertising ()
146
154
147
- def receive (self , timeout = 1 ) :
155
+ def receive (self , timeout : float = 1.0 ) -> str :
148
156
"""
149
157
Returns a message received on the channel on which the radio is
150
158
listening.
@@ -158,7 +166,9 @@ def receive(self, timeout=1):
158
166
return msg [0 ].decode ("utf-8" ).replace ("\x00 " , "" )
159
167
return None
160
168
161
- def receive_full (self , timeout = 1 ):
169
+ def receive_full (
170
+ self , timeout : float = 1.0
171
+ ) -> Optional [Tuple [ReadableBuffer , int , float ]]:
162
172
"""
163
173
Returns a tuple containing three values representing a message received
164
174
on the channel on which the radio is listening. If no message was
0 commit comments