+ABOUTOPEN_NERVLIST = [(5, lambda : play_sound("flipswitch")), (5, lambda:play_sound("flipswitch")), (0, lambda:Logger.warning("Space open but switch not flipped for 10 seconds")),\
+ (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 = 30
+
+# play_sound constants
+SOUNDS_DIRECTORY = "/opt/tuer/sounds/"
+SOUNDS_PLAYER = "/usr/bin/mplayer"
+
+
+class Nerver():
+ # A little utility class used to run the nervlists. A nervlist is a list of (n, f) tuples where f() is run after n seconds.
+ # If f returns something, that's also returned by nerv.
+ def __init__(self, nervlist):
+ self.nervlist = list(nervlist)
+ self.last_event_time = time.time()
+
+ def nerv(self):
+ if len(self.nervlist):
+ (time, f) = self.nervlist[0]
+ now = time.time()
+ time_gone = now-self.last_event_time
+ # check if the first element is to be triggered
+ if time_gone >= time:
+ self.nervlist = self.nervlist[1:] # "pop" the first element, but do not modify original list
+ self.last_event_time = now
+ return f()
+