3333from adafruit_portalbase .network import NetworkBase
3434from adafruit_portalbase .wifi_esp32s2 import WiFi
3535
36+ try :
37+ from typing import Optional , Union , Callable
38+ from adafruit_dotstar import DotStar
39+ except ImportError :
40+ pass
41+
3642__version__ = "0.0.0-auto.0"
3743__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FunHouse.git"
3844
@@ -54,18 +60,18 @@ class Network(NetworkBase):
5460 def __init__ (
5561 self ,
5662 * ,
57- status_dotstar = None ,
58- extract_values = True ,
59- debug = False ,
60- ):
63+ status_dotstar : Optional [ DotStar ] = None ,
64+ extract_values : bool = True ,
65+ debug : bool = False ,
66+ ) -> None :
6167 super ().__init__ (
6268 WiFi (status_led = status_dotstar ),
6369 extract_values = extract_values ,
6470 debug = debug ,
6571 )
6672 self ._mqtt_client = None
6773
68- def init_io_mqtt (self ):
74+ def init_io_mqtt (self ) -> IO_MQTT :
6975 """Initialize MQTT for Adafruit IO"""
7076 try :
7177 aio_username = self ._secrets ["aio_username" ]
@@ -80,12 +86,12 @@ def init_io_mqtt(self):
8086 # pylint: disable=too-many-arguments
8187 def init_mqtt (
8288 self ,
83- broker ,
84- port = 8883 ,
85- username = None ,
86- password = None ,
87- use_io = False ,
88- ):
89+ broker : str ,
90+ port : int = 8883 ,
91+ username : str = None ,
92+ password : str = None ,
93+ use_io : bool = False ,
94+ ) -> Union [ MQTT . MQTT , IO_MQTT ] :
8995 """Initialize MQTT"""
9096 self .connect ()
9197 self ._mqtt_client = MQTT .MQTT (
@@ -103,12 +109,14 @@ def init_mqtt(
103109
104110 # pylint: enable=too-many-arguments
105111
106- def _get_mqtt_client (self ):
112+ def _get_mqtt_client (self ) -> Union [ MQTT . MQTT , IO_MQTT ] :
107113 if self ._mqtt_client is not None :
108114 return self ._mqtt_client
109115 raise RuntimeError ("Please initialize MQTT before using" )
110116
111- def mqtt_loop (self , * args , suppress_mqtt_errors = True , ** kwargs ):
117+ def mqtt_loop (
118+ self , * args : int , suppress_mqtt_errors : bool = True , ** kwargs : int
119+ ) -> None :
112120 """Run the MQTT Loop"""
113121 self ._get_mqtt_client ()
114122 if suppress_mqtt_errors :
@@ -123,7 +131,12 @@ def mqtt_loop(self, *args, suppress_mqtt_errors=True, **kwargs):
123131 if self ._mqtt_client is not None :
124132 self ._mqtt_client .loop (* args , ** kwargs )
125133
126- def mqtt_publish (self , * args , suppress_mqtt_errors = True , ** kwargs ):
134+ def mqtt_publish (
135+ self ,
136+ * args : Union [str , int , float ],
137+ suppress_mqtt_errors : bool = True ,
138+ ** kwargs : Union [str , int , float ]
139+ ) -> None :
127140 """Publish to MQTT"""
128141 self ._get_mqtt_client ()
129142 if suppress_mqtt_errors :
@@ -136,14 +149,16 @@ def mqtt_publish(self, *args, suppress_mqtt_errors=True, **kwargs):
136149 if self ._mqtt_client is not None :
137150 self ._mqtt_client .publish (* args , ** kwargs )
138151
139- def mqtt_connect (self , * args , ** kwargs ):
152+ def mqtt_connect (
153+ self , * args : Union [bool , str , int ], ** kwargs : Union [bool , str , int ]
154+ ) -> None :
140155 """Connect to MQTT"""
141156 self ._get_mqtt_client ()
142157 if self ._mqtt_client is not None :
143158 self ._mqtt_client .connect (* args , ** kwargs )
144159
145160 @property
146- def on_mqtt_connect (self ):
161+ def on_mqtt_connect (self ) -> Optional [ Callable ] :
147162 """
148163 Get or Set the MQTT Connect Handler
149164
@@ -153,12 +168,12 @@ def on_mqtt_connect(self):
153168 return None
154169
155170 @on_mqtt_connect .setter
156- def on_mqtt_connect (self , value ) :
171+ def on_mqtt_connect (self , value : Callable ) -> None :
157172 self ._get_mqtt_client ()
158173 self ._mqtt_client .on_connect = value
159174
160175 @property
161- def on_mqtt_disconnect (self ):
176+ def on_mqtt_disconnect (self ) -> Optional [ Callable ] :
162177 """
163178 Get or Set the MQTT Disconnect Handler
164179
@@ -168,11 +183,11 @@ def on_mqtt_disconnect(self):
168183 return None
169184
170185 @on_mqtt_disconnect .setter
171- def on_mqtt_disconnect (self , value ) :
186+ def on_mqtt_disconnect (self , value : Callable ) -> None :
172187 self ._get_mqtt_client ().on_disconnect = value
173188
174189 @property
175- def on_mqtt_subscribe (self ):
190+ def on_mqtt_subscribe (self ) -> Optional [ Callable ] :
176191 """
177192 Get or Set the MQTT Subscribe Handler
178193
@@ -182,11 +197,11 @@ def on_mqtt_subscribe(self):
182197 return None
183198
184199 @on_mqtt_subscribe .setter
185- def on_mqtt_subscribe (self , value ) :
200+ def on_mqtt_subscribe (self , value : Callable ) -> None :
186201 self ._get_mqtt_client ().on_subscribe = value
187202
188203 @property
189- def on_mqtt_unsubscribe (self ):
204+ def on_mqtt_unsubscribe (self ) -> Optional [ Callable ] :
190205 """
191206 Get or Set the MQTT Unsubscribe Handler
192207
@@ -196,11 +211,11 @@ def on_mqtt_unsubscribe(self):
196211 return None
197212
198213 @on_mqtt_unsubscribe .setter
199- def on_mqtt_unsubscribe (self , value ) :
214+ def on_mqtt_unsubscribe (self , value : Callable ) -> None :
200215 self ._get_mqtt_client ().on_unsubscribe = value
201216
202217 @property
203- def on_mqtt_message (self ):
218+ def on_mqtt_message (self ) -> Optional [ Callable ] :
204219 """
205220 Get or Set the MQTT Message Handler
206221
@@ -210,17 +225,17 @@ def on_mqtt_message(self):
210225 return None
211226
212227 @on_mqtt_message .setter
213- def on_mqtt_message (self , value ) :
228+ def on_mqtt_message (self , value : Callable ) -> None :
214229 self ._get_mqtt_client ().on_message = value
215230
216231 @property
217- def enabled (self ):
232+ def enabled (self ) -> bool :
218233 """
219234 Get or Set whether the WiFi is enabled
220235
221236 """
222237 return self ._wifi .enabled
223238
224239 @enabled .setter
225- def enabled (self , value ) :
240+ def enabled (self , value : bool ) -> None :
226241 self ._wifi .enabled = bool (value )
0 commit comments