Skip to content

Commit

Permalink
slightly relax requirement to transitions 0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aleneum committed May 24, 2024
1 parent d575218 commit 7121104
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
tornado>=5.0
transitions>=0.9.1
transitions>=0.9.0
48 changes: 48 additions & 0 deletions sandbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from transitions_gui import NestedWebMachine
from time import sleep

states = [
{"name": "PumpON", "states": ["SwitchOFF", "SwitchON"], "initial": "SwitchOFF"},
{"name": "PumpOFF", "states": ["SwitchOFF", "SwitchON"], "initial": "SwitchOFF"},
]

transitions = [
["button_pressed", "PumpON_SwitchOFF", "PumpOFF_SwitchOFF"],
["button_pressed", "PumpON_SwitchON", "PumpOFF_SwitchON"],
["button_pressed", "PumpOFF_SwitchOFF", "PumpON_SwitchOFF"],
["button_pressed", "PumpOFF_SwitchON", "PumpON_SwitchON"],
["button_switched", "PumpON_SwitchOFF", "PumpOFF_SwitchON"],
["button_switched", "PumpON_SwitchON", "PumpOFF_SwitchOFF"],
["switch_toggled", "PumpOFF_SwitchOFF", "PumpON_SwitchON"],
["switch_toggled", "PumpON_SwitchOFF", "PumpOFF_SwitchON"],
["switch_toggled", "PumpOFF_SwitchON", "PumpON_SwitchOFF"],
["switch_toggled", "PumpON_SwitchON", "PumpOFF_SwitchOFF"],
]

m = NestedWebMachine(states=states, transitions=transitions, auto_transitions=False, initial="PumpOFF",
graph_css=
[
{
"selector": 'edge[source *= "SwitchOFF"][target *= "SwitchON"],'
'edge[source *= "SwitchON"][target *= "SwitchOFF"]',
"css": {
"label": "",
"source-text-offset": 90,
"source-label": "data(label)",
}
},
{
"selector": "edge",
"css": {
"font-size": 12
}
}
]
)

try:
while True:
sleep(5)
m.button_pressed()
except KeyboardInterrupt: # Ctrl + C will shutdown the machine
m.stop_server()

0 comments on commit 7121104

Please sign in to comment.