1from automat import MethodicalMachine 2 3 4class Led(object): 5 _machine = MethodicalMachine() 6 7 @_machine.state() 8 def led_on(self): 9 "led is on" 10 11 @_machine.state(initial=True) 12 def led_off(self): 13 "led is off" 14 15 @_machine.input() 16 def turn_on(self): 17 "turn the led on" 18 19 @_machine.output() 20 def _light(self): 21 print("light") 22 23 led_off.upon(turn_on, enter=led_on, outputs=[_light]) 24 25 26led = Led() 27led.turn_on() 28