+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 = 20
+
+# 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):
+ (wait_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 >= wait_time:
+ self.nervlist = self.nervlist[1:] # "pop" the first element, but do not modify original list
+ self.last_event_time = now
+ return f()
+