From ed207b6e1a7c38800528a9fcc71b26963211a871 Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 24 Mar 2022 20:14:15 +0100 Subject: [PATCH 1/2] Rename `getEntityColor` to `get_entity_color` I have also set a minimum brightness for the icon otherwise it's almost not visible anymore when the brightness value is very low. What do you think? --- apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py b/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py index 2b75be1e..c54f3cfe 100644 --- a/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py +++ b/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py @@ -462,14 +462,14 @@ class LovelaceUIPanel: if item_type == "light": switch_val = 1 if entity.state == "on" else 0 - icon_color = self.getEntityColor(entity) + icon_color = self.get_entity_color(entity) icon_id = get_icon_id_ha("light", overwrite=icon) return f",{item_type},{item},{icon_id},{icon_color},{name},{switch_val}" if item_type in ["switch", "input_boolean"]: icon_id = get_icon_id_ha(item_type, state=entity.state, overwrite=icon) switch_val = 1 if entity.state == "on" else 0 - icon_color = self.getEntityColor(entity) + icon_color = self.get_entity_color(entity) return f",switch,{item},{icon_id},{icon_color},{name},{switch_val}" if item_type in ["sensor", "binary_sensor"]: @@ -477,7 +477,7 @@ class LovelaceUIPanel: icon_id = get_icon_id_ha("sensor", state=entity.state, device_class=device_class, overwrite=icon) unit_of_measurement = self.get_safe_ha_attribute(entity.attributes, "unit_of_measurement", "") value = entity.state + " " + unit_of_measurement - icon_color = self.getEntityColor(entity) + icon_color = self.get_entity_color(entity) return f",text,{item},{icon_id},{icon_color},{name},{value}" if item_type in ["button", "input_button"]: @@ -576,7 +576,7 @@ class LovelaceUIPanel: self.send_mqtt_msg(command) - def getEntityColor(self, entity): + def get_entity_color(self, entity): attr = entity.attributes default_color_on = rgb_dec565([253, 216, 53]) default_color_off = rgb_dec565([68, 115, 158]) @@ -588,14 +588,14 @@ class LovelaceUIPanel: color = rgb_brightness(color, attr.brightness) icon_color = rgb_dec565(color) elif "brightness" in attr: - color = rgb_brightness([253, 216, 53], attr.brightness) + color = rgb_brightness([253, 216, 53], max(70, attr.brightness)) icon_color = rgb_dec565(color) return icon_color def generate_light_detail_page(self, entity): entity = self.api.get_entity(entity) switch_val = 1 if entity.state == "on" else 0 - icon_color = self.getEntityColor(entity) + icon_color = self.get_entity_color(entity) brightness = "disable" color_temp = "disable" color = "disable" From 77b05b80799b56a97af8756143d5381e3d126912 Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 25 Mar 2022 15:46:03 +0100 Subject: [PATCH 2/2] add min brightness --- apps/nspanel-lovelace-ui/luibackend/pages.py | 2 +- apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/nspanel-lovelace-ui/luibackend/pages.py b/apps/nspanel-lovelace-ui/luibackend/pages.py index 5c3dadc9..150c29e5 100644 --- a/apps/nspanel-lovelace-ui/luibackend/pages.py +++ b/apps/nspanel-lovelace-ui/luibackend/pages.py @@ -34,7 +34,7 @@ class LuiPagesGen(object): color = rgb_brightness(color, attr.brightness) icon_color = rgb_dec565(color) elif "brightness" in attr: - color = rgb_brightness([253, 216, 53], attr.brightness) + color = rgb_brightness([253, 216, 53], max(70, attr.brightness)) icon_color = rgb_dec565(color) return icon_color diff --git a/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py b/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py index 5d64dc28..1d26825b 100644 --- a/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py +++ b/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py @@ -76,4 +76,4 @@ class NsPanelLovelaceUIManager(hass.Hass): topic_recv = cfg.get("panelRecvTopic") LuiMqttListener(mqtt_api, topic_recv, controller, updater) - LOGGER.info('Started') \ No newline at end of file + LOGGER.info('Started')