mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2025-12-23 16:04:25 +01:00
implemented conversion of temperature
This commit is contained in:
@@ -335,6 +335,7 @@ key | optional | type | default | description
|
|||||||
`timeFormat` | True | string | `%H:%M` | Time Format on screensaver. Substring after `?` is displayed in a seperate smaller textbox. Useful for 12h time format with AM/PM `"%I:%M ?%p"`
|
`timeFormat` | True | string | `%H:%M` | Time Format on screensaver. Substring after `?` is displayed in a seperate smaller textbox. Useful for 12h time format with AM/PM `"%I:%M ?%p"`
|
||||||
`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
|
||||||
`weather` | True | string | `weather.example` | weather entity from homeassistant
|
`weather` | True | string | `weather.example` | weather entity from homeassistant
|
||||||
|
`weatherUnit` | True | string | `celsius` | unit for temperature, valid values are `celsius` or `fahrenheit`
|
||||||
`weatherOverrideForecast1` | True | string | `None` | sensor entity from home assistant here to override the first weather forecast item on the screensaver
|
`weatherOverrideForecast1` | True | string | `None` | sensor entity from home assistant here to override the first weather forecast item on the screensaver
|
||||||
`weatherOverrideForecast2` | True | string | `None` | sensor entity from home assistant here to override the second weather forecast item on the screensaver
|
`weatherOverrideForecast2` | True | string | `None` | sensor entity from home assistant here to override the second weather forecast item on the screensaver
|
||||||
`weatherOverrideForecast3` | True | string | `None` | sensor entity from home assistant here to override the third weather forecast item on the screensaver
|
`weatherOverrideForecast3` | True | string | `None` | sensor entity from home assistant here to override the third weather forecast item on the screensaver
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ class LuiBackendConfig(object):
|
|||||||
'dateFormatBabel': "full",
|
'dateFormatBabel': "full",
|
||||||
'dateFormat': "%A, %d. %B %Y",
|
'dateFormat': "%A, %d. %B %Y",
|
||||||
'weather': 'weather.example',
|
'weather': 'weather.example',
|
||||||
'weatherUnit': '°C',
|
'weatherUnit': 'celsius',
|
||||||
'weatherOverrideForecast1': None,
|
'weatherOverrideForecast1': None,
|
||||||
'weatherOverrideForecast2': None,
|
'weatherOverrideForecast2': None,
|
||||||
'weatherOverrideForecast3': None,
|
'weatherOverrideForecast3': None,
|
||||||
|
|||||||
@@ -43,6 +43,13 @@ def rgb_dec565(rgb_color):
|
|||||||
# and shift them to make them a 16 bit dec value in 565 format.
|
# and shift them to make them a 16 bit dec value in 565 format.
|
||||||
return ((int(red / 255 * 31) << 11) | (int(green / 255 * 63) << 5) | (int(blue / 255 * 31)))
|
return ((int(red / 255 * 31) << 11) | (int(green / 255 * 63) << 5) | (int(blue / 255 * 31)))
|
||||||
|
|
||||||
|
def convert_temperature_from_celsius(c, unit):
|
||||||
|
if unit == "celsius":
|
||||||
|
temp = (c * 1.8) + 32
|
||||||
|
return f"{temp}°F"
|
||||||
|
else:
|
||||||
|
return f"{temp}°C"
|
||||||
|
|
||||||
def get_attr_safe(entity, attr, default):
|
def get_attr_safe(entity, attr, default):
|
||||||
res = entity.attributes.get(attr, default)
|
res = entity.attributes.get(attr, default)
|
||||||
if res is None:
|
if res is None:
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import datetime
|
|||||||
|
|
||||||
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 helper import scale, rgb_dec565, rgb_brightness, get_attr_safe
|
from helper import scale, rgb_dec565, rgb_brightness, get_attr_safe, convert_temperature_from_celsius
|
||||||
from localization import get_translation
|
from localization import get_translation
|
||||||
|
|
||||||
# check Babel
|
# check Babel
|
||||||
@@ -71,7 +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)
|
||||||
text_cur = f"{we.attributes.temperature}{unit}"
|
text_cur = convert_temperature_from_celsius(we.attributes.temperature, unit)
|
||||||
|
|
||||||
weather_res = ""
|
weather_res = ""
|
||||||
for i in range(1,5):
|
for i in range(1,5):
|
||||||
@@ -84,7 +84,7 @@ class LuiPagesGen(object):
|
|||||||
else:
|
else:
|
||||||
up = up.strftime("%a")
|
up = up.strftime("%a")
|
||||||
icon = get_icon_id_ha("weather", state=we.attributes.forecast[i-1]['condition'])
|
icon = get_icon_id_ha("weather", state=we.attributes.forecast[i-1]['condition'])
|
||||||
down = f"{we.attributes.forecast[i-1]['temperature']} {unit}"
|
down = convert_temperature_from_celsius(we.attributes.forecast[i-1]['temperature'], unit)
|
||||||
else:
|
else:
|
||||||
LOGGER.info(f"Forecast {i} is overriden with {wOF}")
|
LOGGER.info(f"Forecast {i} is overriden with {wOF}")
|
||||||
icon = None
|
icon = None
|
||||||
|
|||||||
Reference in New Issue
Block a user