aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael McVady <michaelm@telnyx.com>2024-01-28 17:42:15 -0600
committerMichael McVady <michaelm@telnyx.com>2024-01-28 17:42:15 -0600
commit89e72db15c4d4feac71a0a84e9be431ccb22d548 (patch)
treed86d83b38d37c35ea4483cf404e9d037bf03fd1b
parentfd17a92765c4bdc9350487a9b937eb3d4707dfa7 (diff)
Set random color
-rw-r--r--README.md3
-rw-r--r--app.py32
-rw-r--r--requirements-dev.txt2
3 files changed, 31 insertions, 6 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..1f48fd3
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# lux
+
+Controls a [lifx lightbulb](https://www.lifx.com/collections/lightbulbs) somewhere in the world.
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,
+ ]
+)
diff --git a/requirements-dev.txt b/requirements-dev.txt
new file mode 100644
index 0000000..7559a40
--- /dev/null
+++ b/requirements-dev.txt
@@ -0,0 +1,2 @@
+black
+isort