1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
from random import randint
from lifxlan import LifxLAN
from litestar import Litestar, get, post
lifxlan = LifxLAN()
@get("/")
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]:
try:
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(
[
get_index,
post_index,
]
)
|