Ejemplo n.º 1
0
    def login():
        json = request.get_json()

        if not validate_json.validate(validate_json.login_schema, json):
            return web_response.bad_request()

        return auth.login(json['login'], json['password'])
Ejemplo n.º 2
0
    def blinds_instant_action(context):
        json = request.get_json()

        if not validate_json.validate(
                validate_json.blind_instant_action_schema, json):
            return web_response.bad_request()

        for device_id in json['device_ids']:
            asylumd_client.shutterAction(device_id - 1, json['action_id'] - 1)

        return web_response.blinds_action_executed()
Ejemplo n.º 3
0
    def delete_blinds_task(context):
        json = request.get_json()

        if not validate_json.validate(validate_json.delete_task_schema, json):
            return web_response.bad_request()

        try:
            BlindsTask.query.filter_by(id=json['task_id']).delete()
            db.session.commit()
        except:
            return web_response.database_error()

        return web_response.blinds_task_deleted()
Ejemplo n.º 4
0
    def delete_mac_address(context, user_id):
        if user_id is None:
            user_id = context['user']['id']

        json = request.get_json()
        if not validate_json.validate(validate_json.delete_mac_address_schema, json):
            return web_response.bad_request()

        try:
            MacAddress.query.filter_by(id=json['mac_address_id']).delete()
            db.session.commit()
        except:
            return web_response.database_error()

        return web_response.ok_request()
Ejemplo n.º 5
0
    def add_mac_address(context, user_id):
        if user_id is None:
            user_id = context['user']['id']

        json = request.get_json()

        if not validate_json.validate(validate_json.add_mac_address_schema, json):
            return web_response.bad_request()

        try:
            db.session.add(MacAddress(
                user_id=user_id,
                mac_address=json['mac_address'].lower()
            ))
            db.session.commit()
        except:
            return web_response.database_error()

        return web_response.ok_request()
Ejemplo n.º 6
0
    def add_blinds_task(context):
        json = request.get_json()

        if not validate_json.validate(validate_json.add_blinds_tasks_schema,
                                      json):
            return web_response.bad_request()

        try:
            db.session.bulk_save_objects(
                list(
                    map(
                        lambda x: BlindsTask(time=json['unix_time'],
                                             device=x,
                                             action=json['action_id'],
                                             user_id=context['user']['id'],
                                             timeout=5 * 60,
                                             active=True),
                        json['devices_ids'])))
            db.session.commit()
        except:
            return web_response.database_error()

        return web_response.blind_task_added()
Ejemplo n.º 7
0
    def add_blinds_schedule(context):
        json = request.get_json()

        if not validate_json.validate(validate_json.add_blinds_schedule_schema,
                                      json):
            return web_response.bad_request()

        try:
            db.session.bulk_save_objects(
                list(
                    map(
                        lambda x: BlindsSchedule(
                            device=x,
                            action=json['action_id'],
                            hour_type=json['hour_type'],
                            time_offset=json['time_offset'],
                            user_id=context['user']['id']),
                        json['devices_ids'])))

            db.session.commit()
        except:
            return web_response.database_error()

        return web_response.blinds_schedule_added()