Skip to content

Commit 03ad60d

Browse files
committed
Add simple support for iterator-based event subscription
1 parent 190b045 commit 03ad60d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

traeger.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import uuid
1515
import urllib
1616
import json
17-
17+
import queue
1818

1919
CLIENT_ID = "2fuohjtqv1e63dckp5v84rau0j"
2020

@@ -112,3 +112,13 @@ def get_grill_status(self, timeout = 10):
112112
time.sleep(1)
113113
remaining -= 1
114114
return self.grill_status
115+
116+
def grill_status_subscription(self):
117+
sub_queue = queue.Queue()
118+
def handle_message(client, userdata, message):
119+
sub_queue.put(json.loads(message.payload))
120+
client = self.get_mqtt_client(self.grill_connect, handle_message)
121+
for grill in self.grills:
122+
client.subscribe(("prod/thing/update/{}".format(grill["thingName"]),1))
123+
while True:
124+
yield sub_queue.get()

0 commit comments

Comments
 (0)