mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2025-12-24 08:24:25 +01:00
Add localization for weather forecast
Show the day in local format for the weather forecast
This commit is contained in:
@@ -4,6 +4,13 @@ import hassapi as hass
|
||||
import math
|
||||
import colorsys
|
||||
|
||||
# check Babel
|
||||
import importlib
|
||||
babel_spec = importlib.util.find_spec("babel")
|
||||
if babel_spec is not None:
|
||||
import babel.dates
|
||||
|
||||
|
||||
class NsPanelLovelaceUIManager(hass.Hass):
|
||||
def initialize(self):
|
||||
|
||||
@@ -20,6 +27,8 @@ class NsPanelLovelaceUI:
|
||||
# check configured items
|
||||
self.check_items()
|
||||
|
||||
self.babel_spec = importlib.util.find_spec("babel")
|
||||
|
||||
# Setup, mqtt subscription and callback
|
||||
self.mqtt = self.api.get_plugin_api("MQTT")
|
||||
self.mqtt.mqtt_subscribe(topic=self.config["panelRecvTopic"])
|
||||
@@ -140,12 +149,8 @@ class NsPanelLovelaceUI:
|
||||
self.send_mqtt_msg("time,{0}".format(time))
|
||||
|
||||
def update_date(self, kwargs):
|
||||
|
||||
import importlib
|
||||
babel_spec = importlib.util.find_spec("babel")
|
||||
if babel_spec is not None:
|
||||
self.api.log("babel package found", level="DEBUG")
|
||||
import babel.dates
|
||||
if self.babel_spec is not None:
|
||||
self.api.log("Babel package found", level="DEBUG")
|
||||
if "dateFormatBabel" in self.config:
|
||||
dateformat = self.config["dateFormatBabel"]
|
||||
else:
|
||||
@@ -153,7 +158,7 @@ class NsPanelLovelaceUI:
|
||||
date = babel.dates.format_date(datetime.datetime.now(), dateformat, locale=self.config["locale"])
|
||||
self.send_mqtt_msg(f"date,?{date}")
|
||||
else:
|
||||
self.api.log("babel package not found", level="DEBUG")
|
||||
self.api.log("Babel package not found", level="DEBUG")
|
||||
date = datetime.datetime.now().strftime(self.config["dateFormat"])
|
||||
self.send_mqtt_msg(f"date,?{date}")
|
||||
|
||||
@@ -187,12 +192,12 @@ class NsPanelLovelaceUI:
|
||||
|
||||
o1 = we.attributes.forecast[0]['datetime']
|
||||
o1 = datetime.datetime.fromisoformat(o1)
|
||||
o1 = o1.strftime("%a")
|
||||
o1 = babel.dates.format_date(o1, "E", locale=self.config["locale"])
|
||||
i1 = weathericons[we.attributes.forecast[0]['condition']]
|
||||
u1 = we.attributes.forecast[0]['temperature']
|
||||
o2 = we.attributes.forecast[1]['datetime']
|
||||
o2 = datetime.datetime.fromisoformat(o2)
|
||||
o2 = o2.strftime("%a")
|
||||
o2 = babel.dates.format_date(o2, "E", locale=self.config["locale"])
|
||||
i2 = weathericons[we.attributes.forecast[1]['condition']]
|
||||
u2 = we.attributes.forecast[1]['temperature']
|
||||
self.send_mqtt_msg(f"weatherUpdate,?{weathericons[we.state]}?{we.attributes.temperature}{unit}?{26}?{we.attributes.humidity} %?{o1}?{i1}?{u1}?{o2}?{i2}?{u2}")
|
||||
@@ -554,4 +559,4 @@ class NsPanelLovelaceUI:
|
||||
sat = r
|
||||
hsv = (math.degrees(math.atan2(y, x))%360/360, sat, 1)
|
||||
rgb = self.hsv2rgb(hsv[0],hsv[1],hsv[2])
|
||||
return rgb
|
||||
return rgb
|
||||
|
||||
Reference in New Issue
Block a user