This commit is contained in:
joBr99
2023-02-26 22:49:55 +01:00
parent 2a98edd665
commit 276025b6c4
2 changed files with 25 additions and 10 deletions

View File

@@ -53,24 +53,29 @@ class Card(object):
self.entities.append(Entity(e))
self.id = f"{self.cardType}_{self.key}".replace(".","_").replace("~","_").replace(" ","_")
def get_entity_names(self):
entityIds = []
def get_entity_names(self, uuid=False):
entityIds = {}
if self.entity is not None:
entityIds.append(self.entity.entityId)
entityIds[self.entity.uuid] = self.entity.entityId
if self.entity.status is not None:
entityIds.append(self.entity.status)
entityIds[self.entity.uuid] = self.entity.status
for e in self.entities:
entityIds.append(e.entityId)
entityIds[e.uuid] = e.entityId
if e.status is not None:
entityIds.append(e.status)
entityIds[e.uuid] = 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.append(val.get("entity"))
return entityIds
#entityIds.append(val.get("entity"))
entityIds["nouuid."] = val.get("entity")
if uuid:
return entityIds
else:
return entityIds.values()
def get_entity_list(self):
entitys = []

View File

@@ -144,6 +144,8 @@ 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()
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}")
for item in items:
if apis.ha_api.entity_exists(item):
@@ -152,13 +154,21 @@ class LuiController(object):
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")
if entity in self._current_card.get_entity_names():
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:
res_uuid = uuid
apis.ha_api.log(f"Callback Entity is on current page: {entity}", level="DEBUG")
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"]:
if entity.startswith("light"):
self._pages_gen.generate_light_detail_page(entity)
self._pages_gen.generate_light_detail_page(res_uuid)
if entity.startswith("cover"):
self._pages_gen.generate_shutter_detail_page(entity)
if entity.startswith("fan"):