23
23
import re
24
24
25
25
try :
26
- from typing import List , Any
26
+ from typing import List , Any , Callable , Optional
27
27
except ImportError :
28
28
pass
29
29
@@ -200,7 +200,7 @@ def _on_unsubscribe_mqtt(self, client, user_data, topic, pid):
200
200
if self .on_unsubscribe is not None :
201
201
self .on_unsubscribe (self , user_data , topic , pid )
202
202
203
- def add_feed_callback (self , feed_key : str , callback_method : str ):
203
+ def add_feed_callback (self , feed_key : str , callback_method : Callable ):
204
204
"""Attaches a callback_method to an Adafruit IO feed.
205
205
The callback_method function is called when a
206
206
new value is written to the feed.
@@ -245,7 +245,10 @@ def loop(self, timeout=1):
245
245
246
246
# Subscriptions
247
247
def subscribe (
248
- self , feed_key : str = None , group_key : str = None , shared_user : str = None
248
+ self ,
249
+ feed_key : str = None ,
250
+ group_key : str = None ,
251
+ shared_user : Optional [str ] = None ,
249
252
):
250
253
"""Subscribes to your Adafruit IO feed or group.
251
254
Can also subscribe to someone else's feed.
@@ -306,7 +309,7 @@ def subscribe_to_weather(self, weather_record: int, forecast: str):
306
309
)
307
310
)
308
311
309
- def subscribe_to_time (self , time_type ):
312
+ def subscribe_to_time (self , time_type : str ):
310
313
"""Adafruit IO provides some built-in MQTT topics for getting the current server time.
311
314
312
315
:param str time_type: Current Adafruit IO server time. Can be 'seconds', 'millis', or 'iso'.
@@ -320,7 +323,10 @@ def subscribe_to_time(self, time_type):
320
323
self ._client .subscribe ("time/" + time_type )
321
324
322
325
def unsubscribe (
323
- self , feed_key : str = None , group_key : str = None , shared_user : str = None
326
+ self ,
327
+ feed_key : str = None ,
328
+ group_key : str = None ,
329
+ shared_user : Optional [str ] = None ,
324
330
):
325
331
"""Unsubscribes from an Adafruit IO feed or group.
326
332
Can also subscribe to someone else's feed.
@@ -387,7 +393,7 @@ def publish_multiple(
387
393
def publish (
388
394
self ,
389
395
feed_key : str ,
390
- data : Any ,
396
+ data : str ,
391
397
metadata : str = None ,
392
398
shared_user : str = None ,
393
399
is_group : bool = False ,
@@ -534,7 +540,7 @@ def _compose_path(self, path: str):
534
540
return "https://io.adafruit.com/api/v2/{0}/{1}" .format (self .username , path )
535
541
536
542
# HTTP Requests
537
- def _post (self , path : str , payload : json ):
543
+ def _post (self , path : str , payload : Any ):
538
544
"""
539
545
POST data to Adafruit IO
540
546
@@ -578,7 +584,11 @@ def _delete(self, path: str):
578
584
579
585
# Data
580
586
def send_data (
581
- self , feed_key : str , data : str , metadata : dict = None , precision : int = None
587
+ self ,
588
+ feed_key : str ,
589
+ data : str ,
590
+ metadata : Optional [dict ] = None ,
591
+ precision : Optional [int ] = None ,
582
592
):
583
593
"""
584
594
Sends value data to a specified Adafruit IO feed.
@@ -712,7 +722,10 @@ def get_feed(self, feed_key: str, detailed: bool = False):
712
722
return self ._get (path )
713
723
714
724
def create_new_feed (
715
- self , feed_key : str , feed_desc : str = None , feed_license : str = None
725
+ self ,
726
+ feed_key : str ,
727
+ feed_desc : Optional [str ] = None ,
728
+ feed_license : Optional [str ] = None ,
716
729
):
717
730
"""
718
731
Creates a new Adafruit IO feed.
@@ -730,8 +743,8 @@ def create_and_get_feed(
730
743
self ,
731
744
feed_key : str ,
732
745
detailed : bool = False ,
733
- feed_desc : str = None ,
734
- feed_license : str = None ,
746
+ feed_desc : Optional [ str ] = None ,
747
+ feed_license : Optional [ str ] = None ,
735
748
):
736
749
"""
737
750
Attempts to return a feed; if the feed does not exist, it is created, and then returned.
0 commit comments