Open the space when the switch is toggled while we are closed
authorRalf Jung <post@ralfj.de>
Wed, 23 Oct 2013 17:13:54 +0000 (19:13 +0200)
committerRalf Jung <post@ralfj.de>
Wed, 23 Oct 2013 17:13:54 +0000 (19:13 +0200)
actor.py
statemachine.py

index 25939a61ee3d3dbbda368a0d3b942a7549fd023e..f2f1ad28b64cbf02d3ee1a2a6c82abce28f7e830 100644 (file)
--- a/actor.py
+++ b/actor.py
@@ -35,7 +35,7 @@ class Actor:
                CMD_GREEN_ON: CMD("green on",      pin=23, tid=2, todo=[(True, 0)]),
                CMD_GREEN_OFF: CMD("green off",    pin=23, tid=2, todo=[(False, 0)]),
                CMD_RED_ON: CMD("red on",          pin=26, tid=2, todo=[(True, 0)]),
-               CMD_RED_OFF: CMD("red on",          pin=26, tid=2, todo=[(False, 0)]),
+               CMD_RED_OFF: CMD("red off",        pin=26, tid=2, todo=[(False, 0)]),
        }
        
        def __init__(self):
index 7c75a7a273868cfc3f684d0f4df6214d4c1f761e..ca58e1d08b747ed003448f17a764142883c05430 100644 (file)
@@ -116,6 +116,9 @@ class StateMachine():
                        if not self.pins().door_locked:
                                logger.info("Door unlocked, space is about to open")
                                return StateMachine.StateAboutToOpen(self.state_machine)
+                       if not self.old_pins().space_active and self.pins().space_active:
+                               logger.info("Space toggled to active while it was closed - unlocking the door")
+                               return StateMachine.StateUnlocking(self.state_machine)
                        return super().handle_pins_event()
        
        class AbstractUnlockedState(AbstractNonStartState):
@@ -127,7 +130,6 @@ class StateMachine():
                        if self.pins().door_locked:
                                logger.info("Door locked, closing space")
                                if self.pins().space_active:
-                                       # FIXME the same state can be reached by first locking the door, and then activating the space. What to do then?
                                        logger.warning("StateMachine: door manually locked, but space switch is still on - going to StateZu")
                                        play_sound("manual_lock")
                                return StateMachine.StateZu(self.state_machine)