Skip to content

Commit 3d43570

Browse files
author
brentru
committed
adding group publishing, unsubscribe support for groups
1 parent 7d0b951 commit 3d43570

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

Adafruit_IO/mqtt_client.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,24 @@ def subscribe_time(self, time):
213213
raise TypeError('Invalid Time Feed Specified.')
214214
return
215215

216-
def unsubscribe(self, feed_id):
217-
"""Unsubscribes from a specified MQTT feed.
218-
Note: this does not prevent publishing to a feed, it will unsubscribe
216+
def unsubscribe(self, feed_id=None, group_id=None):
217+
"""Unsubscribes from a specified MQTT topic.
218+
Note: this does not prevent publishing to a topic, it will unsubscribe
219219
from receiving messages via on_message.
220220
"""
221-
(res, mid) = self._client.unsubscribe('{0}/feeds/{1}'.format(self._username, feed_id))
221+
if feed_id is not None:
222+
self._client.unsubscribe('{0}/feeds/{1}'.format(self._username, feed_id))
223+
elif group_id is not None:
224+
self._client.unsubscribe('{0}/groups/{1}'.format(self._username, group_id))
225+
else:
226+
raise TypeError('Invalid topic type specified.')
227+
return
228+
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)
222234

223235
def publish(self, feed_id, value=None, feed_user=None):
224236
"""Publish a value to a specified feed.
@@ -233,4 +245,4 @@ def publish(self, feed_id, value=None, feed_user=None):
233245
payload=value)
234246
else:
235247
(res, self._pub_mid) = self._client.publish('{0}/feeds/{1}'.format(self._username, feed_id),
236-
payload=value)
248+
payload=value)

0 commit comments

Comments
 (0)