def handle_open(self, endpoint, content): """Handle the opening of a gate by an endpoint. """ if endpoint[0].type == 'openalpr': code, success, meta = self.read_openalpr(endpoint, content) else: code, success, meta = self.read_generic(endpoint, content) if code == '': return False access = Access.query.filter( Access.code == code, Access.endpoint == endpoint[0].id).first() snapshot = self.save_snapshot(endpoint[4]) a = Activity() a.endpoint = endpoint[0].id a.code = code a.meta = meta a.snapshot = snapshot if 'tags' not in a.meta: a.meta['tags'] = [] # TODO: handle valid from/to timestamps if access and success: # Send gate open command requests.get(endpoint[1], timeout=1) a.success = True a.access = access.id # Send NVR trigger requests.get(endpoint[2], timeout=1) db.session.add(a) db.session.commit() return a.success