Replies: 3 comments
-
Hi @mniemotka, I cannot reproduce your example based on the provided information. Your assumption that an internal transition should not exit nor enter a state is correct. My minimal example works as expected. Codefrom transitions import Machine
import logging
logging.basicConfig(level=logging.DEBUG)
transitions = [
['off_time', 'ON', 'OFF'],
['off_time', 'OFF', None]
]
states = ['ON', 'OFF']
class Model:
def on_enter_OFF(self):
print("OFF ENTERED")
model = Model()
m = Machine(model=model, states=states, transitions=transitions, initial="ON")
model.off_time()
model.off_time() Output
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Alexander,
Thanks so much for the fast response. For sure you are getting the results I would expect. If nothing else, you taught me the logging method, which I think will be SUPER helpful in seeing what might be going on with my code, versus the old school method of a bunch of print statements. I will add logging to my code and report what happens.
Thanks again for your help, and confirming my understanding of how internal transistions should work.
Mike
Yahoo Mail: Search, Organize, Conquer
On Sun, May 26, 2024 at 11:25 AM, Alexander ***@***.***> wrote:
Hi @mniemotka,
I cannot reproduce your example based on the provided information. Your assumption that an internal transition should not exit nor enter a state is correct. My minimal example works as expected.
Code
from transitions import Machine
import logging
logging.basicConfig(level=logging.DEBUG)
transitions = [
['off_time', 'ON', 'OFF'],
['off_time', 'OFF', None]
]
states = ['ON', 'OFF']
class Model:
def on_enter_OFF(self):
print("OFF ENTERED")
model = Model()
m = Machine(model=model, states=states, transitions=transitions, initial="ON")
model.off_time()
model.off_time()
Output
DEBUG:transitions.core:Executed machine preparation callbacks before conditions.
DEBUG:transitions.core:Initiating transition from state ON to state OFF...
DEBUG:transitions.core:Executed callbacks before conditions.
DEBUG:transitions.core:Executed callback before transition.
DEBUG:transitions.core:Exiting state ON. Processing callbacks...
INFO:transitions.core:Finished processing state ON exit callbacks.
DEBUG:transitions.core:Entering state OFF. Processing callbacks...
OFF ENTERED
INFO:transitions.core:Executed callback 'on_enter_OFF'
INFO:transitions.core:Finished processing state OFF enter callbacks.
DEBUG:transitions.core:Executed callback after transition.
DEBUG:transitions.core:Executed machine finalize callbacks
DEBUG:transitions.core:Executed machine preparation callbacks before conditions.
DEBUG:transitions.core:Initiating transition from state OFF to state None...
DEBUG:transitions.core:Executed callbacks before conditions.
DEBUG:transitions.core:Executed callback before transition.
DEBUG:transitions.core:Executed callback after transition.
DEBUG:transitions.core:Executed machine finalize callbacks
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Alexander,
Using logging was the key, as I discovered, as you can see below, that once I was in the scheduled_off state, the was a case where in fact, it does transition to None, as expected, but then later, there is a transition from scheduled_off to scheduled_off..... it turns out that my program has a main loop which first checks to see if the pump should be on or off based on the scheduling dictionary, and THEN it checks the pool temperature compared to the solar panel temperature, and would open or close a valve as result, which is a different transition, to a new state IF the pump is on.
But since the pump is OFF in scheduled_off, then no matter what the temperature check shows, I should stay in scheduled_off, ie an internal transition, but I has that defined as going from scheduled_off TO scheduled_off, so that is why it was happening.
Your help is GREATLY appreciated!
Have a great weekend
Mike
On Sunday, May 26, 2024 at 11:25:15 AM CDT, Alexander Neumann ***@***.***> wrote:
Hi @mniemotka,
I cannot reproduce your example based on the provided information. Your assumption that an internal transition should not exit nor enter a state is correct. My minimal example works as expected.
Code
from transitions import Machine
import logging
logging.basicConfig(level=logging.DEBUG)
transitions = [
['off_time', 'ON', 'OFF'],
['off_time', 'OFF', None]
]
states = ['ON', 'OFF']
class Model:
def on_enter_OFF(self):
print("OFF ENTERED")
model = Model()
m = Machine(model=model, states=states, transitions=transitions, initial="ON")
model.off_time()
model.off_time()
Output
DEBUG:transitions.core:Executed machine preparation callbacks before conditions.
DEBUG:transitions.core:Initiating transition from state ON to state OFF...
DEBUG:transitions.core:Executed callbacks before conditions.
DEBUG:transitions.core:Executed callback before transition.
DEBUG:transitions.core:Exiting state ON. Processing callbacks...
INFO:transitions.core:Finished processing state ON exit callbacks.
DEBUG:transitions.core:Entering state OFF. Processing callbacks...
OFF ENTERED
INFO:transitions.core:Executed callback 'on_enter_OFF'
INFO:transitions.core:Finished processing state OFF enter callbacks.
DEBUG:transitions.core:Executed callback after transition.
DEBUG:transitions.core:Executed machine finalize callbacks
DEBUG:transitions.core:Executed machine preparation callbacks before conditions.
DEBUG:transitions.core:Initiating transition from state OFF to state None...
DEBUG:transitions.core:Executed callbacks before conditions.
DEBUG:transitions.core:Executed callback before transition.
DEBUG:transitions.core:Executed callback after transition.
DEBUG:transitions.core:Executed machine finalize callbacks
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So I have a program that controls my pool pump and solar heater. I am using Transitions for a state machine, and as an example, if the schedule check says the pump should be off, it will fire the transition called off_time. For the transition definitions, if the state is already schedule_off, I have it set as an internal transition, since there is no reason to change states. BUT, when I run the program, I can see from debug prints that the code that is in "on_enter_schedule_off" keeps getting executed. It does not effect the overall performance of the controller, but I am trying to understand why the "on_enter" is firing since I thought the internal transition would bypass that.
Thanks for any help
Beta Was this translation helpful? Give feedback.
All reactions