@@ -107,7 +107,6 @@ def _on_connect_mqtt(self, client, userdata, flags, rc):
107
107
self ._client ._logger .debug ('Client called on_connect.' )
108
108
if rc == 0 :
109
109
self ._connected = True
110
- print ('Connected to Adafruit IO!' )
111
110
else :
112
111
raise AdafruitIO_MQTTError (rc )
113
112
# Call the user-defined on_connect callback if defined
@@ -138,8 +137,7 @@ def _on_message_mqtt(self, client, topic, payload):
138
137
# Parse the MQTT topic string
139
138
topic_name = topic .split ('/' )
140
139
if topic_name [1 ] == "groups" :
141
- # Adafruit IO Group Feed Parsing
142
- # May have rx'd more than one feed - parse them.
140
+ # Adafruit IO Group Feed(s)
143
141
feeds = []
144
142
messages = []
145
143
payload = eval (payload )
@@ -150,9 +148,13 @@ def _on_message_mqtt(self, client, topic, payload):
150
148
messages .append (payload )
151
149
topic_name = feeds
152
150
message = messages
151
+ elif topic_name [0 ] == "time" :
152
+ # Adafruit IO Time Topic
153
+ topic_name = topic_name [1 ]
154
+ message = payload
153
155
else :
156
+ # Standard Adafruit IO Feed
154
157
topic_name = topic_name [2 ]
155
- # parse the payload
156
158
message = '' if payload is None else message
157
159
else :
158
160
raise ValueError ('You must define an on_message method before calling this callback.' )
@@ -191,7 +193,6 @@ def subscribe(self, feed_key=None, group_key=None, shared_user=None):
191
193
192
194
client.subscribe([('temperature'), ('humidity')])
193
195
"""
194
- print ('sub called!' )
195
196
if shared_user is not None and feed_key is not None :
196
197
self ._client .subscribe ('{0}/feeds/{1}' .format (shared_user , feed_key ))
197
198
elif group_key is not None :
@@ -227,6 +228,19 @@ def subscribe_to_weather(self, integration_id, forecast_type):
227
228
"""
228
229
self ._client .subscribe ('{0}/integration/weather/{1}/{2}' .format (self ._user , integration_id , forecast_type ))
229
230
231
+ def subscribe_to_time (self , time_type ):
232
+ """Adafruit IO provides some built-in MQTT topics for getting the current server time.
233
+ :param str time_type: Current Adafruit IO server time. Can be `seconds`, `millis`, or `iso`.
234
+ Information about these topics can be found on the Adafruit IO MQTT API Docs.:
235
+ https://io.adafruit.com/api/docs/mqtt.html#time-topics
236
+ """
237
+ if time_type == 'seconds' or time_type == 'millis' :
238
+ self ._client .subscribe ('time/' + time_type )
239
+ elif time_type == 'iso' :
240
+ self ._client .subscribe ('time/ISO-8601' )
241
+ else :
242
+ raise TypeError ('Invalid time feed type specified' )
243
+
230
244
def unsubscribe (self , feed_key = None , group_key = None , shared_user = None ):
231
245
"""Unsubscribes from an Adafruit IO feed or group.
232
246
Can also subscribe to someone else's feed.
0 commit comments