baseimage-tutorial-framework/buttons.py

25 lines
898 B
Python
Raw Normal View History

from transitions import Machine
class Buttons:
states = ['ayy', 'bee', 'cee']
transitions = [
{'trigger': 'anchor_a', 'source': 'ayy', 'dest': 'bee'},
{'trigger': 'anchor_b', 'source': 'bee', 'dest': 'cee'},
{'trigger': 'anchor_c', 'source': 'cee', 'dest': 'ayy'},
]
def __init__(self, handler=None):
self.handler = handler
self.machine = Machine(model=self,
states=Buttons.states,
transitions=Buttons.transitions,
initial='ayy',
send_event=True,
ignore_invalid_triggers=True,
after_state_change='forward_message')
def forward_message(self, event_data):
message = event_data.kwargs.get('message')
self.handler.send_message(message)