Skip to content

Commit 54f8790

Browse files
author
brentru
committed
consolidate group_publish into publish method
1 parent 3d43570 commit 54f8790

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

Adafruit_IO/mqtt_client.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def subscribe_group(self, group_id):
195195
"""Subscribe to changes on the specified group. When the group is updated
196196
the on_message function will be called with the group_id and the new value.
197197
"""
198-
self._client.subscribe('{0}/groups/{1}'.format(self._username, group_id))
198+
self._client.subscribe('{0}/groups/{1}'.format(self._username, group_id))
199199

200200
def subscribe_time(self, time):
201201
"""Subscribe to changes on the Adafruit IO time feeds. When the feed is
@@ -226,23 +226,21 @@ def unsubscribe(self, feed_id=None, group_id=None):
226226
raise TypeError('Invalid topic type specified.')
227227
return
228228

229-
def publish_group(self, group_id, feed_id, value=None):
230-
"""Publish a value to a specified feed within a group
231-
"""
232-
pub_string = '{0}/feeds/{1}.{2}'.format(self._username, group_id, feed_id)
233-
self._client.publish('{0}/feeds/{1}.{2}'.format(self._username, group_id, feed_id), payload=value)
234-
235-
def publish(self, feed_id, value=None, feed_user=None):
229+
def publish(self, feed_id, value=None, group_id=None, feed_user=None):
236230
"""Publish a value to a specified feed.
237231
238232
Params:
239233
- feed_id: The id of the feed to update.
240-
- feed_user (optional): The user id of the feed. Used for feed sharing.
241234
- value: The new value to publish to the feed.
235+
- (optional) group_id: The id of the group to update.
236+
- (optional) feed_user: The feed owner's username. Used for Sharing Feeds.
242237
"""
243-
if feed_user is not None:
244-
(res, self._pub_mid) = self._client.publish('{0}/feeds/{1}'.format(feed_user, feed_id),
245-
payload=value)
246-
else:
247-
(res, self._pub_mid) = self._client.publish('{0}/feeds/{1}'.format(self._username, feed_id),
248-
payload=value)
238+
if feed_user is not None: # shared feed
239+
(res, self._pub_mid) = self._client.publish('{0}/feeds/{1}'.format(feed_user, feed_id),
240+
payload=value)
241+
elif group_id is not None: # group-specified feed
242+
self._client.publish('{0}/feeds/{1}.{2}'.format(self._username, group_id, feed_id),
243+
payload=value)
244+
else: # regular feed
245+
(res, self._pub_mid) = self._client.publish('{0}/feeds/{1}'.format(self._username, feed_id),
246+
payload=value)

0 commit comments

Comments
 (0)