From de8c2ae6e2403c260e9d827536ccc19271a05625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 6 Apr 2018 17:09:35 +0200 Subject: [PATCH] Implement FSMUpdates to EventHandlers --- lib/tfw/networking/server/tfw_server.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/tfw/networking/server/tfw_server.py b/lib/tfw/networking/server/tfw_server.py index d9e3f00..d6e6889 100644 --- a/lib/tfw/networking/server/tfw_server.py +++ b/lib/tfw/networking/server/tfw_server.py @@ -43,6 +43,7 @@ class TFWServer: self._fsm_manager.trigger(trigger, message) except AttributeError: LOG.debug('FSM failed to execute nonexistent trigger: "%s"', trigger) + message['FSMUpdate'] = self._fsm_updater.get_fsm_state_and_transitions() return message def proxy_filter(self, message): @@ -95,7 +96,10 @@ class FSMUpdater: def generate_fsm_update(self): key = 'FSMUpdate' - response = {'data': {'current_state': self.fsm.state, - 'valid_transitions': - [{'trigger': trigger} for trigger in self.fsm.machine.get_triggers(self.fsm.state)]}} + response = {'data': self.get_fsm_state_and_transitions()} return key, response + + def get_fsm_state_and_transitions(self): + state = self.fsm.state + valid_transitions = [{'trigger': trigger} for trigger in self.fsm.machine.get_triggers(self.fsm.state)] + return {'current_state': state, 'valid_transitions': valid_transitions}