diff --git a/README.md b/README.md index a663c62f..75b6eda9 100644 --- a/README.md +++ b/README.md @@ -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"` `dateFormat` | True | string | `%A, %d. %B %Y` | date format used if babel is not installed `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 `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 diff --git a/apps/nspanel-lovelace-ui/luibackend/config.py b/apps/nspanel-lovelace-ui/luibackend/config.py index f6c4774b..79251208 100644 --- a/apps/nspanel-lovelace-ui/luibackend/config.py +++ b/apps/nspanel-lovelace-ui/luibackend/config.py @@ -109,7 +109,7 @@ class LuiBackendConfig(object): 'dateFormatBabel': "full", 'dateFormat': "%A, %d. %B %Y", 'weather': 'weather.example', - 'weatherUnit': '°C', + 'weatherUnit': 'celsius', 'weatherOverrideForecast1': None, 'weatherOverrideForecast2': None, 'weatherOverrideForecast3': None, diff --git a/apps/nspanel-lovelace-ui/luibackend/helper.py b/apps/nspanel-lovelace-ui/luibackend/helper.py index b6b3b794..5a9d491c 100644 --- a/apps/nspanel-lovelace-ui/luibackend/helper.py +++ b/apps/nspanel-lovelace-ui/luibackend/helper.py @@ -43,6 +43,13 @@ def rgb_dec565(rgb_color): # 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))) +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): res = entity.attributes.get(attr, default) if res is None: diff --git a/apps/nspanel-lovelace-ui/luibackend/pages.py b/apps/nspanel-lovelace-ui/luibackend/pages.py index 06a2719a..e848fa14 100644 --- a/apps/nspanel-lovelace-ui/luibackend/pages.py +++ b/apps/nspanel-lovelace-ui/luibackend/pages.py @@ -3,7 +3,7 @@ import datetime from icon_mapping import get_icon_id 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 # check Babel @@ -71,7 +71,7 @@ class LuiPagesGen(object): return 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 = "" for i in range(1,5): @@ -84,7 +84,7 @@ class LuiPagesGen(object): else: up = up.strftime("%a") 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: LOGGER.info(f"Forecast {i} is overriden with {wOF}") icon = None