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
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
def chromecast(): TV.power_on() TV.set_input("HDMI-1") RECEIVER.send_command("MEDIA")
def all_off(): TV.power_off() RECEIVER.send_command("POWER")
def vinyl(): RECEIVER.send_command("CD")
def airplay(): TV.power_on() TV.set_input("AirPlay") RECEIVER.send_command("TV")
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")
def switch(): TV.power_on() TV.set_input("HDMI-1") RECEIVER.send_command("GAME")
def get_inputs(): return {"inputs": RECEIVER.get_inputs()}