Implementing stuff (I suck at commits sometimes lol)
This commit is contained in:
@@ -1,6 +1,35 @@
|
||||
import Messaging.mqttsession as ms
|
||||
import time
|
||||
import umsgpack
|
||||
|
||||
class Commander:
|
||||
def get_votes(self):
|
||||
raise Exception("Vote cannot be submitted as it's not implemented")
|
||||
|
||||
def __init__(self, timeout = 60):
|
||||
self.timeout = timeout
|
||||
self._votes = []
|
||||
self._client = ms.Client()
|
||||
|
||||
def on_message(client, userdata, message):
|
||||
self._votes.append(umsgpack.unpackb(message.payload))
|
||||
|
||||
self.add_subscription("FakeSwarm/FirstTest", on_message)
|
||||
|
||||
self._client.loop_start()
|
||||
|
||||
def get_votes(self, topic, message, qos=0):
|
||||
# Publish a message that votes are needed.
|
||||
ms.client.publish(topic, message, qos)
|
||||
time.sleep(self.timeout)
|
||||
make_decision()
|
||||
|
||||
def make_decision(self):
|
||||
raise Exception("Vote cannot be submitted as it's not implemented")
|
||||
votes = self._votes
|
||||
|
||||
for vote in votes:
|
||||
continue
|
||||
|
||||
def add_subscription(self, topic, callback=None, qos=0):
|
||||
self._client.subscribe(topic)
|
||||
|
||||
if callback is not None:
|
||||
self._client.message_callback_add(topic, callback)
|
||||
Reference in New Issue
Block a user