diff --git a/apps/nspanel-lovelace-ui/luibackend/theme.py b/apps/nspanel-lovelace-ui/luibackend/theme.py index cf78b9ec..62f7766b 100644 --- a/apps/nspanel-lovelace-ui/luibackend/theme.py +++ b/apps/nspanel-lovelace-ui/luibackend/theme.py @@ -1,4 +1,6 @@ +from helper import rgb_dec565 + default_screensaver_color_mapping = { #"item": "color in decimal RGB565 (1-65535)" "background": "0", @@ -13,8 +15,8 @@ default_screensaver_color_mapping = { "tForecast4": "65535", "tF1Icon": "65535", "tF2Icon": "65535", - "tf3Icon": "65535", - "tf4Icon": "65535", + "tF3Icon": "65535", + "tF4Icon": "65535", "tForecast1Val": "65535", "tForecast2Val": "65535", "tForecast3Val": "65535", @@ -26,17 +28,46 @@ default_screensaver_color_mapping = { "tMR": "65535" } +default_weather_icon_color_mapping = { + #"item-per HA" "color in decimal RGB 565 (1-65535)" + "clear-night": "35957", #50% grey + "cloudy": "31728", #grey-blue + "exceptional": "63488", #red + "fog": "21130", #75% grey + "hail": "65535", #white + "lightning": "65120", #golden-yellow + "lightning-rainy": "50400", #dark-golden-yellow + "partlycloudy": "35957", #50% grey + "pouring": "249", #blue + "rainy": "33759", #light-blue + "snowy": "65535", #white + "snowy-rainy": "44479", #light-blue-grey + "sunny": "63469", #bright-yellow + "windy": "35957", #50% grey + "windy-variant": "35957" #50% grey +} -def map_color(key, theme= None, state=None): -# read theme for override - if theme is not None and key in theme: - config_color = theme[key] - else: - config_color = default_screensaver_color_mapping[key] - return config_color - -def get_screensaver_color_output(theme=None): +def get_screensaver_color_output(theme, state=None): color_output = "color" for key in default_screensaver_color_mapping: - color_output += f"~{map_color(key=key, theme=theme)}" + color_output += f"~{map_color(key=key, theme=theme, state=state)}" return color_output + +def map_color(key, theme, state=None): + config_color = default_screensaver_color_mapping[key] +# Use theme color if set + if key in theme: + config_color = rgb_dec565(theme[key]) +# Use Autocolouring for weather + elif state is not None: + if key == "tMainIcon" or key == "tF1Icon" or key == "tF2Icon" or key == "tF3Icon" or key == "tF4Icon": + config_color = map_weather_icon_color(key=key, state=state) + return config_color + + +def map_weather_icon_color(key, state): + if state[key] in default_weather_icon_color_mapping: + config_color = default_weather_icon_color_mapping[state[key]] + else: + config_color = "65535" + return config_color