2019-07-05 13:25:59 +00:00
|
|
|
class FSMUpdater:
|
|
|
|
def __init__(self, fsm):
|
|
|
|
self.fsm = fsm
|
|
|
|
|
|
|
|
@property
|
|
|
|
def fsm_update(self):
|
|
|
|
return {
|
2019-08-08 12:45:59 +00:00
|
|
|
'key': 'fsm.update',
|
2019-07-12 21:25:16 +00:00
|
|
|
**self.fsm_update_data
|
2019-07-05 13:25:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@property
|
|
|
|
def fsm_update_data(self):
|
|
|
|
valid_transitions = [
|
|
|
|
{'trigger': trigger}
|
|
|
|
for trigger in self.fsm.get_triggers(self.fsm.state)
|
|
|
|
]
|
2019-08-23 13:27:03 +00:00
|
|
|
if not self.fsm.event_log:
|
2019-08-26 09:10:39 +00:00
|
|
|
return None
|
2019-07-05 13:25:59 +00:00
|
|
|
last_fsm_event = self.fsm.event_log[-1]
|
|
|
|
return {
|
|
|
|
'current_state': self.fsm.state,
|
|
|
|
'valid_transitions': valid_transitions,
|
|
|
|
'in_accepted_state': self.fsm.in_accepted_state,
|
|
|
|
'last_event': last_fsm_event
|
|
|
|
}
|