LED-Control/rest.py

33 lines
617 B
Python
Raw Normal View History

2021-10-25 20:04:55 +01:00
from flask import Flask, request
2021-10-26 16:55:30 +01:00
import ast
2021-10-28 12:34:09 +01:00
2021-10-25 20:04:55 +01:00
from colormap import rgb2hex
2021-10-28 12:34:09 +01:00
from lib.shared import run_bulb_action
2021-10-25 20:04:55 +01:00
app = Flask(__name__)
2021-10-26 16:55:30 +01:00
@app.route("/on")
def on():
2021-10-26 17:00:16 +01:00
res = run_bulb_action("cc2333")
return {"result": res}
2021-10-26 10:39:04 +01:00
@app.route("/off")
2021-10-26 10:40:10 +01:00
def off():
2021-10-26 17:00:16 +01:00
res = run_bulb_action("cc2433")
return {"result": res}
2021-10-25 20:04:55 +01:00
2021-10-26 10:33:37 +01:00
@app.route("/colour")
2021-10-26 16:55:30 +01:00
def colour():
rgb = list(ast.literal_eval(request.args.get("rgb")))
2021-10-26 16:33:17 +01:00
r = rgb[0]
g = rgb[1]
b = rgb[2]
hex = rgb2hex(r, g, b)
hex = hex.replace("#", "")
2021-10-26 16:55:30 +01:00
value = "56" + hex + "00f0aa"
2021-10-26 17:00:16 +01:00
res = run_bulb_action(value)
return {"result": res}