2222 https://github.com/adafruit/circuitpython/releases
2323
2424"""
25+ try :
26+ from typing import Optional , Tuple
27+ import _bleio
28+ from circuitpython_typing import ReadableBuffer
29+ except ImportError :
30+ pass
31+
32+
2533import time
2634import struct
2735from micropython import const
@@ -60,7 +68,7 @@ class _RadioAdvertisement(Advertisement):
6068 )
6169
6270 @classmethod
63- def matches (cls , entry ) :
71+ def matches (cls , entry : _bleio . ScanEntry ) -> bool :
6472 """Checks for ID matches"""
6573 if len (entry .advertisement_bytes ) < 6 :
6674 return False
@@ -71,14 +79,14 @@ def matches(cls, entry):
7179 )
7280
7381 @property
74- def msg (self ):
82+ def msg (self ) -> ReadableBuffer :
7583 """Raw radio data"""
7684 if _RADIO_DATA_ID not in self .manufacturer_data .data :
7785 return b""
7886 return self .manufacturer_data .data [_RADIO_DATA_ID ]
7987
8088 @msg .setter
81- def msg (self , value ) :
89+ def msg (self , value : ReadableBuffer ) -> None :
8290 self .manufacturer_data .data [_RADIO_DATA_ID ] = value
8391
8492
@@ -104,7 +112,7 @@ def __init__(self, **args):
104112 # Handle user related configuration.
105113 self .configure (** args )
106114
107- def configure (self , channel = 42 ):
115+ def configure (self , channel : int = 42 ) -> None :
108116 """
109117 Set configuration values for the radio.
110118
@@ -116,7 +124,7 @@ def configure(self, channel=42):
116124 else :
117125 raise ValueError ("Channel must be in range 0-255" )
118126
119- def send (self , message ) :
127+ def send (self , message : str ) -> None :
120128 """
121129 Send a message string on the channel to which the radio is
122130 broadcasting.
@@ -125,7 +133,7 @@ def send(self, message):
125133 """
126134 return self .send_bytes (message .encode ("utf-8" ))
127135
128- def send_bytes (self , message ) :
136+ def send_bytes (self , message : bytes ) -> None :
129137 """
130138 Send bytes on the channel to which the radio is broadcasting.
131139
@@ -144,7 +152,7 @@ def send_bytes(self, message):
144152 time .sleep (AD_DURATION )
145153 self .ble .stop_advertising ()
146154
147- def receive (self , timeout = 1 ) :
155+ def receive (self , timeout : float = 1.0 ) -> str :
148156 """
149157 Returns a message received on the channel on which the radio is
150158 listening.
@@ -158,7 +166,9 @@ def receive(self, timeout=1):
158166 return msg [0 ].decode ("utf-8" ).replace ("\x00 " , "" )
159167 return None
160168
161- def receive_full (self , timeout = 1 ):
169+ def receive_full (
170+ self , timeout : float = 1.0
171+ ) -> Optional [Tuple [ReadableBuffer , int , float ]]:
162172 """
163173 Returns a tuple containing three values representing a message received
164174 on the channel on which the radio is listening. If no message was
0 commit comments