diff --git a/nspanel-lovelace-ui/rootfs/usr/bin/mqtt-manager/ha_cards.py b/nspanel-lovelace-ui/rootfs/usr/bin/mqtt-manager/ha_cards.py index 9835faf8..e50507cd 100644 --- a/nspanel-lovelace-ui/rootfs/usr/bin/mqtt-manager/ha_cards.py +++ b/nspanel-lovelace-ui/rootfs/usr/bin/mqtt-manager/ha_cards.py @@ -9,7 +9,7 @@ class HAEntity(panel_cards.Entity): def __init__(self, locale, config, panel): super().__init__(locale, config, panel) - def render(self): + def render(self, cardType=""): # get data from HA data = libs.home_assistant.get_entity_data(self.entity_id) if data: @@ -130,33 +130,30 @@ class HAEntity(panel_cards.Entity): etype=self.etype, action="stop", device_class=device_class) icon_stop_status = "enable" 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 _: 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": # entityTypePanel = "text" # unit = get_attr_safe(entity, "temperature_unit", "") @@ -228,7 +225,7 @@ class EntitiesCard(HACard): def render(self): result = f"{self.title}~{self.gen_nav()}" for e in self.entities: - result += e.render() + result += e.render(cardType=self.type) return result class QRCard(HACard): @@ -290,7 +287,7 @@ def card_factory(locale, settings, panel): def entity_factory(locale, settings, panel): etype = settings["entity"].split(".")[0] - if etype in ["delete", "navigate"]: + if etype in ["delete", "navigate", "iText"]: entity = panel_cards.Entity(locale, settings, panel) else: entity = HAEntity(locale, settings, panel) diff --git a/nspanel-lovelace-ui/rootfs/usr/bin/mqtt-manager/main.py b/nspanel-lovelace-ui/rootfs/usr/bin/mqtt-manager/main.py index 5f0effa4..64d766d3 100644 --- a/nspanel-lovelace-ui/rootfs/usr/bin/mqtt-manager/main.py +++ b/nspanel-lovelace-ui/rootfs/usr/bin/mqtt-manager/main.py @@ -123,10 +123,15 @@ def connect_and_loop(): libs.panel_cmd.init(client) # Create NsPanel object - for name, settings in settings["nspanels"].items(): - panels[name] = LovelaceUIPanel(client, name, settings) + for name, settings_panel in settings["nspanels"].items(): + 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( - settings["panelSendTopic"], "pageStartup") + settings_panel["panelSendTopic"], "pageStartup") # Loop MQTT client.loop_forever() diff --git a/nspanel-lovelace-ui/rootfs/usr/bin/mqtt-manager/panel.py b/nspanel-lovelace-ui/rootfs/usr/bin/mqtt-manager/panel.py index adebe3c1..d1b2f5c7 100644 --- a/nspanel-lovelace-ui/rootfs/usr/bin/mqtt-manager/panel.py +++ b/nspanel-lovelace-ui/rootfs/usr/bin/mqtt-manager/panel.py @@ -18,6 +18,8 @@ class LovelaceUIPanel: self.name = name_panel self.settings = settings_panel self.sendTopic = self.settings["panelSendTopic"] + self.model = self.settings.get("model", "eu") + self.current_card = None self.privious_cards = [] diff --git a/nspanel-lovelace-ui/rootfs/usr/bin/mqtt-manager/panel_cards.py b/nspanel-lovelace-ui/rootfs/usr/bin/mqtt-manager/panel_cards.py index 06b2f8a2..07cd1ffa 100644 --- a/nspanel-lovelace-ui/rootfs/usr/bin/mqtt-manager/panel_cards.py +++ b/nspanel-lovelace-ui/rootfs/usr/bin/mqtt-manager/panel_cards.py @@ -25,12 +25,13 @@ class Entity: self.entity_id = config["entity"] self.etype = self.entity_id.split(".")[0] 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): - icon_char = self.icon_overwrite + def render(self, cardType=""): + icon_char = self.icon_overwrite or "" color = rgb_dec565([255, 255, 255]) - name = "" + name = self.name_overwrite or "" value = "" match self.etype: case 'delete': @@ -45,3 +46,7 @@ class Entity: return f"~button~{self.entity_id}~{get_icon_char(icon_char)}~{color}~{name}~{value}" else: 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}"