From 89e72db15c4d4feac71a0a84e9be431ccb22d548 Mon Sep 17 00:00:00 2001 From: Michael McVady Date: Sun, 28 Jan 2024 17:42:15 -0600 Subject: Set random color --- app.py | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'app.py') diff --git a/app.py b/app.py index d669836..954edc1 100644 --- a/app.py +++ b/app.py @@ -1,22 +1,42 @@ -from lifxlan import LifxLAN, BLUE +from random import randint +from lifxlan import LifxLAN from litestar import Litestar, get, post +lifxlan = LifxLAN() + @get("/") -async def index() -> str: - return "Hello, world!" +async def get_index() -> dict[str, str]: + try: + # colors = lifxlan.get_color_all_lights() + lifxlan.set_color_all_lights( + [randint(0, 65535), randint(0, 65535), randint(0, 65535), randint(0, 9000)], + rapid=True, + ) + except Exception as e: + return {"status": "error", "message": str(e)} + + # return {"status": str(colors)} + return {"status": "ok"} @post("/") async def post_index() -> dict[str, str]: - lifxlan = LifxLAN() try: - lifxlan.set_color_all_lights(BLUE, rapid=True) + lifxlan.set_color_all_lights( + [randint(0, 65535), randint(0, 65535), randint(0, 65535), randint(0, 9000)], + rapid=True, + ) except Exception as e: return {"status": "error", "message": str(e)} return {"status": "ok"} -app = Litestar([index, post_index]) +app = Litestar( + [ + get_index, + post_index, + ] +) -- cgit v1.2.3