From: Ralf Jung Date: Mon, 14 Oct 2013 19:47:26 +0000 (+0200) Subject: better logging; properly detect whether the bell button was newly pressed X-Git-Url: https://git.ralfj.de/saartuer.git/commitdiff_plain/3313462175e847d3c0c5075e1ecc589f1d264ca7?ds=inline;hp=--cc better logging; properly detect whether the bell button was newly pressed --- 3313462175e847d3c0c5075e1ecc589f1d264ca7 diff --git a/actor.py b/actor.py index 8f57d9f..8dd7323 100644 --- a/actor.py +++ b/actor.py @@ -24,11 +24,11 @@ class Actor: logger.info("Actor: Running command %s" % name) for (value, delay) in todo: if value is not None: - logger.debug("Setting pin %d to %d" % (pin, value)) + logger.debug("Actor: Setting pin %d to %d" % (pin, value)) GPIO.output(pin, value) time.sleep(delay) else: - logger.error("Actor: Gut unknown command %d" % cmd) + logger.critical("Actor: Got unknown command %d" % cmd) def stop(self): self.act.stop() diff --git a/libtuer.py b/libtuer.py index 613ce4e..8f9c48f 100644 --- a/libtuer.py +++ b/libtuer.py @@ -17,6 +17,7 @@ def sendeMail(subject, text, receivers, sender='sphinx@hacksaar.de', replyTo=Non msg['To'] = ', '.join(receivers) if replyTo is not None: msg['Reply-To'] = replyTo + # FIXME set time # put into envelope and send s = smtplib.SMTP('ralfj.de') s.sendmail(sender, receivers, msg.as_string()) diff --git a/statemachine.py b/statemachine.py index 893287a..01cf83f 100644 --- a/statemachine.py +++ b/statemachine.py @@ -27,10 +27,6 @@ ABOUTOPEN_NERVLIST = [(5, lambda : play_sound("flipswitch")), (5, lambda:play_so (10, lambda:play_sound("flipswitch")), (10, lambda:play_sound("flipswitch")), (0, lambda:logger.error("Space open but switch not flipped for 30 seconds")),\ (10, lambda:play_sound("flipswitch")), (10, lambda:play_sound("flipswitch")), (6, lambda:play_sound("flipswitch")), (4, lambda:logger.critical("Space open but switch not flipped for 60 seconds"))] -# StateAuf constants -# time that must pass between two bell_ringing events to buzz the door again (seconds) -AUF_BELLBUZZ_REPEAT_TIME = 2 - # Timeout we wait after the switch was switched to "Closed", until we assume nobody will open the door and we just lock it # ALso the time we wait after the door was opend, till we assume something went wrong and start nerving LEAVE_TIMEOUT = 20 @@ -84,6 +80,8 @@ class StateMachine(): return self._nerver.nerv() def pins(self): return self.state_machine.pins + def old_pins(self): + return self.state_machine.old_pins def actor(self): return self.state_machine.actor def handle_event(self,ev,arg): # don't override @@ -144,7 +142,7 @@ class StateMachine(): # TODO: 202 notification also here if possible self.callbacks.append(callback) def could_not_open(self): - logger.critical("Couldn't open door after %d tries. Going back to StateZu." % OPEN_REPEAT_NUMBER) + 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) @@ -152,7 +150,7 @@ class StateMachine(): def handle_cmd_unlock_event(self, callback): # intentionally not calling super() implementation callback("299 redundant: Space seems to be already open. Still processing your request tough.") - logger.info("Received OPEN command in StateAboutToOpen. This should not be necessary.") + logger.info("StateMachine: Received UNLOCK command in StateAboutToOpen. This should not be necessary.") self.actor().act(Actor.CMD_UNLOCK) class StateAboutToOpen(AbstractStateWhereOpeningIsRedundant): @@ -173,18 +171,15 @@ class StateMachine(): def handle_pins_event(self): super().handle_pins_event() pins = self.pins() - if pins.bell_ringing: - # TODO: use old_pins instead of a timer - now = time.time() - if self.last_buzzed is None or now-self.last_buzzed < AUF_BELLBUZZ_REPEAT_TIME: - logger.info("buzzing because of bell ringing in state auf") - self.actor().act(Actor.CMD_BUZZ) - self.last_buzzed = now + if pins.bell_ringing and not self.old_pins().bell_ringing: + # someone just pressed the bell + logger.info("StateMachine: buzzing because of bell ringing in state auf") + self.actor().act(Actor.CMD_BUZZ) if not pins.space_active: - logger.info("space switch off - starting leaving procedure") + logger.info("StateMachine: space switch off - starting leaving procedure") return StateMachine.StateAboutToLeave(self.state_machine) if pins.door_locked: - logger.info("door manually locked, but space switch on - going to StateZu") + logger.info("StateMachine: door manually locked, but space switch on - going to StateZu") play_sound("manual_lock") return StateMachine.StateZu(self.state_machine) @@ -201,14 +196,14 @@ class StateMachine(): 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("door manually opened during locking") + logger.warning("StateMachine: door manually opened during locking") return StateMachine.StateAboutToOpen(self.state_machine) if pins.door_locked: return StateMachine.StateZu(self.state_machine) def handle_cmd_unlock_event(self,callback): callback("409 conflict: The server is currently trying to lock the door. Try again later.") def could_not_close(self): - logger.critical("Couldn't close door after %d tries. Going back to StateAboutToOpen." % CLOSE_REPEAT_NUMBER) + 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(State): @@ -253,6 +248,6 @@ class StateMachine(): 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: - logger.debug("StateMachine: new state = %s" % newstate.__class__.__name__) + 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) diff --git a/tyshell b/tyshell index 9f32725..f8627d2 100755 --- a/tyshell +++ b/tyshell @@ -32,7 +32,7 @@ def extcmd(cmd): def sendcmd(addr, cmd): def run(c): - print("Running %s..." % (cmd)) + print("206 Sending command %s..." % (cmd)) s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.connect(addr) s.settimeout(60.0)