Exemplo n.º 1
0
def handle_color_controller(request):
    endpoint_id = request["directive"]["endpoint"]["endpointId"]
    value = request["directive"]["payload"]["color"]

    api.set_color(endpoint_id, value)

    response = Response(ResponseName.RESPONSE)
    response.add_context(ContextName.COLOR, value)
    response.add_correlation_token(
        request["directive"]["header"]["correlationToken"])
    response.add_endpoint(endpoint_id)
    return response
Exemplo n.º 2
0
def handle_power_controller(request):
    request_name = request["directive"]["header"]["name"]
    endpoint_id = request["directive"]["endpoint"]["endpointId"]

    value = "ON" if request_name == "TurnOn" else "OFF"
    api.set_power_state(endpoint_id, value)

    response = Response(ResponseName.RESPONSE)
    response.add_context(ContextName.POWER_STATE, value)
    response.add_correlation_token(
        request["directive"]["header"]["correlationToken"])
    response.add_endpoint(endpoint_id)
    return response