mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-23 12:51:32 +00:00
27 lines
723 B
Python
27 lines
723 B
Python
class FSMUpdater:
|
|
def __init__(self, fsm):
|
|
self.fsm = fsm
|
|
|
|
@property
|
|
def fsm_update(self):
|
|
return {
|
|
'key': 'fsm.update',
|
|
**self.fsm_update_data
|
|
}
|
|
|
|
@property
|
|
def fsm_update_data(self):
|
|
valid_transitions = [
|
|
{'trigger': trigger}
|
|
for trigger in self.fsm.get_triggers(self.fsm.state)
|
|
]
|
|
if not self.fsm.event_log:
|
|
return None
|
|
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
|
|
}
|