Skip to content

Commit d790205

Browse files
committed
typing tweaks
1 parent c7aa888 commit d790205

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

adafruit_io/adafruit_io.py

+24-11
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import re
2424

2525
try:
26-
from typing import List, Any
26+
from typing import List, Any, Callable, Optional
2727
except ImportError:
2828
pass
2929

@@ -200,7 +200,7 @@ def _on_unsubscribe_mqtt(self, client, user_data, topic, pid):
200200
if self.on_unsubscribe is not None:
201201
self.on_unsubscribe(self, user_data, topic, pid)
202202

203-
def add_feed_callback(self, feed_key: str, callback_method: str):
203+
def add_feed_callback(self, feed_key: str, callback_method: Callable):
204204
"""Attaches a callback_method to an Adafruit IO feed.
205205
The callback_method function is called when a
206206
new value is written to the feed.
@@ -245,7 +245,10 @@ def loop(self, timeout=1):
245245

246246
# Subscriptions
247247
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,
249252
):
250253
"""Subscribes to your Adafruit IO feed or group.
251254
Can also subscribe to someone else's feed.
@@ -306,7 +309,7 @@ def subscribe_to_weather(self, weather_record: int, forecast: str):
306309
)
307310
)
308311

309-
def subscribe_to_time(self, time_type):
312+
def subscribe_to_time(self, time_type: str):
310313
"""Adafruit IO provides some built-in MQTT topics for getting the current server time.
311314
312315
: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):
320323
self._client.subscribe("time/" + time_type)
321324

322325
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,
324330
):
325331
"""Unsubscribes from an Adafruit IO feed or group.
326332
Can also subscribe to someone else's feed.
@@ -387,7 +393,7 @@ def publish_multiple(
387393
def publish(
388394
self,
389395
feed_key: str,
390-
data: Any,
396+
data: str,
391397
metadata: str = None,
392398
shared_user: str = None,
393399
is_group: bool = False,
@@ -534,7 +540,7 @@ def _compose_path(self, path: str):
534540
return "https://io.adafruit.com/api/v2/{0}/{1}".format(self.username, path)
535541

536542
# HTTP Requests
537-
def _post(self, path: str, payload: json):
543+
def _post(self, path: str, payload: Any):
538544
"""
539545
POST data to Adafruit IO
540546
@@ -578,7 +584,11 @@ def _delete(self, path: str):
578584

579585
# Data
580586
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,
582592
):
583593
"""
584594
Sends value data to a specified Adafruit IO feed.
@@ -712,7 +722,10 @@ def get_feed(self, feed_key: str, detailed: bool = False):
712722
return self._get(path)
713723

714724
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,
716729
):
717730
"""
718731
Creates a new Adafruit IO feed.
@@ -730,8 +743,8 @@ def create_and_get_feed(
730743
self,
731744
feed_key: str,
732745
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,
735748
):
736749
"""
737750
Attempts to return a feed; if the feed does not exist, it is created, and then returned.

0 commit comments

Comments
 (0)