added localization support for date

This commit is contained in:
joBr99
2022-03-16 23:39:36 +01:00
committed by GitHub
parent 044e4ee638
commit f91e27781f
5 changed files with 33 additions and 11 deletions

View File

@@ -84,6 +84,13 @@ The easiest way to install it is through Home Assistant's Supervisor Add-on Stor
![hass-add-on-store](doc-pics/hass-add-on-store.png)
#### Add babel package to AppDaemon Container (Optional)
For localisation format (date in your local language) you need to add the python package babel to your AppDaemon Installation.
![appdaemon-babel](doc-pics/appdaemon-babel.png)
### Installing Studio Code Server (optional, recommended)
You will need a way to edit the `apps.yaml` config file in the Appdaemon folder.
@@ -251,9 +258,10 @@ nspanel-1:
value: 10
- time: "23:00:00"
value: 0
locale: "de_DE"
locale: "de_DE" # only used if babel python package is installed
dateFormatBabel: "full" # only used if babel python package is installed
timeFormat: "%H:%M"
dateFormat: "%A, %d. %B %Y"
dateFormat: "%A, %d. %B %Y" # ignored if babel python package is installed
weatherEntity: weather.example
pages:
- type: cardEntities

View File

@@ -12,9 +12,10 @@ nspanel:
value: 10
- time: "23:00:00"
value: 0
locale: "de_DE"
locale: "de_DE" # only used if babel python package is installed
dateFormatBabel: "full" # only used if babel python package is installed
timeFormat: "%H:%M"
dateFormat: "%A, %d. %B %Y"
dateFormat: "%A, %d. %B %Y" # ignored if babel python package is installed
weatherEntity: weather.example
pages:
- type: cardEntities

View File

@@ -1,7 +1,6 @@
import json
import datetime
import hassapi as hass
import math
import colorsys
@@ -141,9 +140,22 @@ class NsPanelLovelaceUI:
self.send_mqtt_msg("time,{0}".format(time))
def update_date(self, kwargs):
# TODO: implement localization of date
date = datetime.datetime.now().strftime(self.config["dateFormat"])
self.send_mqtt_msg("date,?{0}".format(date))
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 "dateFormatBabel" in self.config:
dateformat = self.config["dateFormatBabel"]
else:
dateformat = "full"
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")
date = datetime.datetime.now().strftime(self.config["dateFormat"])
self.send_mqtt_msg(f"date,?{date}")
def update_screensaver_brightness(self, kwargs):
self.current_screensaver_brightness = kwargs['value']
@@ -542,4 +554,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

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -18,9 +18,10 @@ nspanel-1:
value: 10
- time: "23:00:00"
value: 0
locale: "de_DE"
locale: "de_DE" # only used if babel python package is installed
dateFormatBabel: "full" # only used if babel python package is installed
timeFormat: "%H:%M"
dateFormat: "%A, %d. %B %Y"
dateFormat: "%A, %d. %B %Y" # ignored if babel python package is installed
weatherEntity: weather.example
pages:
- type: cardEntities