Implementing stuff (I suck at commits sometimes lol)

This commit is contained in:
DSTO\pivatom
2018-12-13 11:00:27 +10:30
parent 750624fe2b
commit 6f0bd56b4a
9 changed files with 146 additions and 19 deletions

View File

@@ -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)

View File

@@ -0,0 +1,21 @@
from voter import Voter
import Messaging.mqttsession as ms
from Messaging.packmessage import PackMessage
class MqttVoter(Voter):
def __init__(self):
# Should use a factory here to always get the same session.
# Just going to use a singleton for now, as there should only be
# one session in the program.
ms.client = ms.Client()
ms.host = "10.0.123.11"
def submit_vote(self):
pass
def set_vote(self):
pass
def get_vote(self):
pass

View File

@@ -1,16 +1,9 @@
class Vote:
from Messaging.packmessage import PackMessage
class Vote(PackMessage):
def __init__(self, voter, vote):
self._voter = voter
self._vote = vote
@property
def voter(self):
return self._voter
@voter.setter
def voter(self, value):
self._voter = value
@property
def vote(self):
return self._vote
@@ -19,5 +12,23 @@ class Vote:
def vote(self, value):
self._vote = value
def to_string(self):
pass
def serialise(self):
# Still need associated device as well? to know who went the message,
# to check that we don't add too many messages in case of multiple
# sends.
self.message = {"vote": self.vote}
# Call super method equivalent.
super(Vote, self).serialise()
def deserialise(self):
super(Vote, self).deserialise()
if "vote" in self.message:
self.vote = self.message["vote"]
else:
# Do something.
pass

View File

@@ -1,4 +1,7 @@
from Messaging.packmessage import PackMessage
class Voter:
def submit_vote(self):
raise Exception("Vote cannot be submitted as it's not implemented")
def submit_vote(self, vote_contents):
NotImplementedError