I am using pytransitions with a state machine for example
from transitions import Machine
from transitions import EventData
class Matter(object):
def __init__(self):
transitions = [
{'trigger': 'heat', 'source': 'solid', 'dest': 'liquid'},
{'trigger': 'heat', 'source': 'liquid', 'dest': 'gas'},
{'trigger': 'cool', 'source': 'gas', 'dest': 'liquid'},
{'trigger': 'cool', 'source': 'liquid', 'dest': 'solid'}
]
self.machine = Machine(
model=self,
states=['solid', 'liquid', 'gas'],
transitions=transitions,
initial='solid',
send_event=True
)
def on_enter_gas(self, event: EventData):
print(f"entering gas from {event.transition.source}")
def on_enter_liquid(self, event: EventData):
print(f"entering liquid from {event.transition.source}")
def on_enter_solid(self, event: EventData):
print(f"entering solid from {event.transition.source}")
I would like to add a state, for which any trigger remains in the same state, without invoking a transition, and without explicitly specifying every possible trigger, and also without ignoring all invalid triggers (as this is very good for debugging).
I would like for example a state crystal
which can be reached by triggering crystalize
from liquid
, for which any event will do nothing.
Can this be achieved with the library?
Another way to phrase this question would be some way to ignore_invalid_triggers=True
only for a specific state, not all states.