mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2025-12-21 15:04:24 +01:00
.
This commit is contained in:
@@ -9,7 +9,7 @@ class HAEntity(panel_cards.Entity):
|
|||||||
def __init__(self, locale, config, panel):
|
def __init__(self, locale, config, panel):
|
||||||
super().__init__(locale, config, panel)
|
super().__init__(locale, config, panel)
|
||||||
|
|
||||||
def render(self):
|
def render(self, cardType=""):
|
||||||
# get data from HA
|
# get data from HA
|
||||||
data = libs.home_assistant.get_entity_data(self.entity_id)
|
data = libs.home_assistant.get_entity_data(self.entity_id)
|
||||||
if data:
|
if data:
|
||||||
@@ -130,33 +130,30 @@ class HAEntity(panel_cards.Entity):
|
|||||||
etype=self.etype, action="stop", device_class=device_class)
|
etype=self.etype, action="stop", device_class=device_class)
|
||||||
icon_stop_status = "enable"
|
icon_stop_status = "enable"
|
||||||
value = f"{icon_up}|{icon_stop}|{icon_down}|{icon_up_status}|{icon_stop_status}|{icon_down_status}"
|
value = f"{icon_up}|{icon_stop}|{icon_down}|{icon_up_status}|{icon_stop_status}|{icon_down_status}"
|
||||||
|
case 'sensor':
|
||||||
|
device_class = self.attributes.get("device_class", "")
|
||||||
|
unit_of_measurement = self.attributes.get("unit_of_measurement", "")
|
||||||
|
value = self.state
|
||||||
|
# limit value to 4 chars on us-p
|
||||||
|
if self.panel.model == "us-p" and cardType == "cardEntities":
|
||||||
|
value = self.state[:4]
|
||||||
|
if value[-1] == ".":
|
||||||
|
value = value[:-1]
|
||||||
|
|
||||||
|
if device_class != "temperature":
|
||||||
|
value = value + " "
|
||||||
|
value = value + unit_of_measurement
|
||||||
|
print(f"fuck {cardType} {value} {self.icon_overwrite}")
|
||||||
|
if cardType in ["cardGrid", "cardGrid2"] and not self.icon_overwrite:
|
||||||
|
icon_char = value
|
||||||
|
|
||||||
|
case 'binary_sensor':
|
||||||
|
device_class = self.attributes.get("device_class", "")
|
||||||
|
value = get_translation(self.locale, f"backend.component.binary_sensor.state.{device_class}.{entity.state}")
|
||||||
|
|
||||||
case _:
|
case _:
|
||||||
name = "unsupported"
|
name = "unsupported"
|
||||||
|
|
||||||
# elif entityType in ["sensor", "binary_sensor"]:
|
|
||||||
# entityTypePanel = "text"
|
|
||||||
# device_class = entity.attributes.get("device_class", "")
|
|
||||||
# unit_of_measurement = entity.attributes.get(
|
|
||||||
# "unit_of_measurement", "")
|
|
||||||
# value = entity.state
|
|
||||||
# # limit value to 4 chars on us-p
|
|
||||||
# if self._config.get("model") == "us-p" and cardType == "cardEntities":
|
|
||||||
# value = entity.state[:4]
|
|
||||||
# if value[-1] == ".":
|
|
||||||
# value = value[:-1]
|
|
||||||
# if device_class != "temperature":
|
|
||||||
# value = value + " "
|
|
||||||
# value = value + unit_of_measurement
|
|
||||||
# if entityType == "binary_sensor":
|
|
||||||
# value = get_translation(
|
|
||||||
# self._locale, f"backend.component.binary_sensor.state.{device_class}.{entity.state}")
|
|
||||||
# if (cardType == "cardGrid" or cardType == "cardGrid2") and entityType == "sensor" and icon is None:
|
|
||||||
# icon_id = entity.state[:4]
|
|
||||||
# if icon_id[-1] == ".":
|
|
||||||
# icon_id = icon_id[:-1]
|
|
||||||
# else:
|
|
||||||
# icon_id = get_icon_ha(entityId, overwrite=icon)
|
|
||||||
|
|
||||||
# elif entityType == "weather":
|
# elif entityType == "weather":
|
||||||
# entityTypePanel = "text"
|
# entityTypePanel = "text"
|
||||||
# unit = get_attr_safe(entity, "temperature_unit", "")
|
# unit = get_attr_safe(entity, "temperature_unit", "")
|
||||||
@@ -228,7 +225,7 @@ class EntitiesCard(HACard):
|
|||||||
def render(self):
|
def render(self):
|
||||||
result = f"{self.title}~{self.gen_nav()}"
|
result = f"{self.title}~{self.gen_nav()}"
|
||||||
for e in self.entities:
|
for e in self.entities:
|
||||||
result += e.render()
|
result += e.render(cardType=self.type)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
class QRCard(HACard):
|
class QRCard(HACard):
|
||||||
@@ -290,7 +287,7 @@ def card_factory(locale, settings, panel):
|
|||||||
|
|
||||||
def entity_factory(locale, settings, panel):
|
def entity_factory(locale, settings, panel):
|
||||||
etype = settings["entity"].split(".")[0]
|
etype = settings["entity"].split(".")[0]
|
||||||
if etype in ["delete", "navigate"]:
|
if etype in ["delete", "navigate", "iText"]:
|
||||||
entity = panel_cards.Entity(locale, settings, panel)
|
entity = panel_cards.Entity(locale, settings, panel)
|
||||||
else:
|
else:
|
||||||
entity = HAEntity(locale, settings, panel)
|
entity = HAEntity(locale, settings, panel)
|
||||||
|
|||||||
@@ -123,10 +123,15 @@ def connect_and_loop():
|
|||||||
libs.panel_cmd.init(client)
|
libs.panel_cmd.init(client)
|
||||||
|
|
||||||
# Create NsPanel object
|
# Create NsPanel object
|
||||||
for name, settings in settings["nspanels"].items():
|
for name, settings_panel in settings["nspanels"].items():
|
||||||
panels[name] = LovelaceUIPanel(client, name, settings)
|
if "timezone" not in settings_panel:
|
||||||
|
settings_panel["timezone"] = settings.get("timezone", "Europe/Berlin")
|
||||||
|
if "locale" not in settings_panel:
|
||||||
|
settings_panel["timezone"] = settings.get("locale", "en_US")
|
||||||
|
|
||||||
|
panels[name] = LovelaceUIPanel(client, name, settings_panel)
|
||||||
libs.panel_cmd.page_type(
|
libs.panel_cmd.page_type(
|
||||||
settings["panelSendTopic"], "pageStartup")
|
settings_panel["panelSendTopic"], "pageStartup")
|
||||||
|
|
||||||
# Loop MQTT
|
# Loop MQTT
|
||||||
client.loop_forever()
|
client.loop_forever()
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ class LovelaceUIPanel:
|
|||||||
self.name = name_panel
|
self.name = name_panel
|
||||||
self.settings = settings_panel
|
self.settings = settings_panel
|
||||||
self.sendTopic = self.settings["panelSendTopic"]
|
self.sendTopic = self.settings["panelSendTopic"]
|
||||||
|
self.model = self.settings.get("model", "eu")
|
||||||
|
|
||||||
|
|
||||||
self.current_card = None
|
self.current_card = None
|
||||||
self.privious_cards = []
|
self.privious_cards = []
|
||||||
|
|||||||
@@ -25,12 +25,13 @@ class Entity:
|
|||||||
self.entity_id = config["entity"]
|
self.entity_id = config["entity"]
|
||||||
self.etype = self.entity_id.split(".")[0]
|
self.etype = self.entity_id.split(".")[0]
|
||||||
self.panel = panel
|
self.panel = panel
|
||||||
self.icon_overwrite = config.get("icon", "")
|
self.icon_overwrite = config.get("icon", None)
|
||||||
|
self.name_overwrite = config.get("name", None)
|
||||||
|
|
||||||
def render(self):
|
def render(self, cardType=""):
|
||||||
icon_char = self.icon_overwrite
|
icon_char = self.icon_overwrite or ""
|
||||||
color = rgb_dec565([255, 255, 255])
|
color = rgb_dec565([255, 255, 255])
|
||||||
name = ""
|
name = self.name_overwrite or ""
|
||||||
value = ""
|
value = ""
|
||||||
match self.etype:
|
match self.etype:
|
||||||
case 'delete':
|
case 'delete':
|
||||||
@@ -45,3 +46,7 @@ class Entity:
|
|||||||
return f"~button~{self.entity_id}~{get_icon_char(icon_char)}~{color}~{name}~{value}"
|
return f"~button~{self.entity_id}~{get_icon_char(icon_char)}~{color}~{name}~{value}"
|
||||||
else:
|
else:
|
||||||
return f"~text~{self.entity_id}~{get_icon_char('mdi:alert-circle-outline')}~17299~page not found~"
|
return f"~text~{self.entity_id}~{get_icon_char('mdi:alert-circle-outline')}~17299~page not found~"
|
||||||
|
case 'iText':
|
||||||
|
# TODO: Render as HA Template
|
||||||
|
value = self.entity_id.split(".")[1]
|
||||||
|
return f"~text~{self.entity_id}~{get_icon_char(icon_char)}~{color}~{name}~{value}"
|
||||||
|
|||||||
Reference in New Issue
Block a user