diff options
Diffstat (limited to 'app.py')
-rw-r--r-- | app.py | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -9,11 +9,18 @@ from litestar.contrib.jinja import JinjaTemplateEngine from litestar.response import Template from litestar.template import TemplateConfig +# FIXME: discovery happens here, but things can change. +# Try power cycling the light and see what happens. lifxlan = LifxLAN() DEFAULT_COLOR = "#FF0000" -TEMPLATE_STR = '<!DOCTYPE html><html><body style="background-color: {{ color }}"><h1>{{ message }}</h1></body></html>' - +TEMPLATE_STR = """<!DOCTYPE html> +<html> +<body style="background-color: {{ color }}"> +<h1>{{ message }}</h1> +</body> +</html> +""" logging.basicConfig(level=logging.DEBUG) log = logging.getLogger() @@ -40,12 +47,12 @@ async def get_index() -> Template: context={"color": DEFAULT_COLOR, "message": f"error: {str(e)}"}, ) - rgb_color = DEFAULT_COLOR + rgb_hex = DEFAULT_COLOR try: r, g, b = hsv_to_rgb(hue / 65535, saturation / 65535, brightness / 65535) log.info("RGB: %s, %s, %s", r, g, b) - rgb_color = "#%02x%02x%02x" % (int(r * 255), int(g * 255), int(b * 255)) - log.info("hex RGB: %s", rgb_color) + rgb_hex = "#%02x%02x%02x" % (int(r * 255), int(g * 255), int(b * 255)) + log.info("hex RGB: %s", rgb_hex) except Exception as e: log.exception("Error converting color") return Template( @@ -54,7 +61,7 @@ async def get_index() -> Template: ) return Template( - template_str=TEMPLATE_STR, context={"color": rgb_color, "message": ""} + template_str=TEMPLATE_STR, context={"color": rgb_hex, "message": ""} ) |