Only wait for space switches while we are in StateZu
[saartuer.git] / statemachine.py
index 522657637b9731d236b853889db6f9af5a362395..d8b7c537ff6cdf88362646f39c2ea35d5cc410c3 100644 (file)
@@ -30,7 +30,7 @@ ABOUTOPEN_NERVLIST = [(5, lambda : play_sound("flipswitch")), (5, lambda:play_so
 
 # Timeout we wait after the switch was switched to "Closed", until we assume nobody will open the door and we just lock it
 # ALso the time we wait after the door was opend, till we assume something went wrong and start nerving
-LEAVE_TIMEOUT = 4
+LEAVE_TIMEOUT = 20
 
 # play_sound constants
 SOUNDS_DIRECTORY = "/opt/tuer/sounds/"
@@ -127,7 +127,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)
@@ -147,6 +146,11 @@ class StateMachine():
        class StateZu(AbstractLockedState):
                def handle_cmd_unlock_event(self,callback):
                        return StateMachine.StateUnlocking(self.state_machine, callback)
+               def handle_pins_event(self):
+                       if not self.old_pins().space_active and self.pins().space_active: # first thing to check: edge detection
+                               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 StateUnlocking(AbstractLockedState):
                def __init__(self,sm,callback=None):
@@ -194,7 +198,7 @@ class StateMachine():
                        self.last_buzzed = None
                def handle_pins_event(self):
                        pins = self.pins()
-                       if pins.bell_ringing and not self.old_pins().bell_ringing:
+                       if pins.bell_ringing and not self.old_pins().bell_ringing: # first thing to check: edge detection
                                # someone just pressed the bell
                                logger.info("StateMachine: buzzing because of bell ringing in StateAuf")
                                self.actor().act(Actor.CMD_BUZZ)