From 0ca1982ebc7a1fcb4c818022ed955cd3204fcbcf Mon Sep 17 00:00:00 2001 From: joBr99 <29555657+joBr99@users.noreply.github.com> Date: Wed, 1 Feb 2023 21:25:50 +0100 Subject: [PATCH] implement effect fav list --- .../luibackend/controller.py | 25 ++++++++----------- apps/nspanel-lovelace-ui/luibackend/pages.py | 25 ++++++++++++++++--- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/apps/nspanel-lovelace-ui/luibackend/controller.py b/apps/nspanel-lovelace-ui/luibackend/controller.py index 27d0d869..c82916c2 100644 --- a/apps/nspanel-lovelace-ui/luibackend/controller.py +++ b/apps/nspanel-lovelace-ui/luibackend/controller.py @@ -194,6 +194,9 @@ class LuiController(object): def button_press(self, entity_id, button_type, value): apis.ha_api.log(f"Button Press Event; entity_id: {entity_id}; button_type: {button_type}; value: {value} ") + if entity_id.startswith('uuid'): + entity_config = self._config._config_entites_table.get(entity_id) + entity_id = entity_config.entityId # internal buttons if entity_id == "screensaver" and button_type == "bExit": # get default card if there is one @@ -226,14 +229,6 @@ class LuiController(object): if button_type == "bExit": self._pages_gen.render_card(self._current_card) - #if button_type == "bHome": - # if self._previous_cards: - # self._current_card = self._previous_cards[0] - # self._previous_cards.clear() - # else: - # self._current_card = self._config.getCard(0) - # self._pages_gen.render_card(self._current_card) - elif entity_id == "updateDisplayNoYes" and value == "no": self._pages_gen.render_card(self._current_card) @@ -275,10 +270,6 @@ class LuiController(object): if button_type == "button": - if entity_id.startswith('uuid'): - le = self._config._config_entites_table.get(entity_id) - entity_id = le.entityId - if entity_id.startswith('navigate'): # internal navigation for next/prev if entity_id.startswith('navigate.uuid'): @@ -320,7 +311,7 @@ class LuiController(object): else: apis.ha_api.get_entity(entity_id).call_service("return_to_base") elif entity_id.startswith('service'): - apis.ha_api.call_service(entity_id.replace('service.', '', 1).replace('.','/', 1), **le.data) + apis.ha_api.call_service(entity_id.replace('service.', '', 1).replace('.','/', 1), **entity_config.data) # for media page if button_type == "media-next": @@ -419,8 +410,12 @@ class LuiController(object): if button_type == "mode-light": entity = apis.ha_api.get_entity(entity_id) - option = entity.attributes.effect_list[int(value)] - entity.call_service("select_effect", option=option) + options_list = entity_config.entity_input_config.get("effectList") + if options_list is not None: + option = options_list[int(value)] + else: + option = entity.attributes.effect_list[int(value)] + entity.call_service("turn_on", effect=option) if button_type == "mode-media_player": entity = apis.ha_api.get_entity(entity_id) diff --git a/apps/nspanel-lovelace-ui/luibackend/pages.py b/apps/nspanel-lovelace-ui/luibackend/pages.py index b3fc1730..3bdddf40 100644 --- a/apps/nspanel-lovelace-ui/luibackend/pages.py +++ b/apps/nspanel-lovelace-ui/luibackend/pages.py @@ -382,6 +382,9 @@ class LuiPagesGen(object): value = apis.ha_api.render_template(ovalue) if self._locale == "he_IL" and any("\u0590" <= c <= "\u05EA" for c in name): name = name[::-1] + # use uuid instead for some types and probably expand on this in future + if entityType in ["light"]: + entityId = uuid return f"~{entityTypePanel}~{entityId}~{icon_id}~{color}~{name}~{value}" def generate_entities_page(self, navigation, heading, items, cardType, tempUnit): @@ -719,7 +722,11 @@ class LuiPagesGen(object): return def generate_light_detail_page(self, entity_id, is_open_detail=False): - entity = apis.ha_api.get_entity(entity_id) + if entity_id.startswith('uuid'): + entity_config = self._config._config_entites_table.get(entity_id) + entity = apis.ha_api.get_entity(entity_config.entityId) + else: + entity = apis.ha_api.get_entity(entity_id) switch_val = 1 if entity.state == "on" else 0 icon_color = self.get_entity_color(entity) brightness = "disable" @@ -874,16 +881,26 @@ class LuiPagesGen(object): self._send_mqtt_msg(f"entityUpdateDetail~{entity_id}~{icon_id}~{icon_color}~{modes_out}", force=is_open_detail) def generate_input_select_detail_page(self, entity_id, is_open_detail=False): - entity = apis.ha_api.get_entity(entity_id) + options_list = None + if entity_id.startswith('uuid'): + entity_config = self._config._config_entites_table.get(entity_id) + entity = apis.ha_api.get_entity(entity_config.entityId) + ha_type = entity_config.entityId.split(".")[0] + options_list = entity_config.entity_input_config.get("effectList") + else: + entity = apis.ha_api.get_entity(entity_id) + ha_type = entity_id.split(".")[0] options = [] icon_color = 0 - ha_type = entity_id.split(".")[0] icon_color = self.get_entity_color(entity, ha_type=ha_type) state = entity.state if ha_type in ["input_select", "select"]: options = entity.attributes.get("options", []) elif ha_type == "light": - options = entity.attributes.get("effect_list", [])[:15] + if options_list is not None: + options = options_list + else: + options = entity.attributes.get("effect_list", [])[:15] elif ha_type == "media_player": state = entity.attributes.get("source", "") options = entity.attributes.get("source_list", [])