From d72b6eb3b787ea31c165de06a996dfca93d10146 Mon Sep 17 00:00:00 2001
From: Ralf Jung <post@ralfj.de>
Date: Thu, 24 Oct 2013 10:39:29 +0200
Subject: [PATCH] Only wait for space switches while we are in StateZu

---
 statemachine.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/statemachine.py b/statemachine.py
index ca58e1d..d8b7c53 100644
--- a/statemachine.py
+++ b/statemachine.py
@@ -116,9 +116,6 @@ 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):
@@ -149,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):
@@ -196,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)
-- 
2.39.5