mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2025-12-21 15:04:24 +01:00
implement some local templates
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# https://developers.home-assistant.io/docs/add-ons/configuration#add-on-config
|
||||
name: NSPanel Lovelace UI Addon
|
||||
version: "4.7.34"
|
||||
version: "4.7.35"
|
||||
slug: nspanel-lovelace-ui
|
||||
description: NSPanel Lovelace UI Addon
|
||||
services:
|
||||
|
||||
@@ -8,6 +8,7 @@ import dateutil.parser as dp
|
||||
import babel
|
||||
from libs.icon_mapping import get_icon_char
|
||||
from libs.helper import rgb_dec565, scale
|
||||
import ha_template
|
||||
|
||||
class HAEntity(panel_cards.Entity):
|
||||
def __init__(self, locale, config, panel):
|
||||
@@ -15,10 +16,6 @@ class HAEntity(panel_cards.Entity):
|
||||
|
||||
def render(self, cardType=""):
|
||||
|
||||
if self.icon_overwrite and self.icon_overwrite.startswith("ha:"):
|
||||
out = libs.home_assistant.render_template(self.icon_overwrite[3:])
|
||||
self.icon_overwrite = out
|
||||
|
||||
if self.etype in ["delete", "navigate", "iText"]:
|
||||
out = super().render()
|
||||
if self.etype == "navigate" and "status" in self.config:
|
||||
@@ -44,9 +41,7 @@ class HAEntity(panel_cards.Entity):
|
||||
entity_type_panel = "text"
|
||||
icon_char = ha_icons.get_icon_ha(self.etype, self.state, device_class=self.attributes.get("device_class", None), media_content_type=self.attributes.get("media_content_type", None), overwrite=self.config.get("icon"))
|
||||
color = ha_colors.get_entity_color(
|
||||
self.etype, self.state, self.attributes)
|
||||
if self.color_overwrite:
|
||||
color = rgb_dec565(self.color_overwrite)
|
||||
self.etype, self.state, self.attributes, self.color_overwrite)
|
||||
name = self.config.get("name", self.attributes.get("friendly_name", "unknown"))
|
||||
if self.name_overwrite:
|
||||
name = self.name_overwrite
|
||||
@@ -217,6 +212,14 @@ class HAEntity(panel_cards.Entity):
|
||||
case _:
|
||||
name = "unsupported"
|
||||
|
||||
|
||||
if self.icon_overwrite and self.icon_overwrite.startswith("ha:"):
|
||||
#icon_char = libs.home_assistant.render_template(self.icon_overwrite[3:])
|
||||
icon_char = ha_template.render(self.icon_overwrite[3:])
|
||||
|
||||
if self.value_overwrite and self.value_overwrite.startswith("ha:"):
|
||||
value = ha_template.render(self.value_overwrite[3:])
|
||||
|
||||
return f"~{entity_type_panel}~iid.{self.iid}~{icon_char}~{color}~{name}~{value}"
|
||||
|
||||
class HACard(panel_cards.Card):
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
from jinja2 import Environment, BaseLoader
|
||||
from typing import (
|
||||
Any
|
||||
)
|
||||
import libs.home_assistant
|
||||
|
||||
def states(entity_id):
|
||||
return libs.home_assistant.get_entity_data(entity_id).get("state")
|
||||
|
||||
def state_attr(entity_id, attr):
|
||||
return libs.home_assistant.get_entity_data(entity_id).get('attributes', []).get(attr)
|
||||
|
||||
def iif(value: Any, if_true: Any = True, if_false: Any = False, if_none: Any = False) -> Any:
|
||||
if value is None:
|
||||
return if_none
|
||||
if bool(value):
|
||||
return if_true
|
||||
return if_false
|
||||
|
||||
func_dict = {
|
||||
"states": states,
|
||||
"state_attr": state_attr,
|
||||
"iif": iif
|
||||
}
|
||||
|
||||
def render(template):
|
||||
jinja_template = Environment(loader=BaseLoader()).from_string(template)
|
||||
jinja_template.globals.update(func_dict)
|
||||
template_string = jinja_template.render()
|
||||
return template_string
|
||||
@@ -193,7 +193,7 @@ def execute_script(entity_name: str, domain: str, service: str, service_data: di
|
||||
}
|
||||
send_message(json.dumps(msg))
|
||||
# busy waiting for response with a timeout of 0.2 seconds - maybe there's a better way of doing this
|
||||
mustend = time.time() + 0.2
|
||||
mustend = time.time() + 0.4
|
||||
while time.time() < mustend:
|
||||
if response_buffer[call_id] == True:
|
||||
#print(f'loooooooooop {time.time()}')
|
||||
|
||||
@@ -31,6 +31,7 @@ class Entity:
|
||||
self.icon_overwrite = config.get("icon", None)
|
||||
self.name_overwrite = config.get("name", None)
|
||||
self.color_overwrite = config.get("color", None)
|
||||
self.value_overwrite = config.get("value", None)
|
||||
font_mapping = {
|
||||
"small": "1",
|
||||
"medium": "2",
|
||||
|
||||
@@ -6,4 +6,5 @@ django-environ
|
||||
python-dateutil
|
||||
scheduler
|
||||
babel
|
||||
watchdog
|
||||
watchdog
|
||||
jinja2
|
||||
Reference in New Issue
Block a user