35
35
* Adafruit CircuitPython firmware for the supported boards:
36
36
https://github.com/adafruit/circuitpython/releases
37
37
"""
38
- import time
38
+ from time import struct_time
39
39
from adafruit_io .adafruit_io_errors import (
40
40
AdafruitIO_RequestError ,
41
41
AdafruitIO_ThrottleError ,
@@ -66,7 +66,13 @@ def __init__(self, mqtt_client):
66
66
raise TypeError (
67
67
"This class requires a MiniMQTT client object, please create one."
68
68
)
69
- self ._user = self ._client ._user
69
+ # Adafruit IO Auth. requires a username
70
+ try :
71
+ self ._user = self ._client ._user
72
+ except :
73
+ raise TypeError (
74
+ "Adafruit IO requires a username, please set one in MiniMQTT"
75
+ )
70
76
# User-defined MQTT callback methods must be init'd to None
71
77
self .on_connect = None
72
78
self .on_disconnect = None
@@ -142,6 +148,7 @@ def _on_message_mqtt(self, client, topic, payload):
142
148
if self .on_message is not None :
143
149
# Parse the MQTT topic string
144
150
topic_name = topic .split ("/" )
151
+ print (topic_name )
145
152
if topic_name [1 ] == "groups" :
146
153
# Adafruit IO Group Feed(s)
147
154
feeds = []
@@ -162,7 +169,7 @@ def _on_message_mqtt(self, client, topic, payload):
162
169
else :
163
170
# Standard Adafruit IO Feed
164
171
topic_name = topic_name [2 ]
165
- message = "" if payload is None else message
172
+ message = payload
166
173
else :
167
174
raise ValueError (
168
175
"You must define an on_message method before calling this callback."
@@ -592,7 +599,7 @@ def receive_time(self):
592
599
"""
593
600
path = self ._compose_path ("integrations/time/struct.json" )
594
601
time = self ._get (path )
595
- return time . struct_time (
602
+ return struct_time (
596
603
(
597
604
time ["year" ],
598
605
time ["mon" ],
0 commit comments