- class StateClosing(State):
- # TODO: share code with StateOpening, and possibly also with the nerv-mechanism from StateAboutToOpen
- def __init__(self,callback,sm):
- State.__init__(self,sm)
- self.callbacks=[callback]
- # FIXME: can we send "202 processing: Trying to close the door" here? Are the callbacks multi-use?
- self.tries = 0
- self.actor().act(Actor.CMD_CLOSE)
- def notify(self, did_it_work):
- s = "200 okay: door closed" if did_it_work else ("500 internal server error: Couldn't close door with %d tries à %f seconds" % (CLOSE_REPEAT_NUMBER,CLOSE_REPEAT_TIMEOUT))
- for cb in self.callbacks:
- if cb is not None:
- cb(s)
+ class StateLocking(State):
+ # TODO: share code with StateUnlocking
+ 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 not pins.door_closed: # this should always be true, but just to be sure...
+ self.actor().act(Actor.CMD_LOCK)