Skip to content

Commit 581dcbc

Browse files
author
brentru
committed
require username, reimport struct time...
1 parent b6830b3 commit 581dcbc

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

adafruit_io/adafruit_io.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* Adafruit CircuitPython firmware for the supported boards:
3636
https://github.com/adafruit/circuitpython/releases
3737
"""
38-
import time
38+
from time import struct_time
3939
from adafruit_io.adafruit_io_errors import (
4040
AdafruitIO_RequestError,
4141
AdafruitIO_ThrottleError,
@@ -66,7 +66,13 @@ def __init__(self, mqtt_client):
6666
raise TypeError(
6767
"This class requires a MiniMQTT client object, please create one."
6868
)
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+
)
7076
# User-defined MQTT callback methods must be init'd to None
7177
self.on_connect = None
7278
self.on_disconnect = None
@@ -142,6 +148,7 @@ def _on_message_mqtt(self, client, topic, payload):
142148
if self.on_message is not None:
143149
# Parse the MQTT topic string
144150
topic_name = topic.split("/")
151+
print(topic_name)
145152
if topic_name[1] == "groups":
146153
# Adafruit IO Group Feed(s)
147154
feeds = []
@@ -162,7 +169,7 @@ def _on_message_mqtt(self, client, topic, payload):
162169
else:
163170
# Standard Adafruit IO Feed
164171
topic_name = topic_name[2]
165-
message = "" if payload is None else message
172+
message = payload
166173
else:
167174
raise ValueError(
168175
"You must define an on_message method before calling this callback."
@@ -592,7 +599,7 @@ def receive_time(self):
592599
"""
593600
path = self._compose_path("integrations/time/struct.json")
594601
time = self._get(path)
595-
return time.struct_time(
602+
return struct_time(
596603
(
597604
time["year"],
598605
time["mon"],

0 commit comments

Comments
 (0)