Exemplo n.º 1
0
    def open_gate(self, gate, user_id, command='open'):
        """Handle gate opening via web interface.
        """
        if command == 'open':
            requests.get(gate.uri_open, timeout=1)

        elif command == 'close':
            requests.get(gate.uri_close, timeout=1)

        else:
            return None

        requests.get(gate.uri_nvr, timeout=1)

        snapshot = self.save_snapshot(gate.id)

        a = Activity()
        a.gate = gate.id
        a.snapshot = snapshot
        a.command = command
        a.success = True
        a.user = user_id
        a.meta = {'tags': ['web'] if command == 'open' else ['close', 'web']}

        db.session.add(a)
        db.session.commit()

        return a.success
Exemplo n.º 2
0
    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