target state in an transition before or after callback #681
Replies: 2 comments
-
Hello @spitzlbergerj, maybe
from transitions import Machine
from transitions.core import EventData
class Model:
def before_cb(self, event_data: EventData) -> None:
print("===== Before Transition ====")
print(f"Trigger: {event_data.event.name}")
print(f"Source: {event_data.transition.source}")
print(f"Dest: {event_data.transition.dest}")
print(f"Args: {event_data.args}")
print(f"Kwargs: {event_data.kwargs}")
print("-" * 28)
states = ["A", "B", "C"]
transitions = [{"trigger": "go", "source": "A", "dest": "B", "before": "before_cb"},
{"trigger": "go", "source": "B", "dest": "C", "before": "before_cb"}]
model = Model()
machine = Machine(model, states=states, transitions=transitions, send_event=True, initial="A")
model.go(1, fast=False)
model.go(super_fast=True, power=42) |
Beta Was this translation helpful? Give feedback.
-
Thank you very much, @aleneum , I discovered this option yesterday evening and was already on this track. Your code snippet helps me a lot because I had not found what structure event has and how to access individual parts. So thank you very much Best regards |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm new to using the transitions library, but I'm getting along quite well.
I have the following definition of states and transitions
I would now like to know in the callbacks before_move and move_motor which target status should be changed to. For this I would need either the trigger or the target status.
Unfortunately, I can't get any further at this point? How do I query trigger or target status?
Thank you very much!
Grüße
Sepp
Beta Was this translation helpful? Give feedback.
All reactions