mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2025-12-19 22:24:15 +01:00
added localization support for date
This commit is contained in:
12
README.md
12
README.md
@@ -84,6 +84,13 @@ The easiest way to install it is through Home Assistant's Supervisor Add-on Stor
|
||||
|
||||

|
||||
|
||||
#### 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.
|
||||
|
||||

|
||||
|
||||
|
||||
### 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
BIN
doc-pics/appdaemon-babel.png
Normal file
BIN
doc-pics/appdaemon-babel.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
5
info.md
5
info.md
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user