From 6338af247fea7443db527c417df1225dd9d768aa Mon Sep 17 00:00:00 2001 From: joBr99 <29555657+joBr99@users.noreply.github.com> Date: Wed, 8 Mar 2023 18:52:53 +0100 Subject: [PATCH] fixes #805 --- apps/nspanel-lovelace-ui/luibackend/config.py | 23 ++++++++++++------- .../luibackend/controller.py | 15 ++++++------ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/apps/nspanel-lovelace-ui/luibackend/config.py b/apps/nspanel-lovelace-ui/luibackend/config.py index 010d1fff..a37c6862 100644 --- a/apps/nspanel-lovelace-ui/luibackend/config.py +++ b/apps/nspanel-lovelace-ui/luibackend/config.py @@ -11,7 +11,6 @@ class Entity(object): def __init__(self, entity_input_config): self.uuid = f"uuid.{uuid()}" if type(entity_input_config) is not dict: - #self._ha_api.log("Config error, not a dict check your entity configs") self.entityId = "error" else: self.entityId = entity_input_config.get("entity", "unknown") @@ -59,26 +58,34 @@ class Card(object): def get_entity_names(self, uuid=False): entityIds = {} + #apis.ha_api.log(f"test123 {self.entity.entityId}") if self.entity is not None: - entityIds[self.entity.uuid] = self.entity.entityId + #entityIds[self.entity.uuid] = self.entity.entityId + entityIds.setdefault(self.entity.uuid, []).append(self.entity.entityId) if self.entity.status is not None: - entityIds[self.entity.uuid] = self.entity.status + #entityIds[self.entity.uuid] = self.entity.status + entityIds.setdefault(self.entity.uuid, []).append(self.entity.status) for e in self.entities: - entityIds[e.uuid] = e.entityId + #entityIds[e.uuid] = e.entityId + entityIds.setdefault(e.uuid, []).append(e.entityId) if e.status is not None: - entityIds[e.uuid] = e.status + #entityIds[e.uuid] = e.status + entityIds.setdefault(e.uuid, []).append(e.status) # additional keys to check add_ent_keys = ['statusIcon1', 'statusIcon2', 'alarmControl'] for ent_key in add_ent_keys: val = self.raw_config.get(ent_key) if val is not None: - entityIds[f"{ent_key}."] = val.get("entity") - + #entityIds[f"{ent_key}."] = val.get("entity") + ntityIds.setdefault(self.entity.uuid, []).append(val.get("entity")) if uuid: return entityIds else: - return entityIds.values() + out = [] + for l in entityIds.values(): + out.extend(l) + return out def get_entity_list(self): entitys = [] diff --git a/apps/nspanel-lovelace-ui/luibackend/controller.py b/apps/nspanel-lovelace-ui/luibackend/controller.py index 6981fda9..50d595f1 100644 --- a/apps/nspanel-lovelace-ui/luibackend/controller.py +++ b/apps/nspanel-lovelace-ui/luibackend/controller.py @@ -144,6 +144,7 @@ class LuiController(object): apis.ha_api.listen_state(self.update_screensaver_brightness_state_callback, entity_id=screen_brightness_config) items = self._config.get_all_entity_names() + apis.ha_api.log(f"gtest123: {items}") prefixes = ("navigate.") items = [x for x in items if not x.startswith(prefixes)] apis.ha_api.log(f"Registering callbacks for the following items: {items}") @@ -152,18 +153,18 @@ class LuiController(object): apis.ha_api.listen_state(self.state_change_callback, entity_id=item, attribute="all") def state_change_callback(self, entity, attribute, old, new, kwargs): - apis.ha_api.log(f"Got callback for: {entity}", level="DEBUG") - apis.ha_api.log(f"Current page has the following items: {self._current_card.get_entity_names()}", level="DEBUG") + #apis.ha_api.log(f"Got callback for: {entity}") + #apis.ha_api.log(f"Current page has the following items: {self._current_card.get_entity_names(uuid=True)}") entities_on_card = self._current_card.get_entity_names(uuid=True) - # lookup uuid for enity on current card res_uuid = "uuid.notfound" - if entity in entities_on_card.values(): - for uuid, name in entities_on_card.items(): - if entity == name: + if entity in sum(entities_on_card.values(), []): + for uuid, names in entities_on_card.items(): + apis.ha_api.log(f"test124 items: {entities_on_card.items()} names: {names}") + if entity in names: res_uuid = uuid - apis.ha_api.log(f"Callback Entity is on current page: {entity}", level="DEBUG") + #apis.ha_api.log(f"Callback Entity is on current page: {entity}") self._pages_gen.render_card(self._current_card, send_page_type=False) # send detail page update, just in case if self._current_card.cardType in ["cardGrid", "cardEntities", "cardMedia"]: