- logger.info("space switch off - starting leaving procedure")
- return StateAboutToLeave(self.state_machine)
- if pins.door_locked:
- logger.error("door manually locked, but space switch on - going to StateZu")
- play_sound("manual_lock")
- return StateZu(self.state_machine)
- # handle_wakeup_event intentionally not overwritten
-
- class StateClosing(State):
- #TODO Ralf/Conny
- pass
-
- class StateAboutToLeave(State):
- #TODO Ralf
- pass
-
- class StateLeaving(State):
- #TODO Ralf
- pass
+ logger.info("StateMachine: space switch turned off - starting leaving procedure")
+ return StateMachine.StateAboutToLeave(self.state_machine)
+ return super().handle_pins_event()
+
+ class StateLocking(AbstractUnlockedState):
+ def __init__(self,sm):
+ # construct a nervlist
+ nervlist = [(CLOSE_REPEAT_TIMEOUT, lambda: self.actor().act(Actor.CMD_LOCK)) for t in range(CLOSE_REPEAT_NUMBER)]
+ nervlist += [(CLOSE_REPEAT_TIMEOUT, self.could_not_close)]
+ super().__init__(sm, nervlist)
+ if self.pins().door_closed: # this should always be true, but just to be sure...
+ self.actor().act(Actor.CMD_LOCK)
+ def handle_pins_event(self):
+ pins = self.pins()
+ if not pins.door_closed:
+ # TODO play a sound? This shouldn't happen, door was opened while we are locking
+ logger.warning("StateMachine: door manually opened during locking")
+ return StateMachine.StateAboutToOpen(self.state_machine)
+ # TODO do anything here if the switch is activated now?
+ return super().handle_pins_event()
+ def handle_cmd_unlock_event(self,callback):
+ callback("409 conflict: The sphinx is currently trying to lock the door. Try again later.")
+ def could_not_close(self):
+ logger.critical("StateMachine: Couldn't close door after %d tries. Going back to StateAboutToOpen." % CLOSE_REPEAT_NUMBER)
+ return StateMachine.StateAboutToOpen(self.state_machine)
+
+ class StateAboutToLeave(AbstractUnlockedState):
+ def __init__(self, sm):
+ nervlist = [(LEAVE_TIMEOUT, lambda: StateMachine.StateLocking(self.state_machine))]
+ super().__init__(sm, nervlist)
+ def handle_pins_event(self):
+ if not self.pins().door_closed:
+ return StateMachine.StateLeaving(self.state_machine)
+ if self.pins().space_active:
+ logger.info("Space re-activated, cancelling leaving procedure")
+ return StateMachine.StateAuf(self.state_machine)
+ return super().handle_pins_event()
+
+ class StateLeaving(AbstractUnlockedState):
+ def __init__(self, sm):
+ nervlist = [(LEAVE_TIMEOUT, lambda: StateMachine.StateAboutToOpen(self.state_machine))]
+ super().__init__(sm, nervlist)
+ def handle_pins_event(self):
+ if self.pins().door_closed:
+ logger.info("The space was left, locking the door")
+ return StateMachine.StateLocking(self.state_machine)
+ if self.pins().space_active:
+ logger.info("Space re-activated, cancelling leaving procedure")
+ return StateMachine.StateAuf(self.state_machine)
+ return super().handle_pins_event()