mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-06 00:01:20 +00:00
21 lines
708 B
Python
21 lines
708 B
Python
|
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)
|