mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2025-12-22 15:34:26 +01:00
add lookup table for entities
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import uuid
|
||||
|
||||
class Entity(object):
|
||||
def __init__(self, entity_input_config):
|
||||
self.uuid = f"uuid.{uuid.uuid4().hex}"
|
||||
if type(entity_input_config) is not dict:
|
||||
#self._ha_api.log("Config error, not a dict check your entity configs")
|
||||
self.entityId = "error"
|
||||
@@ -30,7 +33,7 @@ class Card(object):
|
||||
self.id = f"{self.cardType}_{self.key}".replace(".","_").replace("~","_").replace(" ","_")
|
||||
#self._ha_api.log(f"Created Card {self.cardType} with pos {pos} and id {self.id}")
|
||||
|
||||
def get_entity_list(self):
|
||||
def get_entity_names(self):
|
||||
entityIds = []
|
||||
if self.entity is not None:
|
||||
entityIds.append(self.entity.entityId)
|
||||
@@ -50,6 +53,16 @@ class Card(object):
|
||||
entityIds.append(val.get("entity"))
|
||||
return entityIds
|
||||
|
||||
def get_entity_list(self):
|
||||
entitys = []
|
||||
if self.entity is not None:
|
||||
entitys.append(self.entity)
|
||||
else:
|
||||
for e in self.entities:
|
||||
entitys.append(e)
|
||||
return entitys
|
||||
|
||||
|
||||
class LuiBackendConfig(object):
|
||||
|
||||
def dict_recursive_update(self, source: dict, target: dict) -> dict:
|
||||
@@ -138,10 +151,13 @@ class LuiBackendConfig(object):
|
||||
# parse screensaver
|
||||
self._config_screensaver = Card(self.get("screensaver"))
|
||||
|
||||
# parsed hidden pages that can be accessed through navigate
|
||||
# parse hidden pages that can be accessed through navigate
|
||||
for card in self.get("hiddenCards"):
|
||||
self._config_hidden_cards.append(Card(card))
|
||||
|
||||
# all entites sorted by generated key, to be able to use short identifiers
|
||||
self._config_entites_table = {x.uuid: x for x in self.get_all_entitys()}
|
||||
|
||||
def get(self, name):
|
||||
path = name.split(".")
|
||||
value = self._config
|
||||
@@ -158,12 +174,20 @@ class LuiBackendConfig(object):
|
||||
return value
|
||||
|
||||
def get_all_entity_names(self):
|
||||
entities = []
|
||||
for card in self._config_cards:
|
||||
entities.extend(card.get_entity_names())
|
||||
for card in self._config_hidden_cards:
|
||||
entities.extend(card.get_entity_names())
|
||||
entities.extend(self._config_screensaver.get_entity_names())
|
||||
return entities
|
||||
|
||||
def get_all_entitys(self):
|
||||
entities = []
|
||||
for card in self._config_cards:
|
||||
entities.extend(card.get_entity_list())
|
||||
for card in self._config_hidden_cards:
|
||||
entities.extend(card.get_entity_list())
|
||||
entities.extend(self._config_screensaver.get_entity_list())
|
||||
return entities
|
||||
|
||||
def getCard(self, pos):
|
||||
|
||||
@@ -157,8 +157,8 @@ class LuiController(object):
|
||||
|
||||
def state_change_callback(self, entity, attribute, old, new, kwargs):
|
||||
self._ha_api.log(f"Got callback for: {entity}", level="DEBUG")
|
||||
self._ha_api.log(f"Current page has the following items: {self._current_card.get_entity_list()}", level="DEBUG")
|
||||
if entity in self._current_card.get_entity_list():
|
||||
self._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():
|
||||
self._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
|
||||
@@ -266,6 +266,10 @@ 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 for navigation to nested pages
|
||||
dstCard = self._config.searchCard(entity_id)
|
||||
@@ -291,6 +295,7 @@ class LuiController(object):
|
||||
elif entity_id.startswith('input_select'):
|
||||
self._ha_api.get_entity(entity_id).call_service("select_next")
|
||||
|
||||
|
||||
# for media page
|
||||
if button_type == "media-next":
|
||||
self._ha_api.get_entity(entity_id).call_service("media_next_track")
|
||||
|
||||
@@ -162,6 +162,7 @@ class LuiPagesGen(object):
|
||||
icon = item.iconOverride
|
||||
colorOverride = item.colorOverride
|
||||
name = item.nameOverride
|
||||
uuid = item.uuid
|
||||
# type of the item is the string before the "." in the entityId
|
||||
entityType = entityId.split(".")[0]
|
||||
|
||||
@@ -194,6 +195,10 @@ class LuiPagesGen(object):
|
||||
name = name if name is not None else "conf name missing"
|
||||
icon_res = get_icon_id(icon) if icon is not None else get_icon_id("alert-circle-outline")
|
||||
return f"~text~{entityId}~{icon_res}~17299~{name}~{value}"
|
||||
if entityType == "service":
|
||||
icon_id = get_icon_id_ha("script", overwrite=icon)
|
||||
text = get_translation(self._locale, "frontend.ui.card.script.run")
|
||||
return f"~button~{uuid}~{icon_id}~17299~{name}~{text}"
|
||||
if not self._ha_api.entity_exists(entityId):
|
||||
return f"~text~{entityId}~{get_icon_id('alert-circle-outline')}~17299~Not found check~ apps.yaml"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user