nervlist = [(OPEN_REPEAT_TIMEOUT, lambda: self.actor().act(Actor.CMD_UNLOCK)) for t in range(OPEN_REPEAT_NUMBER)]
nervlist += [(OPEN_REPEAT_TIMEOUT, self.could_not_open)]
super().__init__(sm,nervlist)
- self.callbacks=[callback]
- # TODO: can we send "202 processing: Trying to unlock the door" here? Are the callbacks multi-use?
+ self.callbacks = []
self.actor().act(Actor.CMD_UNLOCK)
- def notify(self, did_it_work):
- s = "200 okay: door unlocked" if did_it_work else ("500 internal server error: Couldn't unlock door with %d tries à %f seconds" % (OPEN_REPEAT_NUMBER,OPEN_REPEAT_TIMEOUT))
+ # enqueue the callback
+ self.handle_cmd_unlock_event(callback)
+ def notify(self, s, lastMsg):
for cb in self.callbacks:
- if cb is not None:
- cb(s)
+ cb(s, lastMsg)
def on_leave(self):
- self.notify(not self.pins().door_locked)
+ s = "200 okay: door unlocked" if not self.pins().door_locked else ("500 internal server error: Couldn't unlock door with %d tries à %f seconds" % (OPEN_REPEAT_NUMBER,OPEN_REPEAT_TIMEOUT))
+ self.notify(s, lastMsg=True)
def handle_cmd_unlock_event(self,callback):
- # TODO: 202 notification also here if possible
- self.callbacks.append(callback)
+ if callback is not None:
+ callback("202 processing: Trying to unlock the door", lastMsg=False)
+ 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)
return StateMachine.StateZu(self.state_machine)
the_socket.accept()
except KeyboardInterrupt:
# this is what we waited for!
- logger.info("Got SIGINT, terminating...")
pass
+logger.info("Terminating...")
+
# bring 'em all down
the_waker.stop() # this one first, it "randomly" calls other threads
the_pins.stop() # as does this