baseimage-tutorial-framework/src/app/fsm_base.py

21 lines
708 B
Python
Raw Normal View History

from transitions import Machine
import event_handler_connector
class FSMBase:
states, transitions = [], []
def __init__(self, initial: str = None):
self.machine = Machine(model=self,
states=self.states,
transitions=self.transitions,
initial=initial or self.states[0],
send_event=True,
ignore_invalid_triggers=True,
after_state_change='forward_message')
def forward_message(self, event_data):
message = event_data.kwargs.get('message')
event_handler_connector.send_message(message)