Replies: 2 comments
-
Just found the solution. I was formally working with the package which was not case sensitive. |
Beta Was this translation helpful? Give feedback.
-
Hello @dedtadeas, as you already figured out from transitions import Machine, State
class LowerCaseState(State):
@property
def name(self):
return super().name.lower()
@property
def value(self):
return super().value.lower()
class LowerCaseMachine(Machine):
state_cls = LowerCaseState
class Model:
def on_enter_final_state(self):
self.to_b()
model = Model()
machine = LowerCaseMachine(model, states=["INIT", "A", "b", "fInAL_sTAtE"], initial="init")
assert model.state == "init"
assert hasattr(model, "to_a")
assert hasattr(model, "to_final_state")
model.to_final_state()
assert model.state == "b"
assert not model.is_final_state()
# just for illustration
assert machine.states["init"]._name == "INIT" You just need to be careful to 'address' states by their normalized/lower case name because even though states still have their original strings internally, class LowerCaseState(State):
def __init__(self, name, on_enter=None, on_exit=None, ignore_invalid_triggers=None):
super().__init__(name.lower(), on_enter=on_enter,
on_exit=on_exit, ignore_invalid_triggers=ignore_invalid_triggers) For |
Beta Was this translation helpful? Give feedback.
-
Hi,
I would like to ask a question, why the run goes only from INITIAL to REQUESTED without triggering on_enter_requested function? Thank you!
Beta Was this translation helpful? Give feedback.
All reactions