LED-Control/rest.py
2021-10-28 12:34:09 +01:00

33 lines
617 B
Python

from flask import Flask, request
import ast
from colormap import rgb2hex
from lib.shared import run_bulb_action
app = Flask(__name__)
@app.route("/on")
def on():
res = run_bulb_action("cc2333")
return {"result": res}
@app.route("/off")
def off():
res = run_bulb_action("cc2433")
return {"result": res}
@app.route("/colour")
def colour():
rgb = list(ast.literal_eval(request.args.get("rgb")))
r = rgb[0]
g = rgb[1]
b = rgb[2]
hex = rgb2hex(r, g, b)
hex = hex.replace("#", "")
value = "56" + hex + "00f0aa"
res = run_bulb_action(value)
return {"result": res}