implement cooldown config option for cards

This commit is contained in:
joBr99
2023-02-01 22:44:18 +01:00
parent 0ca1982ebc
commit 5050e430ec
2 changed files with 10 additions and 2 deletions

View File

@@ -40,6 +40,8 @@ class Card(object):
self.key = card_input_config.get("key", "unknown")
self.nav1Override = card_input_config.get("navItem1")
self.nav2Override = card_input_config.get("navItem2")
self.last_update = 0
self.cooldown = card_input_config.get("cooldown", 0)
# for single entity card like climate or media
self.entity = None
if card_input_config.get("entity") is not None:
@@ -49,8 +51,7 @@ class Card(object):
for e in card_input_config.get("entities", []):
self.entities.append(Entity(e))
self.id = f"{self.cardType}_{self.key}".replace(".","_").replace("~","_").replace(" ","_")
#self._ha_api.log(f"Created Card {self.cardType} and id {self.id}")
def get_entity_names(self):
entityIds = []
if self.entity is not None:

View File

@@ -648,6 +648,13 @@ class LuiPagesGen(object):
def render_card(self, card, send_page_type=True):
# page type is false, so this request is from a callback
if not send_page_type and card.cooldown != 0:
if (time.time()-card.last_update) < card.cooldown:
return
card.last_update = time.time()
leftBtn = "delete~~~~~"
if card.uuid_prev is not None:
leftBtn = self.generate_entities_item(Entity(