Merge pull request #27 from avatao-content/eh-stateupdates

Implement FSMUpdates to EventHandlers
This commit is contained in:
Bokros Bálint 2018-04-06 17:33:45 +02:00 committed by GitHub
commit 8043338e58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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