mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2025-12-23 07:54:25 +01:00
Merge pull request #219 from illuzn/illuzn-patch-themes
Screensaver Themes Patch
This commit is contained in:
38
README.md
38
README.md
@@ -385,6 +385,7 @@ key | optional | type | default | description
|
|||||||
`dateAdditonalTemplate` | True | string | `" - {{ states('sun.sun') }}"` | Addional Text dispayed after Date, can contain Homeassistant Templates
|
`dateAdditonalTemplate` | True | string | `" - {{ states('sun.sun') }}"` | Addional Text dispayed after Date, can contain Homeassistant Templates
|
||||||
`dateFormat` | True | string | `%A, %d. %B %Y` | date format used if babel is not installed
|
`dateFormat` | True | string | `%A, %d. %B %Y` | date format used if babel is not installed
|
||||||
`cards` | False | complex | | configuration for cards that are displayed on panel
|
`cards` | False | complex | | configuration for cards that are displayed on panel
|
||||||
|
`theme` | True | complex | | configuration for theme
|
||||||
`screensaver` | True | complex | | configuration for screensaver
|
`screensaver` | True | complex | | configuration for screensaver
|
||||||
`hiddenCards` | True | complex | | configuration for cards that can be accessed though navigate items
|
`hiddenCards` | True | complex | | configuration for cards that can be accessed though navigate items
|
||||||
|
|
||||||
@@ -461,7 +462,6 @@ key | optional | type | default | description
|
|||||||
`alternativeLayout` | True | boolean | `False` | alternative layout with humidity
|
`alternativeLayout` | True | boolean | `False` | alternative layout with humidity
|
||||||
`defaultCard` | True | string | `None` | default page after exiting screensaver; only works with top level cards defined in cards; needs to be a navigation item, see subpages (navigate.type_key) This config option will also be evaluated as a HomeAssistant Template.
|
`defaultCard` | True | string | `None` | default page after exiting screensaver; only works with top level cards defined in cards; needs to be a navigation item, see subpages (navigate.type_key) This config option will also be evaluated as a HomeAssistant Template.
|
||||||
`key` | True | string | `None` | Used by navigate items
|
`key` | True | string | `None` | Used by navigate items
|
||||||
`color` | True | string | `None` | Used to change the default coloring on the screensaver. The color for each element is set seperately and must be specified as a decimal (not hex) RGB565 color. Valid colors range from 0-65535 (0x0000-0xFFFF hex). Format is: `background~time~timeAMPM~date~tMainIcon~tMainText~tForecast1~tForecast2~tForecast3~tForecast4~tF1Icon~tF2Icon~tF3Icon~tF4Icon~tForecast1Val~tForecast2Val~tForecast3Val~tForecast4Val~bar~tMainIconAlt~tMainTextAlt~tMRIcon~tMR`
|
|
||||||
|
|
||||||
Example for the weatherOverride config options:
|
Example for the weatherOverride config options:
|
||||||
|
|
||||||
@@ -471,12 +471,38 @@ Example for the weatherOverride config options:
|
|||||||
name: name
|
name: name
|
||||||
icon: lightbulb
|
icon: lightbulb
|
||||||
```
|
```
|
||||||
|
#### Possible configuration values for theme config
|
||||||
|
|
||||||
Example for color config option:
|
This only works for the screensaver currently.
|
||||||
```yaml
|
|
||||||
color: 111~222~333~444~555~666~777~888~999~1111~2222~3333~4444~5555~6666~7777~8888~9999~11111~22222~33333~44444~55555
|
key | option | type | default | description
|
||||||
```
|
-- | -- | -- | -- | --
|
||||||
N.B. This generates a nonsensical color scheme and should not be used.
|
`background` | True | list | Black | `[R, G, B]`
|
||||||
|
`time` | True | list | White | `[R, G, B]`
|
||||||
|
`timeAMPM` | True | list | White | `[R, G, B]`
|
||||||
|
`date` | True | list | White | `[R, G, B]`
|
||||||
|
`tMainIcon` | True | list | White | `[R, G, B]`
|
||||||
|
`tMainText` | True | list | White | `[R, G, B]`
|
||||||
|
`tForecast1` | True | list | White | `[R, G, B]`
|
||||||
|
`tForecast2` | True | list | White | `[R, G, B]`
|
||||||
|
`tForecast3` | True | list | White | `[R, G, B]`
|
||||||
|
`tForecast4` | True | list | White | `[R, G, B]`
|
||||||
|
`tF1Icon` | True | list | White | `[R, G, B]`
|
||||||
|
`tF2Icon` | True | list | White | `[R, G, B]`
|
||||||
|
`tF3Icon` | True | list | White | `[R, G, B]`
|
||||||
|
`tF4Icon` | True | list | White | `[R, G, B]`
|
||||||
|
`tForecast1Val` | True | list | White | `[R, G, B]`
|
||||||
|
`tForecast2Val` | True | list | White | `[R, G, B]`
|
||||||
|
`tForecast3Val` | True | list | White | `[R, G, B]`
|
||||||
|
`tForecast4Val` | True | list | White | `[R, G, B]`
|
||||||
|
`bar` | True | list | White | `[R, G, B]`
|
||||||
|
`tMainIconAlt` | True | list | White | `[R, G, B]`
|
||||||
|
`tMainTextAlt` | True | list | White | `[R, G, B]`
|
||||||
|
`tMRIcon` | True | list | White | `[R, G, B]`
|
||||||
|
`tMR` | True | list | White | `[R, G, B]`
|
||||||
|
`AutoWeather` | True | string | None | Set to `auto` to enable weather icons to change depending on state e.g. blue for rainy. Any custom colors in `tMainIcon` `tF1Icon` `tF2Icon` `tF3Icon` `tF4Icon` take precedence
|
||||||
|
|
||||||
|
Specify colours as red green and blue values from 0-255 e.g. `[255, 0, 0]` for red or `[0, 0, 255]` for blue. These are translated internally to RGB565 (note that this has lower color depth so the colours may not appear the same). Also note that the screen has a low contrast ratio, so colors look sigificantly different at full display brightness and lowest brightness.
|
||||||
|
|
||||||
#### Schedule sleep brightness
|
#### Schedule sleep brightness
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import dateutil.parser as dp
|
import dateutil.parser as dp
|
||||||
|
|
||||||
|
from theme import get_screensaver_color_output
|
||||||
from icon_mapping import get_icon_id
|
from icon_mapping import get_icon_id
|
||||||
from icons import get_icon_id_ha
|
from icons import get_icon_id_ha
|
||||||
from icons import get_action_id_ha
|
from icons import get_action_id_ha
|
||||||
@@ -61,6 +62,7 @@ class LuiPagesGen(object):
|
|||||||
global babel_spec
|
global babel_spec
|
||||||
we_name = self._config._config_screensaver.entity.entityId
|
we_name = self._config._config_screensaver.entity.entityId
|
||||||
unit = self._config._config_screensaver.raw_config.get("weatherUnit", "celsius")
|
unit = self._config._config_screensaver.raw_config.get("weatherUnit", "celsius")
|
||||||
|
state = {}
|
||||||
|
|
||||||
if self._ha_api.entity_exists(we_name):
|
if self._ha_api.entity_exists(we_name):
|
||||||
we = self._ha_api.get_entity(we_name)
|
we = self._ha_api.get_entity(we_name)
|
||||||
@@ -69,6 +71,7 @@ class LuiPagesGen(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
icon_cur = get_icon_id_ha("weather", state=we.state)
|
icon_cur = get_icon_id_ha("weather", state=we.state)
|
||||||
|
state["tMainIcon"] = we.state
|
||||||
text_cur = convert_temperature(we.attributes.temperature, unit)
|
text_cur = convert_temperature(we.attributes.temperature, unit)
|
||||||
|
|
||||||
forecastSkip = self._config._config_screensaver.raw_config.get(f"forecastSkip")+1
|
forecastSkip = self._config._config_screensaver.raw_config.get(f"forecastSkip")+1
|
||||||
@@ -95,6 +98,14 @@ class LuiPagesGen(object):
|
|||||||
else:
|
else:
|
||||||
up = up.strftime('%a')
|
up = up.strftime('%a')
|
||||||
icon = get_icon_id_ha("weather", state=we.attributes.forecast[fid]['condition'])
|
icon = get_icon_id_ha("weather", state=we.attributes.forecast[fid]['condition'])
|
||||||
|
if i == 1:
|
||||||
|
state["tF1Icon"] = we.attributes.forecast[fid]['condition']
|
||||||
|
elif i == 2:
|
||||||
|
state["tF2Icon"] = we.attributes.forecast[fid]['condition']
|
||||||
|
elif i == 3:
|
||||||
|
state["tF3Icon"] = we.attributes.forecast[fid]['condition']
|
||||||
|
elif i == 4:
|
||||||
|
state["tF4Icon"] = we.attributes.forecast[fid]['condition']
|
||||||
down = convert_temperature(we.attributes.forecast[fid]['temperature'], unit)
|
down = convert_temperature(we.attributes.forecast[fid]['temperature'], unit)
|
||||||
else:
|
else:
|
||||||
up = ""
|
up = ""
|
||||||
@@ -117,6 +128,13 @@ class LuiPagesGen(object):
|
|||||||
|
|
||||||
self._send_mqtt_msg(f"weatherUpdate~{icon_cur}~{text_cur}{weather_res}{altLayout}")
|
self._send_mqtt_msg(f"weatherUpdate~{icon_cur}~{text_cur}{weather_res}{altLayout}")
|
||||||
|
|
||||||
|
# send color if configured in screensaver
|
||||||
|
theme = self._config.get("theme")
|
||||||
|
if theme is not None:
|
||||||
|
if not ("AutoWeather" in theme and theme["AutoWeather"] == "auto"):
|
||||||
|
state = None
|
||||||
|
self._send_mqtt_msg(get_screensaver_color_output(theme=theme, state=state))
|
||||||
|
|
||||||
def generate_entities_item(self, entity, cardType):
|
def generate_entities_item(self, entity, cardType):
|
||||||
entityId = entity.entityId
|
entityId = entity.entityId
|
||||||
icon = entity.iconOverride
|
icon = entity.iconOverride
|
||||||
@@ -419,10 +437,10 @@ class LuiPagesGen(object):
|
|||||||
self.generate_alarm_page(navigation, card.entity)
|
self.generate_alarm_page(navigation, card.entity)
|
||||||
if card.cardType == "screensaver":
|
if card.cardType == "screensaver":
|
||||||
self.update_screensaver_weather()
|
self.update_screensaver_weather()
|
||||||
# send color if configured in screensaver
|
# send color if configured in theme
|
||||||
color = card.raw_config.get("color")
|
theme = self._config.get("theme")
|
||||||
if color is not None:
|
if theme is not None:
|
||||||
self._send_mqtt_msg(f"color~{color}")
|
self._send_mqtt_msg(get_screensaver_color_output(theme))
|
||||||
if card.cardType == "cardQR":
|
if card.cardType == "cardQR":
|
||||||
qrcode = card.raw_config.get("qrCode", "")
|
qrcode = card.raw_config.get("qrCode", "")
|
||||||
self.generate_qr_page(navigation, card.title, card.entities, card.cardType, qrcode)
|
self.generate_qr_page(navigation, card.title, card.entities, card.cardType, qrcode)
|
||||||
|
|||||||
72
apps/nspanel-lovelace-ui/luibackend/theme.py
Normal file
72
apps/nspanel-lovelace-ui/luibackend/theme.py
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
|
||||||
|
from helper import rgb_dec565
|
||||||
|
|
||||||
|
default_screensaver_color_mapping = {
|
||||||
|
#"item": "color in decimal RGB565 (0-65535)"
|
||||||
|
"background": "0",
|
||||||
|
"time": "65535",
|
||||||
|
"timeAMPM": "65535",
|
||||||
|
"date": "65535",
|
||||||
|
"tMainIcon": "65535",
|
||||||
|
"tMainText": "65535",
|
||||||
|
"tForecast1": "65535",
|
||||||
|
"tForecast2": "65535",
|
||||||
|
"tForecast3": "65535",
|
||||||
|
"tForecast4": "65535",
|
||||||
|
"tF1Icon": "65535",
|
||||||
|
"tF2Icon": "65535",
|
||||||
|
"tF3Icon": "65535",
|
||||||
|
"tF4Icon": "65535",
|
||||||
|
"tForecast1Val": "65535",
|
||||||
|
"tForecast2Val": "65535",
|
||||||
|
"tForecast3Val": "65535",
|
||||||
|
"tForecast4Val": "65535",
|
||||||
|
"bar": "65535",
|
||||||
|
"tMainIconAlt": "65535",
|
||||||
|
"tMainTextAlt": "65535",
|
||||||
|
"tMRIcon": "65535",
|
||||||
|
"tMR": "65535"
|
||||||
|
}
|
||||||
|
|
||||||
|
default_weather_icon_color_mapping = {
|
||||||
|
#"item-per HA" "color in decimal RGB 565 (0-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 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, 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 in ["tMainIcon", "tF1Icon", "tF2Icon", "tF3Icon", "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
|
||||||
Reference in New Issue
Block a user