From 41c90f68ce6ae14e9018ddbcb879953de51dc3df Mon Sep 17 00:00:00 2001 From: Johannes Date: Mon, 21 Mar 2022 10:52:55 +0100 Subject: [PATCH] changed color on state --- .../nspanel-lovelace-ui.py | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py b/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py index b4dff8a1..8669bb59 100644 --- a/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py +++ b/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py @@ -484,15 +484,7 @@ class NsPanelLovelaceUI: if item_type == "light": switch_val = 1 if entity.state == "on" else 0 - icon_color = 17299 - if "rgb_color" in entity.attributes: - color = entity.attributes.rgb_color - if "brightness" in entity.attributes: - color = rgb_brightness(color, entity.attributes.brightness) - icon_color = rgb_dec565(color) - elif "brightness" in entity.attributes: - color = rgb_brightness([253, 216, 53], entity.attributes.brightness) - icon_color = rgb_dec565(color) + icon_color = getEntityColor(entity) return f",{item_type},{item},{get_icon_id('lightbulb')},{icon_color},{name},{switch_val}" if item_type == "switch" or item_type == "input_boolean": @@ -630,22 +622,29 @@ class NsPanelLovelaceUI: return f"entityUpd,|{item}|{heading}|{icon}|{title}|{author}|{volume}|{iconplaypause}" + def getEntityColor(self, entity): + 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 == "on" else default_color_off + + if "rgb_color" in attr: + color = attr.rgb_color + if "brightness" in attr: + color = rgb_brightness(color, attr.brightness) + icon_color = rgb_dec565(color) + elif "brightness" in attr: + color = rgb_brightness([253, 216, 53], attr.brightness) + icon_color = rgb_dec565(color) + return icon_color + def generate_detail_page(self, page_type, entity): if page_type == "popupLight": entity = self.api.get_entity(entity) switch_val = 1 if entity.state == "on" else 0 - icon_color = 17299 - - if "rgb_color" in entity.attributes: - color = entity.attributes.rgb_color - if "brightness" in entity.attributes: - color = rgb_brightness(color, entity.attributes.brightness) - icon_color = rgb_dec565(color) - elif "brightness" in entity.attributes: - color = rgb_brightness([253, 216, 53], entity.attributes.brightness) - icon_color = rgb_dec565(color) + icon_color = getEntityColor(entity) brightness = "disable" color_temp = "disable" @@ -681,4 +680,4 @@ class NsPanelLovelaceUI: def send_message_page(self, id, heading, msg, b1, b2): self.send_mqtt_msg(f"pageType,popupNotify") self.send_mqtt_msg(f"entityUpdateDetail,|{id}|{heading}|65535|{b1}|65535|{b2}|65535|{msg}|65535|0") - + \ No newline at end of file