+ self.actor().act(Actor.CMD_RED_OFF)
+ return super().handle_pins_event()
+
+ class AbstractLockedState(AbstractNonStartState):
+ '''A state with invariant "The space is locked", switching to StateAboutToOpen when the space becomes unlocked'''
+ def __init__(self, sm, nervlist = None):
+ super().__init__(sm, nervlist)
+ self.actor().act(Actor.CMD_GREEN_OFF)
+ def handle_pins_event(self):
+ if not self.pins().door_locked:
+ logger.info("Door unlocked, space is about to open")
+ return StateMachine.StateAboutToOpen(self.state_machine)
+ return super().handle_pins_event()
+
+ class AbstractUnlockedState(AbstractNonStartState):
+ '''A state with invariant "The space is unlocked", switching to StateZu when the space becomes locked'''
+ def __init__(self, sm, nervlist = None):
+ super().__init__(sm, nervlist)
+ self.actor().act(Actor.CMD_GREEN_ON)
+ def handle_pins_event(self):
+ if self.pins().door_locked:
+ logger.info("Door locked, closing space")
+ if self.pins().space_active:
+ 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)
+ return super().handle_pins_event()
+
+ class StateStart(State):
+ def __init__(self, sm, nervlist = None, fallback=False):
+ super().__init__(self, sm, nervlist)
+ self.fallback = fallback
+ def handle_pins_event(self):
+ pins = self.pins()
+ if not (pins.door_locked is None or pins.door_closed is None or pins.space_active is None or pins.bell_ringing is None):
+ logger.info("All sensors got a value, switching to a proper state")
+ if self.fallback:
+ logger.info("Going to StateFallback because running in fallback mode")
+ return StateMachine.StateFallback(self.state_machine)
+ if pins.door_locked:
+ return StateMachine.StateZu(self.state_machine)
+ else:
+ return StateMachine.StateAboutToOpen(self.state_machine)
+ return super().handle_pins_event()
+
+ class StateFallback(State):
+ def __init__(self, sm, nervlist = None):
+ super().__init__(self, sm, nervlist)
+ self._last_blink_time = time.time()
+ self._red_state = False