Skip to content

Commit 31efdf8

Browse files
author
brentru
committed
update docstrings
1 parent a6c421b commit 31efdf8

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

adafruit_io/adafruit_io.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
`adafruit_io`
2424
================================================================================
2525
26-
A CircuitPython/Python library for communicating with Adafruit IO
26+
A CircuitPython/Python library for communicating with Adafruit IO over WiFi
2727
2828
* Author(s): Brent Rubell for Adafruit Industries
2929
@@ -66,13 +66,18 @@ def __init__(self, adafruit_io_username, adafruit_io_key, wifi_manager):
6666

6767
@staticmethod
6868
def _create_data(data, metadata):
69+
"""Creates JSON data payload
70+
"""
6971
if metadata is not None:
7072
return {'value':data, 'lat':metadata['lat'], 'lon':metadata['lon'],
7173
'ele':metadata['ele'], 'created_at':metadata['created_at']}
7274
return {'value':data}
7375

7476
@staticmethod
7577
def _handle_error(response):
78+
"""Checks HTTP status codes
79+
and raises errors.
80+
"""
7681
if response.status_code == 429:
7782
raise AdafruitIO_ThrottleError
7883
elif response.status_code == 400:
@@ -81,13 +86,16 @@ def _handle_error(response):
8186
raise AdafruitIO_RequestError(response)
8287

8388
def _compose_path(self, path):
89+
"""Composes a valid API request path.
90+
:param str path: Adafruit IO API URL path.
91+
"""
8492
return "{0}/{1}/{2}/{3}".format('https://io.adafruit.com/api', 'v2', self.username, path)
8593

8694
# HTTP Requests
8795
def _post(self, path, payload):
8896
"""
89-
Send data to Adafruit IO
90-
:param str path: Formatted Adafruit IO URL
97+
POST data to Adafruit IO
98+
:param str path: Formatted Adafruit IO URL from _compose_path
9199
:param json payload: JSON data to send to Adafruit IO
92100
"""
93101
response = self.wifi.post(
@@ -99,8 +107,8 @@ def _post(self, path, payload):
99107

100108
def _get(self, path):
101109
"""
102-
Get data from Adafruit IO
103-
:param str path: Formatted Adafruit IO URL
110+
GET data from Adafruit IO
111+
:param str path: Formatted Adafruit IO URL from _compose_path
104112
"""
105113
response = self.wifi.get(
106114
path,
@@ -110,8 +118,8 @@ def _get(self, path):
110118

111119
def _delete(self, path):
112120
"""
113-
Delete data from Adafruit IO.
114-
:param str path: Formatted Adafruit IO URL
121+
DELETE data from Adafruit IO.
122+
:param str path: Formatted Adafruit IO URL from _compose_path
115123
"""
116124
response = self.wifi.delete(
117125
path,
@@ -122,10 +130,10 @@ def _delete(self, path):
122130
# Data
123131
def send_data(self, feed_key, data, metadata=None):
124132
"""
125-
Sends value data to an Adafruit IO feed.
126-
:param str feed_key: Specified Adafruit IO feed
127-
:param str data: Data to send to an Adafruit IO feed
128-
:param dict metadata: Metadata associated with the data being sent
133+
Sends value data to a specified Adafruit IO feed.
134+
:param str feed_key: Adafruit IO feed key
135+
:param str data: Data to send to the Adafruit IO feed
136+
:param dict metadata: Optional metadata associated with the data
129137
"""
130138
path = self._compose_path("feeds/{0}/data".format(feed_key))
131139
payload = self._create_data(data, metadata)
@@ -134,16 +142,16 @@ def send_data(self, feed_key, data, metadata=None):
134142
def receive_data(self, feed_key):
135143
"""
136144
Return the most recent value for the specified feed.
137-
:param string feed_key: Name/Key/ID of Adafruit IO feed.
145+
:param string feed_key: Adafruit IO feed key
138146
"""
139147
path = self._compose_path("feeds/{0}/data/last".format(feed_key))
140148
return self._get(path)
141149

142150
def delete_data(self, feed_key, data_id):
143151
"""
144-
Delete an existing Data point from a feed.
145-
:param string feed: Feed Key
146-
:param string data_id: Data point to delete
152+
Deletes an existing Data point from a feed.
153+
:param string feed: Adafruit IO feed key
154+
:param string data_id: Data point to delete from the feed
147155
"""
148156
path = self._compose_path("feeds/{0}/data/{1}".format(feed_key, data_id))
149157
return self._delete(path)
@@ -188,9 +196,9 @@ def get_group(self, group_key):
188196
# Feeds
189197
def get_feed(self, feed_key, detailed=False):
190198
"""
191-
Returns feed based on the feed key
192-
:param str feed_key: Feed Key
193-
:param bool detailed: Returns a more detailed feed record
199+
Returns an Adafruit IO feed based on the feed key
200+
:param str feed_key: Adafruit IO Feed Key
201+
:param bool detailed: Returns a more verbose feed record
194202
"""
195203
if detailed:
196204
path = self._compose_path("feeds/{0}/details".format(feed_key))
@@ -200,10 +208,10 @@ def get_feed(self, feed_key, detailed=False):
200208

201209
def create_new_feed(self, feed_key, feed_desc=None, feed_license=None):
202210
"""
203-
Creates a new feed.
204-
:param str feed_key: Feed key
211+
Creates a new Adafruit IO feed.
212+
:param str feed_key: Adafruit IO Feed Key
205213
:param str feed_desc: Optional description of feed
206-
:param str feed_license: Optional feed License
214+
:param str feed_license: Optional feed license
207215
"""
208216
path = self._compose_path("feeds")
209217
payload = {'name':feed_key,

0 commit comments

Comments
 (0)