Expose TFWServer.fsm_manager as a property

This commit is contained in:
Kristóf Tóth 2018-02-27 13:39:31 +01:00
parent 770123310a
commit f21036091c

View File

@ -12,9 +12,9 @@ log = logging.getLogger(__name__)
class TFWServer: class TFWServer:
def __init__(self, fsm_type): def __init__(self, fsm_type):
self._fsm = fsm_type() self._fsm = fsm_type()
self.fsm_updater = FSMUpdater(self._fsm) self._fsm_updater = FSMUpdater(self._fsm)
self.fsm_manager = FSMManager(self._fsm) self._fsm_manager = FSMManager(self._fsm)
self._fsm.subscribe(self.fsm_updater.update) self._fsm.subscribe(self._fsm_updater.update)
self.application = Application( self.application = Application(
[(r'/ws', ZMQWebSocketProxy, {'make_response': self.make_response, [(r'/ws', ZMQWebSocketProxy, {'make_response': self.make_response,
@ -26,9 +26,13 @@ class TFWServer:
def fsm(self): def fsm(self):
return self._fsm return self._fsm
@property
def fsm_manager(self):
return self._fsm_manager
def make_response(self, message): def make_response(self, message):
trigger = message.get('trigger', '') trigger = message.get('trigger', '')
try: self.fsm_manager.trigger(trigger, message) try: self._fsm_manager.trigger(trigger, message)
except AttributeError: log.debug('FSM failed to execute nonexistent trigger: "{}"'.format(trigger)) except AttributeError: log.debug('FSM failed to execute nonexistent trigger: "{}"'.format(trigger))
return message return message