From a3941c36fc0d949e57565c06e3196ea6f53f3f63 Mon Sep 17 00:00:00 2001 From: Johannes Date: Sat, 20 Aug 2022 16:03:21 +0200 Subject: [PATCH] implement assumed state --- apps/nspanel-lovelace-ui/luibackend/config.py | 1 + apps/nspanel-lovelace-ui/luibackend/pages.py | 32 ++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/apps/nspanel-lovelace-ui/luibackend/config.py b/apps/nspanel-lovelace-ui/luibackend/config.py index b387f5d1..52559918 100644 --- a/apps/nspanel-lovelace-ui/luibackend/config.py +++ b/apps/nspanel-lovelace-ui/luibackend/config.py @@ -14,6 +14,7 @@ class Entity(object): self.status = entity_input_config.get("status") self.condState = entity_input_config.get("state") self.condStateNot = entity_input_config.get("state_not") + self.assumedState = entity-input_config.get("assumed_state", False) class Card(object): def __init__(self, card_input_config, pos=None): diff --git a/apps/nspanel-lovelace-ui/luibackend/pages.py b/apps/nspanel-lovelace-ui/luibackend/pages.py index 0ae54e4b..9d6e9759 100644 --- a/apps/nspanel-lovelace-ui/luibackend/pages.py +++ b/apps/nspanel-lovelace-ui/luibackend/pages.py @@ -22,7 +22,7 @@ class LuiPagesGen(object): self._locale = config.get("locale") self._send_mqtt_msg = send_mqtt_msg - def get_entity_color(self, entity, overwrite=None): + def get_entity_color(self, entity, ha_type=None, overwrite=None): if overwrite is not None: if type(overwrite) is list: return rgb_dec565(overwrite) @@ -31,11 +31,23 @@ class LuiPagesGen(object): for overwrite_state, overwrite_val in overwrite.items(): if overwrite_state == state: return rgb_dec565(overwrite_val) - + attr = entity.attributes default_color_on = rgb_dec565([253, 216, 53]) default_color_off = rgb_dec565([68, 115, 158]) - icon_color = default_color_on if entity.state in ["on", "unlocked"] else default_color_off + icon_color = default_color_on if entity.state in ["on", "unlocked", "above_horizon"] else default_color_off + + if ha_type == "alarm_control_panel": + if entity.state == "disarmed": + icon_color = rgb_dec565([13,160,53]) + if entity.state == "armed_home": + icon_color = rgb_dec565([223,76,30]) + if entity.state == "armed_away": + icon_color = rgb_dec565([223,76,30]) + if entity.state == "armed_night": + icon_color = rgb_dec565([223,76,30]) + if entity.state == "armed_vacation": + icon_color = rgb_dec565([223,76,30]) if "rgb_color" in attr: color = attr.rgb_color @@ -230,11 +242,11 @@ class LuiPagesGen(object): else: pos_status = pos if bits & 0b00000001: # SUPPORT_OPEN - if pos != 100 and not (entity.state == "open" and pos == "disable"): + if pos != 100 and not (entity.state == "open" and pos == "disable") and not item.assumedState: icon_up_status = "enable" icon_up = get_action_id_ha(ha_type=entityType, action="open", device_class=device_class) if bits & 0b00000010: # SUPPORT_CLOSE - if pos != 0 and not (entity.state == "closed" and pos == "disable"): + if pos != 0 and not (entity.state == "closed" and pos == "disable") and not item.assumedState: icon_down_status = "enable" icon_down = get_action_id_ha(ha_type=entityType, action="close", device_class=device_class) if bits & 0b00001000: # SUPPORT_STOP @@ -307,6 +319,16 @@ class LuiPagesGen(object): else: text = "Return" return f"~button~{entityId}~{icon_id}~17299~{name}~{text}" + if entityType == "alarm_control_panel": + icon_color = self.get_entity_color(entity, ha_type=entityType, overwrite=colorOverride) + icon_id = get_icon_id_ha(entityType, state=entity.state, overwrite=icon) + text = get_translation(self._locale, f"frontend.state_badge.alarm_control_panel.{entity.state}") + return f"~text~{entityId}~{icon_id}~{icon_color}~{name}~{text}" + if entityType == "sun": + icon_color = self.get_entity_color(entity, overwrite=colorOverride) + icon_id = get_icon_id_ha(entityType, state=entity.state, overwrite=icon) + text = get_translation(self._locale, f"backend.component.sun.state._.{entity.state}") + return f"~text~{entityId}~{icon_id}~{icon_color}~{name}~{text}" return f"~text~{entityId}~{get_icon_id('alert-circle-outline')}~17299~unsupported~" def generate_entities_page(self, navigation, heading, items, cardType):