From 4e54b3e3160226f5b0d9a82aab2d3c7a3f151cdd Mon Sep 17 00:00:00 2001
From: Michael McVady <michaelm@telnyx.com>
Date: Sun, 28 Jan 2024 21:43:28 -0600
Subject: Bikeshedding

---
 app.py | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/app.py b/app.py
index 0cc26b3..9fb5971 100644
--- a/app.py
+++ b/app.py
@@ -1,7 +1,6 @@
 import logging
 from colorsys import hsv_to_rgb
 from random import randint
-from textwrap import dedent
 
 from jinja2 import Environment
 from lifxlan import LifxLAN
@@ -13,6 +12,8 @@ from litestar.template import TemplateConfig
 lifxlan = LifxLAN()
 
 DEFAULT_COLOR = "#FF0000"
+TEMPLATE_STR = '<!DOCTYPE html><html><body style="background-color: {{ color }}"><h1>{{ message }}</h1></body></html>'
+
 
 logging.basicConfig(level=logging.DEBUG)
 log = logging.getLogger()
@@ -20,17 +21,6 @@ log = logging.getLogger()
 
 @get("/")
 async def get_index() -> Template:
-    template_string = dedent(
-        """
-            <!DOCTYPE html>
-            <html>
-            <body style="background-color: {{ color }}">
-            <h1>{{ message }}</h1>
-            </body>
-            </html>
-        """
-    ).strip()
-
     hue = randint(0, 65535)
     saturation = randint(0, 65535)
     brightness = randint(0, 65535)
@@ -39,7 +29,6 @@ async def get_index() -> Template:
 
     try:
         # colors = lifxlan.get_color_all_lights()
-
         lifxlan.set_color_all_lights(
             [hue, saturation, brightness, kelvin],
             rapid=True,
@@ -47,8 +36,8 @@ async def get_index() -> Template:
     except Exception as e:
         log.exception("Error setting color")
         return Template(
-            template_str=template_string,
-            context={"color": DEFAULT_COLOR, "message": str(e)},
+            template_str=TEMPLATE_STR,
+            context={"color": DEFAULT_COLOR, "message": f"error: {str(e)}"},
         )
 
     rgb_color = DEFAULT_COLOR
@@ -60,12 +49,12 @@ async def get_index() -> Template:
     except Exception as e:
         log.exception("Error converting color")
         return Template(
-            template_str=template_string,
-            context={"color": DEFAULT_COLOR, "message": str(e)},
+            template_str=TEMPLATE_STR,
+            context={"color": DEFAULT_COLOR, "message": f"error: {str(e)}"},
         )
 
     return Template(
-        template_str=template_string, context={"color": rgb_color, "message": ""}
+        template_str=TEMPLATE_STR, context={"color": rgb_color, "message": ""}
     )
 
 
-- 
cgit v1.2.3