X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=track-presence.py;h=9e4d272cf8ea7efa7338fd2bc99e9593a44886d4;hb=d73860aa0723724aa86640c099a8e5a925865c93;hp=ddf3f2ef0c5a653d2e5cdb21ec3dc7cc36ebd70a;hpb=3a65dac5066d908f5a2c869a349e12164f57aab4;p=svn42.git diff --git a/track-presence.py b/track-presence.py index ddf3f2e..9e4d272 100644 --- a/track-presence.py +++ b/track-presence.py @@ -41,12 +41,15 @@ class UWSConfig: self.config_parser.add_section('sensors') self.config_parser.set('sensors','remote_cmd',"ssh -o PasswordAuthentication=no %RHOST% %RSHELL% %RSOCKET%") self.config_parser.set('sensors','remote_host',"slug.realraum.at") - self.config_parser.set('sensors','remote_socket',"/var/run/tuer/door_cmd.socket") - self.config_parser.set('sensors','remote_shell',"serial") + self.config_parser.set('sensors','remote_socket',"/var/run/power_sensor.socket") + self.config_parser.set('sensors','remote_shell',"usocket") self.config_parser.add_section('tracker') - self.config_parser.set('tracker','sec_wait_movement_after_door_closed',2.0) - self.config_parser.set('tracker','sec_general_movement_timeout',1800) + self.config_parser.set('tracker','sec_wait_movement_after_door_closed',2.5) + self.config_parser.set('tracker','sec_general_movement_timeout',3600) self.config_parser.set('tracker','server_socket',"/var/run/tuer/presence.socket") + self.config_parser.set('tracker','photo_flashlight',950) + self.config_parser.set('tracker','photo_daylight',500) + self.config_parser.set('tracker','photo_artif_light',150) self.config_parser.add_section('debug') self.config_parser.set('debug','enabled',"False") self.config_mtime=0 @@ -153,7 +156,7 @@ def trackSensorStatusThread(uwscfg,status_tracker,connection_listener): raise Exception("trackSensorStatusThread: subprocess %d finished, returncode: %d" % (sshp.pid,sshp.returncode)) (stdoutdata, stderrdata) = sshp.communicate(input="listen movement\n") (stdoutdata, stderrdata) = sshp.communicate(input="listen button\n") - (stdoutdata, stderrdata) = sshp.communicate(input="listen photo0\n") + (stdoutdata, stderrdata) = sshp.communicate(input="listen photo\n") while True: line = sshp.stdout.readline() logging.debug("Got Line: " + line) @@ -244,6 +247,8 @@ class StatusTracker: #(threading.Thread): self.door_manual_switch_used=False self.last_door_operation_unixts=0 self.last_movement_unixts=0 + self.last_light_value=0 + self.last_light_unixts=0 self.lock=threading.Lock() #Notify State locked by self.presence_notify_lock self.last_somebody_present_result=False @@ -276,11 +281,29 @@ class StatusTracker: #(threading.Thread): self.lock.release() self.checkPresenceStateChangeAndNotify() - def currentLightLevel(self): + def currentLightLevel(self, value): self.uwscfg.checkConfigUpdates() - #... + self.last_light_unixts=time.time() + self.last_light_value=value; self.checkPresenceStateChangeAndNotify() + def checkLight(self, somebody_present=None): + if somebody_present is None: + somebody_present=self.somebodyPresent() + + if self.last_light_value > self.uwscfg.tracker_photo_flashlight: + return "Light: flashlight" + elif self.last_light_value > self.uwscfg.tracker_photo_daylight: + return "Light: daylight" + elif self.last_light_value > self.uwscfg.tracker_photo_artif_light: + if not somebody_present and self.last_light_unixts > self.last_door_operation_unixts: + return "Light: forgotten" + else: + return "Light: on" + else: + return "Light: off" + + #TODO: check brightness level from cam or an arduino sensor def somebodyPresent(self): global uwscfg @@ -294,7 +317,7 @@ class StatusTracker: #(threading.Thread): self.timer=threading.Timer(self.uwscfg.tracker_sec_wait_movement, self.checkPresenceStateChangeAndNotify) self.timer.start() return True - elif (self.last_movement_unixts > self.last_door_operation_unixts and time.time() - self.last_movement_unixts < self.uwscfg.tracker_sec_general_movement_timeout): + elif (self.last_movement_unixts > self.last_door_operation_unixts and (self.door_manual_switch_used or ( time.time() - self.last_movement_unixts < self.uwscfg.tracker_sec_general_movement_timeout))): return True else: return False