def handle_wakeup_event(self):
if self._nerver is not None:
return self._nerver.nerv()
+ def on_leave(self):
+ pass
def pins(self):
return self.state_machine.pins
def old_pins(self):
for cb in self.callbacks:
if cb is not None:
cb(s)
- def handle_pins_event(self):
- # overriding superclass as we need to do notification (TODO can this be done better? on_leave?)
- if not self.pins().door_locked:
- self.notify(True)
- return StateMachine.StateAboutToOpen(self.state_machine)
+ def on_leave(self):
+ self.notify(not self.pins().door_locked)
def handle_cmd_unlock_event(self,callback):
# TODO: 202 notification also here if possible
self.callbacks.append(callback)
def could_not_open(self):
logger.critical("StateMachine: Couldn't open door after %d tries. Going back to StateZu." % OPEN_REPEAT_NUMBER)
- self.notify(False)
return StateMachine.StateZu(self.state_machine)
class AbstractStateWhereUnlockingIsRedundant(AbstractUnlockedState):
class StateAuf(AbstractStateWhereUnlockingIsRedundant):
def __init__(self,sm):
- super().__init__(sm)
+ nervlist = [(24*60*60, lambda: logger.critical("Space is now open for 24h. Is everything all right?"))]
+ super().__init__(sm, nervlist)
self.last_buzzed = None
def handle_pins_event(self):
pins = self.pins()
newstate = self.current_state.handle_event(cmd,arg) # returns None or an instance of the new state
self.old_pins = self.pins
while newstate is not None:
+ self.current_state.on_leave()
logger.debug("StateMachine: Doing state transition %s -> %s" % (self.current_state.__class__.__name__, newstate.__class__.__name__))
self.current_state = newstate
newstate = self.current_state.handle_event(StateMachine.CMD_PINS, self.pins)