adding group publishing, unsubscribe support for groups
This commit is contained in:
parent
7d0b95133d
commit
3d43570cec
1 changed files with 17 additions and 5 deletions
|
|
@ -213,12 +213,24 @@ class MQTTClient(object):
|
||||||
raise TypeError('Invalid Time Feed Specified.')
|
raise TypeError('Invalid Time Feed Specified.')
|
||||||
return
|
return
|
||||||
|
|
||||||
def unsubscribe(self, feed_id):
|
def unsubscribe(self, feed_id=None, group_id=None):
|
||||||
"""Unsubscribes from a specified MQTT feed.
|
"""Unsubscribes from a specified MQTT topic.
|
||||||
Note: this does not prevent publishing to a feed, it will unsubscribe
|
Note: this does not prevent publishing to a topic, it will unsubscribe
|
||||||
from receiving messages via on_message.
|
from receiving messages via on_message.
|
||||||
"""
|
"""
|
||||||
(res, mid) = self._client.unsubscribe('{0}/feeds/{1}'.format(self._username, feed_id))
|
if feed_id is not None:
|
||||||
|
self._client.unsubscribe('{0}/feeds/{1}'.format(self._username, feed_id))
|
||||||
|
elif group_id is not None:
|
||||||
|
self._client.unsubscribe('{0}/groups/{1}'.format(self._username, group_id))
|
||||||
|
else:
|
||||||
|
raise TypeError('Invalid topic type specified.')
|
||||||
|
return
|
||||||
|
|
||||||
|
def publish_group(self, group_id, feed_id, value=None):
|
||||||
|
"""Publish a value to a specified feed within a group
|
||||||
|
"""
|
||||||
|
pub_string = '{0}/feeds/{1}.{2}'.format(self._username, group_id, feed_id)
|
||||||
|
self._client.publish('{0}/feeds/{1}.{2}'.format(self._username, group_id, feed_id), payload=value)
|
||||||
|
|
||||||
def publish(self, feed_id, value=None, feed_user=None):
|
def publish(self, feed_id, value=None, feed_user=None):
|
||||||
"""Publish a value to a specified feed.
|
"""Publish a value to a specified feed.
|
||||||
|
|
@ -233,4 +245,4 @@ class MQTTClient(object):
|
||||||
payload=value)
|
payload=value)
|
||||||
else:
|
else:
|
||||||
(res, self._pub_mid) = self._client.publish('{0}/feeds/{1}'.format(self._username, feed_id),
|
(res, self._pub_mid) = self._client.publish('{0}/feeds/{1}'.format(self._username, feed_id),
|
||||||
payload=value)
|
payload=value)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue