Files
picar/DecisionSystem/mqttvoter.py
2018-12-18 10:13:18 +10:30

32 lines
953 B
Python

from DecisionSystem.voter import Voter
import Messaging.mqttsession as ms
from Messaging.packmessage import PackMessage
from DecisionSystem.vote import Vote
class MqttVoter(Voter):
def __init__(self, host = "10.0.123.11"):
# 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.connect()
def submit_vote(self):
pass
def set_vote(self, vote):
if isinstance(vote, Vote):
self._vote = vote
return True
else:
return False
def get_vote(self):
return self._vote
# This is meant to be the mqtt callback... Should've documented this earlier.
def request_vote(self, client, userdata, message):
# Perhaps do some checking to see what is being voted on...
self.submit_vote()