In [ ]:
from fysom import Fysom
import datetime
In [ ]:
def onenterLow(e):
print("Entered Low:[{}]".format(datetime.datetime.today()))
def onreenterLow(e):
print("Reentered Low")
def onleaveLow(e):
print("Leave Low")
def onenterHigh(e):
print("Entered High")
def onreenterHigh(e):
print("Reentered High")
def onleaveHigh(e):
print("Leave High")
sm = Fysom({
'initial': {'state':'Low', 'event':'init', 'defer':True},
'events':[
{'name':'vz', 'src':'*', 'dst':'Low'},
{'name':'vgth', 'src':['Low','High'], 'dst':'High'},
{'name':'vlth', 'src':['High','Low'], 'dst':'Low'},
],
'callbacks':{
'onenterLow':onenterLow,
'onreenterLow':onreenterLow,
'onleaveLow':onleaveLow,
'onenterHigh':onenterHigh,
'onreenterHigh':onreenterHigh,
'onleaveHigh':onleaveHigh
}
})
In [ ]:
datetime.datetime.today()
In [ ]:
sm.init()
In [ ]:
sm.vgth(dt=datetime.datetime)
In [ ]:
sm.vgth()
In [ ]:
sm.vz()
TODO: Redo this with a instance method rather than a callback function if possible. Also do database inserts as the state changes... Getting close to duration tracking how many of these little objects would it take??
In [ ]: