def from_db_row(row): if row is not None: (ip,serial_number,hostname,registration,status,friendly_name) = row _registration = Message.from_json(registration) cam = Camera(ip,_registration) cam.status = Message.from_json(status) cam.friendly_name = friendly_name return cam else: return None
def pir_led(self,args): register_set = Message(arlo.messages.REGISTER_SET) enabled = args['enabled'] sensitivity = args['sensitivity'] register_set["SetValues"] = { "PIREnableLED":enabled, "PIRLEDSensitivity":sensitivity } return self.send_message(register_set)
def set_quality(self,args): quality = args["quality"].lower() if quality == "low": ra_params = Message(arlo.messages.RA_PARAMS_LOW_QUALITY) registerSet = Message(arlo.messages.REGISTER_SET_LOW_QUALITY) elif quality == "medium": ra_params = Message(arlo.messages.RA_PARAMS_MEDIUM_QUALITY) registerSet = Message(arlo.messages.REGISTER_SET_MEDIUM_QUALITY) elif quality == "high": ra_params = Message(arlo.messages.RA_PARAMS_HIGH_QUALITY) registerSet = Message(arlo.messages.REGISTER_SET_HIGH_QUALITY) elif quality == "subscription": ra_params = Message(arlo.messages.RA_PARAMS_SUBSCRIPTION_QUALITY) registerSet = Message(arlo.messages.REGISTER_SET_SUBSCRIPTION_QUALITY) else: return False return self.send_message(ra_params) and self.send_message(registerSet)
def arm(self,args): register_set = Message(arlo.messages.REGISTER_SET) pir_target_state = args['PIRTargetState'] video_motion_estimation_enable = args['VideoMotionEstimationEnable'] audio_target_state = args['AudioTargetState'] register_set["SetValues"] = { "PIRTargetState":pir_target_state, "PIRStartSensitivity":80, "PIRAction":"Stream", "VideoMotionEstimationEnable":video_motion_estimation_enable, "VideoMotionSensitivity":80, "AudioTargetState":audio_target_state, "DefaultMotionStreamTimeLimit":10 # Unclear what this does, only set in normal traffic when 'Disarmed' } return self.send_message(register_set)
def receive(self): data = self.sock.recv(1024).decode(encoding="utf-8") if data.startswith("L:"): delimiter = data.index(" ") dataLength = int(data[2:delimiter]) json_data = data[delimiter+1:delimiter+1+dataLength] else: return None read = len(json_data) while read < dataLength: to_read = min(dataLength - read, 1024) chunk = self.sock.recv(to_read) if chunk == b'': raise RuntimeError("socket connection broken") chunk_str = chunk.decode(encoding="utf-8") json_data += chunk_str read = read + len(chunk_str) return Message(json.loads(json_data))
def unset_activity_zones(self,args): activity_zones = Message(arlo.messages.ACTIVITY_ZONE_DELETE) return self.send_message(activity_zones)
def set_activity_zones(self,args): activity_zones = Message(arlo.messages.ACTIVITY_ZONE_ALL) # TODO:Set The Co-ordinates return self.send_message(activity_zones)
def speaker_request(self, enabled): register_set = Message(arlo.messages.REGISTER_SET) register_set['AudioSpkrEnable'] = enabled return self.send_message(register_set)
def snapshot_request(self, url): _snapshot_request = Message(arlo.messages.SNAPSHOT) _snapshot_request['DestinationURL'] = url return self.send_message(_snapshot_request)
def status_request(self): _status_request = Message(arlo.messages.STATUS_REQUEST) return self.send_message(_status_request)
def set_user_stream_active(self,active): register_set = Message(arlo.messages.REGISTER_SET) register_set['SetValues']['UserStreamActive'] = int(active) return self.send_message(register_set)
def run(self): while True: timestr = time.strftime("%Y%m%d-%H%M%S") msg = self.connection.receive() if msg != None: if (msg['Type'] == "registration"): camera = Camera.from_db_serial(msg['SystemSerialNumber']) if camera is None: camera = Camera(self.ip, msg) else: camera.registration = msg camera.persist() s_print( f"<[{self.ip}][{msg['ID']}] Registration from {msg['SystemSerialNumber']} - {camera.hostname}" ) if msg['SystemModelNumber'] == 'VMC5040': registerSet = Message( arlo.messages.REGISTER_SET_INITIAL_ULTRA) else: registerSet = Message( arlo.messages.REGISTER_SET_INITIAL) registerSet['WifiCountryCode'] = WIFI_COUNTRY_CODE camera.send_message(registerSet) elif (msg['Type'] == "status"): s_print( f"<[{self.ip}][{msg['ID']}] Status from {msg['SystemSerialNumber']}" ) camera = Camera.from_db_serial(msg['SystemSerialNumber']) camera.ip = self.ip camera.status = msg camera.persist() elif (msg['Type'] == "alert"): camera = Camera.from_db_ip(self.ip) alert_type = msg['AlertType'] s_print(f"<[{self.ip}][{msg['ID']}] {msg['AlertType']}") if alert_type == "pirMotionAlert" and RECORD_ON_MOTION_ALERT: filename = f"{RECORDING_BASE_PATH}{camera.serial_number}_{timestr}_motion.mpg" recorder = Recorder(self.ip, filename, MOTION_RECORDING_TIMEOUT) with recorder_lock: if self.ip in recorders: recorder[self.ip].stop() recorders[self.ip] = recorder recorder.run() webhook_manager.motion_detected( camera.ip, camera.friendly_name, camera.hostname, camera.serial_number, msg['PIRMotion']['zones'], filename) elif alert_type == "audioAlert" and RECORD_ON_AUDIO_ALERT: recorder = Recorder( self.ip, f"{RECORDING_BASE_PATH}{camera.serial_number}_{timestr}_audio.mpg", AUDIO_RECORDING_TIMEOUT) with recorder_lock: if self.ip in recorders: recorder[self.ip].stop() recorders[self.ip] = recorder recorder.run() elif alert_type == "motionTimeoutAlert": with recorder_lock: if self.ip in recorders and recorders[ self.ip] is not None: recorders[self.ip].stop() del recorders[self.ip] else: s_print(f"<[{self.ip}][{msg['ID']}] Unknown message") s_print(msg) ack = Message(arlo.messages.RESPONSE) ack['ID'] = msg['ID'] s_print(f">[{self.ip}][{msg['ID']}] Ack") self.connection.send(ack) self.connection.close() break