示例#1
0
def set_input():
    if not "input" in (request.json or {}):
        return {"error": "input is requred"}, 400
    elif request.json["input"] not in RECEIVER.get_inputs():
        return {"error": "input is invalid"}, 400

    RECEIVER.set_input(request.json["input"])

    return "", 204
示例#2
0
def volume():
    if request.method != "PUT":
        return {"error": "only PUT requests are supported"}, 400

    if not all(k in (request.json or {}) for k in ["amount", "direction"]):
        return {"error": "request must contain amount and direction"}, 400

    if request.json["direction"] not in ["up", "down"]:
        return {"error": "direction must be up or down"}, 400

    try:
        volume_amount = int(request.json["amount"])
    except ValueError:
        return {"error": "amount must be an int"}, 400

    if volume_amount < 0 or volume_amount > 5:
        return {"error": "amount must be between 1 and 5"}, 400

    if request.json["direction"] == "up":
        RECEIVER.send_command("VOLUP", volume_amount)
    else:
        RECEIVER.send_command("VOLDOWN", volume_amount)

    return "", 204
示例#3
0
def chromecast():
    TV.power_on()
    TV.set_input("HDMI-1")
    RECEIVER.send_command("MEDIA")
示例#4
0
def all_off():
    TV.power_off()
    RECEIVER.send_command("POWER")
示例#5
0
def vinyl():
    RECEIVER.send_command("CD")
示例#6
0
def airplay():
    TV.power_on()
    TV.set_input("AirPlay")
    RECEIVER.send_command("TV")
示例#7
0
def cubert():
    TV.power_on()
    # wake up cubert
    wakeonlan.send_magic_packet("70:85:c2:db:fd:90")
    TV.set_input("HDMI-2")
    RECEIVER.send_command("TV")
示例#8
0
def switch():
    TV.power_on()
    TV.set_input("HDMI-1")
    RECEIVER.send_command("GAME")
示例#9
0
def get_inputs():
    return {"inputs": RECEIVER.get_inputs()}