diff options
author | Michael McVady <michaelm@telnyx.com> | 2024-01-28 21:43:28 -0600 |
---|---|---|
committer | Michael McVady <michaelm@telnyx.com> | 2024-01-28 21:43:28 -0600 |
commit | 4e54b3e3160226f5b0d9a82aab2d3c7a3f151cdd (patch) | |
tree | 55d4c8e86059d33383bb1df1178addd605066db2 | |
parent | efa3572376e4402dbe1f55e2ae72c9b6e3019fbf (diff) |
Bikeshedding
-rw-r--r-- | app.py | 25 |
1 files changed, 7 insertions, 18 deletions
@@ -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": ""} ) |