Ejemplo n.º 1
0
def get_action(name):
    action = Action.to_api(name)
    if action:
        return action
    else:
        response.status = 404
        return {"error": "Action {} not found.".format(name)}
Ejemplo n.º 2
0
def get_action(name):
    action = Action.to_api(name)
    if action:
        return action
    else:
        response.status = 404
        return {"error": "Action {} not found.".format(name)}
Ejemplo n.º 3
0
def post_action(id, name):
    device = Device.to_api(id)
    action = Action.to_api(name)
    if device and action:
        if not device["connected"]:
            response.status = 403
            return {"error": "Device {} is not connected.".format(id)}

        args = dict([(arg, request.json.get(arg)) for arg in action["args"]])

        if api.core.do(device, action, **args):
            response.status = 204
        else:
            response.status = 403
            return {"error": "Impossible to do action {} for device {} with args {}".format(name, id, args)}
    else:
        response.status = 404
        return {"error": "Device {} not found.".format(id)}
Ejemplo n.º 4
0
def post_action(id, name):
    device = Device.to_api(id)
    action = Action.to_api(name)
    if device and action:
        if not device["connected"]:
            response.status = 403
            return {"error": "Device {} is not connected.".format(id)}

        args = dict([(arg, request.json.get(arg)) for arg in action["args"]])

        if api.core.do(device, action, **args):
            response.status = 204
        else:
            response.status = 403
            return {
                "error":
                "Impossible to do action {} for device {} with args {}".format(
                    name, id, args)
            }
    else:
        response.status = 404
        return {"error": "Device {} not found.".format(id)}
Ejemplo n.º 5
0
def get_actions():
    query = {}
    for k in request.params.keys():
        query[k] = request.params.get(k)
    return {"actions": Action.all_to_api(query)}
Ejemplo n.º 6
0
def get_actions():
    query = {}
    for k in request.params.keys():
        query[k] = request.params.get(k)
    return {"actions": Action.all_to_api(query)}