33
33
from adafruit_portalbase .network import NetworkBase
34
34
from adafruit_portalbase .wifi_esp32s2 import WiFi
35
35
36
+ try :
37
+ from typing import Optional , Union
38
+ from adafruit_dotstar import DotStar
39
+ except ImportError :
40
+ pass
41
+
36
42
__version__ = "0.0.0-auto.0"
37
43
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FunHouse.git"
38
44
@@ -54,9 +60,9 @@ class Network(NetworkBase):
54
60
def __init__ (
55
61
self ,
56
62
* ,
57
- status_dotstar = None ,
58
- extract_values = True ,
59
- debug = False ,
63
+ status_dotstar : Optional [ DotStar ] = None ,
64
+ extract_values : bool = True ,
65
+ debug : bool = False ,
60
66
):
61
67
super ().__init__ (
62
68
WiFi (status_led = status_dotstar ),
@@ -65,7 +71,7 @@ def __init__(
65
71
)
66
72
self ._mqtt_client = None
67
73
68
- def init_io_mqtt (self ):
74
+ def init_io_mqtt (self ) -> IO_MQTT :
69
75
"""Initialize MQTT for Adafruit IO"""
70
76
try :
71
77
aio_username = self ._secrets ["aio_username" ]
@@ -80,12 +86,12 @@ def init_io_mqtt(self):
80
86
# pylint: disable=too-many-arguments
81
87
def init_mqtt (
82
88
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 , IO_MQTT ] :
89
95
"""Initialize MQTT"""
90
96
self .connect ()
91
97
self ._mqtt_client = MQTT .MQTT (
@@ -103,12 +109,12 @@ def init_mqtt(
103
109
104
110
# pylint: enable=too-many-arguments
105
111
106
- def _get_mqtt_client (self ):
112
+ def _get_mqtt_client (self ) -> Union [ MQTT , IO_MQTT ] :
107
113
if self ._mqtt_client is not None :
108
114
return self ._mqtt_client
109
115
raise RuntimeError ("Please initialize MQTT before using" )
110
116
111
- def mqtt_loop (self , * args , suppress_mqtt_errors = True , ** kwargs ):
117
+ def mqtt_loop (self , * args : int , suppress_mqtt_errors : bool = True , ** kwargs : int ):
112
118
"""Run the MQTT Loop"""
113
119
self ._get_mqtt_client ()
114
120
if suppress_mqtt_errors :
@@ -123,7 +129,7 @@ def mqtt_loop(self, *args, suppress_mqtt_errors=True, **kwargs):
123
129
if self ._mqtt_client is not None :
124
130
self ._mqtt_client .loop (* args , ** kwargs )
125
131
126
- def mqtt_publish (self , * args , suppress_mqtt_errors = True , ** kwargs ):
132
+ def mqtt_publish (self , * args : Union [ str , int , float ], suppress_mqtt_errors : bool = True , ** kwargs : Union [ str , int , float ] ):
127
133
"""Publish to MQTT"""
128
134
self ._get_mqtt_client ()
129
135
if suppress_mqtt_errors :
@@ -136,7 +142,7 @@ def mqtt_publish(self, *args, suppress_mqtt_errors=True, **kwargs):
136
142
if self ._mqtt_client is not None :
137
143
self ._mqtt_client .publish (* args , ** kwargs )
138
144
139
- def mqtt_connect (self , * args , ** kwargs ):
145
+ def mqtt_connect (self , * args : Union [ bool , str , int ], ** kwargs : Union [ bool , str , int ] ):
140
146
"""Connect to MQTT"""
141
147
self ._get_mqtt_client ()
142
148
if self ._mqtt_client is not None :
@@ -153,7 +159,7 @@ def on_mqtt_connect(self):
153
159
return None
154
160
155
161
@on_mqtt_connect .setter
156
- def on_mqtt_connect (self , value ):
162
+ def on_mqtt_connect (self , value : function ):
157
163
self ._get_mqtt_client ()
158
164
self ._mqtt_client .on_connect = value
159
165
@@ -168,7 +174,7 @@ def on_mqtt_disconnect(self):
168
174
return None
169
175
170
176
@on_mqtt_disconnect .setter
171
- def on_mqtt_disconnect (self , value ):
177
+ def on_mqtt_disconnect (self , value : function ):
172
178
self ._get_mqtt_client ().on_disconnect = value
173
179
174
180
@property
@@ -182,7 +188,7 @@ def on_mqtt_subscribe(self):
182
188
return None
183
189
184
190
@on_mqtt_subscribe .setter
185
- def on_mqtt_subscribe (self , value ):
191
+ def on_mqtt_subscribe (self , value : function ):
186
192
self ._get_mqtt_client ().on_subscribe = value
187
193
188
194
@property
@@ -196,7 +202,7 @@ def on_mqtt_unsubscribe(self):
196
202
return None
197
203
198
204
@on_mqtt_unsubscribe .setter
199
- def on_mqtt_unsubscribe (self , value ):
205
+ def on_mqtt_unsubscribe (self , value : function ):
200
206
self ._get_mqtt_client ().on_unsubscribe = value
201
207
202
208
@property
@@ -210,7 +216,7 @@ def on_mqtt_message(self):
210
216
return None
211
217
212
218
@on_mqtt_message .setter
213
- def on_mqtt_message (self , value ):
219
+ def on_mqtt_message (self , value : function ):
214
220
self ._get_mqtt_client ().on_message = value
215
221
216
222
@property
@@ -222,5 +228,5 @@ def enabled(self):
222
228
return self ._wifi .enabled
223
229
224
230
@enabled .setter
225
- def enabled (self , value ):
231
+ def enabled (self , value : bool ):
226
232
self ._wifi .enabled = bool (value )
0 commit comments