Move FSM initialization out of ZMQWebSocketHandler

This commit is contained in:
Bálint Bokros 2017-11-27 18:45:58 +01:00
parent 8d8f55bbe6
commit 638c1b96ae
2 changed files with 5 additions and 4 deletions

View File

@ -23,3 +23,6 @@ class Buttons:
def forward_message(self, event_data):
message = event_data.kwargs.get('message')
component_connector.send_message(message)
fsm = Buttons()

View File

@ -1,17 +1,15 @@
import logging
from tornado.websocket import WebSocketHandler
from buttons import Buttons
from util import parse_anchor_from_message
from buttons import fsm
import component_connector
class ZMQWebSocketHandler(WebSocketHandler):
def __init__(self, application, request, **kwargs):
super().__init__(application, request, **kwargs)
self.fsm = Buttons(self)
def open(self, *args, **kwargs):
def zmq_callback(msg_parts):
@ -23,7 +21,7 @@ class ZMQWebSocketHandler(WebSocketHandler):
def on_message(self, message):
logging.debug('Received on WebSocket: {}'.format(message))
self.fsm.trigger(self._parse_anchor(message), message=message)
fsm.trigger(parse_anchor_from_message(message), message=message)
def send_message(self, message: str, anchor: str = None):
component_connector.send_message(message, anchor)