basic backend implementation for timer popup

This commit is contained in:
joBr99
2022-12-20 20:30:57 +01:00
parent 7c82dd9db9
commit 67c38d998c
2 changed files with 53 additions and 2 deletions

View File

@@ -173,6 +173,8 @@ class LuiController(object):
self._pages_gen.generate_input_select_detail_page(entity) self._pages_gen.generate_input_select_detail_page(entity)
if entity.startswith("media_player"): if entity.startswith("media_player"):
self._pages_gen.generate_input_select_detail_page(entity) self._pages_gen.generate_input_select_detail_page(entity)
if entity.startswith("timer"):
self._pages_gen.generate_timer_detail_page(entity)
if self._current_card.cardType == "cardThermo": if self._current_card.cardType == "cardThermo":
if entity.startswith("climate"): if entity.startswith("climate"):
self._pages_gen.generate_thermo_detail_page(entity) self._pages_gen.generate_thermo_detail_page(entity)
@@ -189,7 +191,8 @@ class LuiController(object):
self._pages_gen.generate_thermo_detail_page(entity_id) self._pages_gen.generate_thermo_detail_page(entity_id)
if detail_type == "popupInSel": if detail_type == "popupInSel":
self._pages_gen.generate_input_select_detail_page(entity_id) self._pages_gen.generate_input_select_detail_page(entity_id)
if detail_type == "popupTimer":
self._pages_gen.generate_timer_detail_page(entity_id)
def button_press(self, entity_id, button_type, value): def button_press(self, entity_id, button_type, value):
apis.ha_api.log(f"Button Press Event; entity_id: {entity_id}; button_type: {button_type}; value: {value} ") apis.ha_api.log(f"Button Press Event; entity_id: {entity_id}; button_type: {button_type}; value: {value} ")
# internal buttons # internal buttons
@@ -414,4 +417,17 @@ class LuiController(object):
if button_type == "mode-media_player": if button_type == "mode-media_player":
entity = apis.ha_api.get_entity(entity_id) entity = apis.ha_api.get_entity(entity_id)
option = entity.attributes.source_list[int(value)] option = entity.attributes.source_list[int(value)]
entity.call_service("select_source", source=option) entity.call_service("select_source", source=option)
# timer detail page
if button_type == "timer-start":
if value is not None:
apis.ha_api.get_entity(entity_id).call_service("start", duration=value)
else:
apis.ha_api.get_entity(entity_id).call_service("start")
if button_type == "timer-cancel":
apis.ha_api.get_entity(entity_id).call_service("cancel")
if button_type == "timer-pause":
apis.ha_api.get_entity(entity_id).call_service("pause")
if button_type == "timer-finish":
apis.ha_api.get_entity(entity_id).call_service("finish")

View File

@@ -846,6 +846,41 @@ class LuiPagesGen(object):
options = "?".join(options) options = "?".join(options)
self._send_mqtt_msg(f"entityUpdateDetail2~{entity_id}~~{icon_color}~{ha_type}~{state}~{options}~") self._send_mqtt_msg(f"entityUpdateDetail2~{entity_id}~~{icon_color}~{ha_type}~{state}~{options}~")
def generate_timer_detail_page(self, entity_id):
if isinstance(entity_id, dict):
entity_id = entity_id["entity_id"]
entity = apis.ha_api.get_entity(entity_id)
icon_color = 0
if entity.state in ["idle", "paused"]:
editable = 1
if entity.state == "paused":
time_remaining = entity.attributes.get("remaining")
else:
time_remaining = entity.attributes.get("duration")
min_remaining = time_remaining.split(":")[1]
sec_remaining = time_remaining.split(":")[2]
action1 = ""
action2 = "start"
action3 = ""
label1 = ""
label2 = "start"
label3 = ""
else: #active
editable = 0
apis.ha_api.run_in(self.generate_timer_detail_page, 1, entity_id=entity_id)
finishes_at = dp.parse(entity.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 = "pause"
label2 = "cancel"
label3 = "finish"
self._send_mqtt_msg(f"entityUpdateDetail~{entity_id}~~{icon_color}~{entity_id}~{min_remaining}~{sec_remaining}~{editable}~{action1}~{action2}~{action3}~{label1}~{label2}~{label3}")
def send_message_page(self, ident, heading, msg, b1, b2): def send_message_page(self, ident, heading, msg, b1, b2):
self._send_mqtt_msg(f"pageType~popupNotify") self._send_mqtt_msg(f"pageType~popupNotify")