self.config_parser.add_section('slug')
self.config_parser.set('slug','cgiuri','http://slug.realraum.at/cgi-bin/switch.cgi?id=%ID%&power=%ONOFF%')
self.config_parser.set('slug','ids_logo','logo')
- self.config_parser.set('slug','ids_present_day','werkzeug')
+ self.config_parser.set('slug','ids_present_day_bright_room','werkzeug')
+ self.config_parser.set('slug','ids_present_day_dark_room','decke werkzeug')
self.config_parser.set('slug','ids_present_night','werkzeug schreibtisch idee labor')
- self.config_parser.set('slug','ids_panic','idee schreibtisch labor werkzeug')
- self.config_parser.set('slug','ids_nonpresent_off','lichter stereo deckehinten')
+ self.config_parser.set('slug','ids_panic','idee schreibtisch labor werkzeug deckevorne deckehinten')
+ self.config_parser.set('slug','ids_nonpresent_off','lichter stereo')
+ self.config_parser.set('slug','light_threshold_brightness','400')
#self.config_parser.set('slug','time_day','6:00-17:00')
self.config_parser.add_section('debug')
self.config_parser.set('debug','enabled',"False")
def haveDaylight():
dawn_per_month = {1:8, 2:7, 3:6, 4:6, 5:5, 6:5, 7:5, 8:6, 9:7, 10:8, 11:8, 12:8}
- dusk_per_month = {1:16, 2:17, 3:18, 4:20, 5:21, 6:21, 7:21, 8:20, 9:19, 10:18, 11:16, 12:16}
+ dusk_per_month = {1:16, 2:17, 3:18, 4:20, 5:20, 6:21, 7:21, 8:20, 9:19, 10:18, 11:16, 12:16}
hour = datetime.datetime.now().hour
month = datetime.datetime.now().month
return (hour >= dawn_per_month[month] and hour < dusk_per_month[month])
######### EVENTS ###############
unixts_last_movement=0
status_presense=None
+room_is_bright=None
+
+def eventRoomGotBright():
+ room_is_bright=True
+
+def eventRoomGotDark():
+ room_is_bright=False
def eventDaylightStart():
for id in uwscfg.slug_ids_logo.split(" "):
global status_presense
status_presense=True
if haveDaylight():
- present_ids=uwscfg.slug_ids_present_day
+ if room_is_bright:
+ present_ids=uwscfg.slug_ids_present_day_bright_room
+ else:
+ present_ids=uwscfg.slug_ids_present_day_dark_room
else:
present_ids=uwscfg.slug_ids_present_night
logging.info("event: someone present, switching on: "+present_ids)
RE_PRESENCE = re.compile(r'Presence: (yes|no)(?:, (opened|closed), (.+))?')
RE_BUTTON = re.compile(r'PanicButton|button\d?')
RE_MOVEMENT = re.compile(r'movement')
+RE_PHOTO = re.compile(r'photo\d: [^0-9]*?(\d+)')
daylight=None
wolfhour=None
unixts_last_periodical=0
if not m is None:
eventMovement()
continue
+ m = RE_PHOTO.match(line)
+ if not m is None:
+ if m.group(1) >= int(uwscfg.slug_light_threshold_brightness):
+ eventRoomGotBright()
+ else:
+ eventRoomGotDark()
+ continue
except Exception, ex:
logging.error("main: "+str(ex))
self.presence_notify_lock=threading.Lock()
#timer
self.timer=None
+ self.timer_timeout=0
def doorOpen(self,who,how):
self.uwscfg.checkConfigUpdates()
def checkAgainIn(self, sec):
- #~ if not self.timer is None:
- #~ logging.debug("checkAgainIn: canceled previous running Timer")
- #~ self.timer.cancel()
- logging.debug("checkAgainIn: starting Timer with timeout %fs" % sec)
- self.timer=threading.Timer(sec, self.checkPresenceStateChangeAndNotify)
- self.timer.start()
+ if self.timer_timeout < time.time():
+ logging.debug("checkAgainIn: starting Timer with timeout %fs" % sec)
+ self.timer=threading.Timer(sec, self.checkPresenceStateChangeAndNotify)
+ self.timer.start()
+ self.timer_timeout = time.time() + sec
+ else:
+ logging.debug("checkAgainIn: not starting timer, already one scheduled in %fs" % (time.time() - self.timer_timeout))
def somebodyPresent(self):
with self.lock:
else:
return False
elif self.door_manual_switch_used and time.time() - self.last_door_operation_unixts <= float(self.uwscfg.tracker_sec_wait_after_manual_close):
- #start timer, checkPresenceStateChangeAndNotify after tracker_sec_wait_movement
self.checkAgainIn(float(self.uwscfg.tracker_sec_wait_after_manual_close))
+ return self.last_somebody_present_result
elif not self.door_manual_switch_used and time.time() - self.last_door_operation_unixts <= float(self.uwscfg.tracker_sec_necessary_to_move_through_door):
- #start timer, checkPresenceStateChangeAndNotify after tracker_sec_wait_movement
self.checkAgainIn(float(self.uwscfg.tracker_sec_necessary_to_move_through_door))
return self.last_somebody_present_result
elif self.last_movement_unixts > self.last_door_operation_unixts - float(self.uwscfg.tracker_sec_movement_before_manual_switch) and self.door_manual_switch_used: