mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2025-12-20 22:47:01 +01:00
implement timer popup
This commit is contained in:
@@ -8,6 +8,9 @@ import dateutil.parser as dp
|
|||||||
import babel
|
import babel
|
||||||
from libs.icon_mapping import get_icon_char
|
from libs.icon_mapping import get_icon_char
|
||||||
from libs.helper import rgb_dec565, scale
|
from libs.helper import rgb_dec565, scale
|
||||||
|
import time
|
||||||
|
import threading
|
||||||
|
import datetime
|
||||||
|
|
||||||
class HAEntity(panel_cards.Entity):
|
class HAEntity(panel_cards.Entity):
|
||||||
def __init__(self, locale, config, panel):
|
def __init__(self, locale, config, panel):
|
||||||
@@ -591,7 +594,7 @@ def card_factory(locale, settings, panel):
|
|||||||
return "NotImplemented", None
|
return "NotImplemented", None
|
||||||
return card.iid, card
|
return card.iid, card
|
||||||
|
|
||||||
def detail_open(locale, detail_type, ha_entity_id, entity_id):
|
def detail_open(locale, detail_type, ha_entity_id, entity_id, sendTopic=None):
|
||||||
data = libs.home_assistant.get_entity_data(ha_entity_id)
|
data = libs.home_assistant.get_entity_data(ha_entity_id)
|
||||||
if data:
|
if data:
|
||||||
state = data.get("state")
|
state = data.get("state")
|
||||||
@@ -732,7 +735,46 @@ def detail_open(locale, detail_type, ha_entity_id, entity_id):
|
|||||||
case 'popupInSel' | 'input_select' | 'select':
|
case 'popupInSel' | 'input_select' | 'select':
|
||||||
print(f"not implemented {detail_type}")
|
print(f"not implemented {detail_type}")
|
||||||
case 'popupTimer' | 'timer':
|
case 'popupTimer' | 'timer':
|
||||||
print(f"not implemented {detail_type}")
|
icon_color = ha_colors.get_entity_color("timer", state, attributes)
|
||||||
|
if state in ["idle", "paused"]:
|
||||||
|
editable = 1
|
||||||
|
if state == "paused":
|
||||||
|
time_remaining = attributes.get("remaining")
|
||||||
|
else:
|
||||||
|
time_remaining = attributes.get("duration")
|
||||||
|
min_remaining = time_remaining.split(":")[1]
|
||||||
|
sec_remaining = time_remaining.split(":")[2]
|
||||||
|
action1 = ""
|
||||||
|
action2 = "start"
|
||||||
|
action3 = ""
|
||||||
|
label1 = ""
|
||||||
|
label2 = get_translation(locale, "frontend.ui.card.timer.actions.start")
|
||||||
|
label3 = ""
|
||||||
|
else: #active
|
||||||
|
editable = 0
|
||||||
|
|
||||||
|
#update timer in a second
|
||||||
|
def update_time():
|
||||||
|
time.sleep(1)
|
||||||
|
out = detail_open(locale, detail_type, ha_entity_id, entity_id, sendTopic=sendTopic)
|
||||||
|
libs.panel_cmd.entityUpdateDetail(sendTopic, out)
|
||||||
|
tt = threading.Thread(target=update_time, args=())
|
||||||
|
tt.daemon = True
|
||||||
|
tt.start()
|
||||||
|
|
||||||
|
finishes_at = dp.parse(attributes.get("finishes_at"))
|
||||||
|
delta = finishes_at - datetime.datetime.now(datetime.timezone.utc)
|
||||||
|
hours, remainder = divmod(delta.total_seconds(), 3600)
|
||||||
|
minutes, seconds = divmod(remainder, 60)
|
||||||
|
min_remaining = int(minutes)
|
||||||
|
sec_remaining = int(seconds)
|
||||||
|
action1 = "pause"
|
||||||
|
action2 = "cancel"
|
||||||
|
action3 = "finish"
|
||||||
|
label1 = get_translation(locale, "frontend.ui.card.timer.actions.pause")
|
||||||
|
label2 = get_translation(locale, "frontend.ui.card.timer.actions.cancel")
|
||||||
|
label3 = get_translation(locale, "frontend.ui.card.timer.actions.finish")
|
||||||
|
return f'{entity_id}~~{icon_color}~{entity_id}~{min_remaining}~{sec_remaining}~{editable}~{action1}~{action2}~{action3}~{label1}~{label2}~{label3}'
|
||||||
case _:
|
case _:
|
||||||
logging.error("popup type %s not implemented", detail_type)
|
logging.error("popup type %s not implemented", detail_type)
|
||||||
return "NotImplemented", None
|
return "NotImplemented", None
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ class LovelaceUIPanel:
|
|||||||
for e in self.current_card.get_iid_entities():
|
for e in self.current_card.get_iid_entities():
|
||||||
if entity_id == e[1]:
|
if entity_id == e[1]:
|
||||||
entity_id_iid = f'iid.{e[0]}'
|
entity_id_iid = f'iid.{e[0]}'
|
||||||
libs.panel_cmd.entityUpdateDetail(self.sendTopic, detail_open(self.settings["locale"], etype, entity_id, entity_id_iid))
|
libs.panel_cmd.entityUpdateDetail(self.sendTopic, detail_open(self.settings["locale"], etype, entity_id, entity_id_iid, sendTopic=self.sendTopic))
|
||||||
|
|
||||||
involved_entities = ha_control.calculate_dim_values(
|
involved_entities = ha_control.calculate_dim_values(
|
||||||
self.settings.get("sleepTracking"),
|
self.settings.get("sleepTracking"),
|
||||||
@@ -252,4 +252,4 @@ class LovelaceUIPanel:
|
|||||||
iid = entity_id.split(".")[1]
|
iid = entity_id.split(".")[1]
|
||||||
if iid in self.entity_iids:
|
if iid in self.entity_iids:
|
||||||
entity_id = self.entity_iids[iid]
|
entity_id = self.entity_iids[iid]
|
||||||
libs.panel_cmd.entityUpdateDetail(self.sendTopic, detail_open(self.settings["locale"], msg[2], entity_id, msg[3]))
|
libs.panel_cmd.entityUpdateDetail(self.sendTopic, detail_open(self.settings["locale"], msg[2], entity_id, msg[3], sendTopic=self.sendTopic))
|
||||||
|
|||||||
Reference in New Issue
Block a user