def get_action(name): action = Action.to_api(name) if action: return action else: response.status = 404 return {"error": "Action {} not found.".format(name)}
def get_action(name): action = Action.to_api(name) if action: return action else: response.status = 404 return {"error": "Action {} not found.".format(name)}
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)}
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)}