This commit is contained in:
Johannes
2022-03-25 22:23:27 +01:00
parent 70557ab748
commit af494ada10
3 changed files with 21 additions and 10 deletions

View File

@@ -1,6 +1,5 @@
import logging
LOGGER = logging.getLogger(__name__)
class PageNode(object):
@@ -59,11 +58,12 @@ class PageNode(object):
items.append(i.data)
return items
def get_all_items_recursive(self):
def get_all_item_names(self, recursive=True):
items = []
for i in self.childs:
if len(i.childs) > 0:
items.extend(i.get_all_items_recursive())
if recursive:
items.extend(i.get_all_item_names())
else:
if type(i.data) is dict:
items.append(i.data.get("item", next(iter(i.data))))

View File

@@ -58,6 +58,13 @@ class LuiController(object):
self._pages_gen.update_time("")
self._pages_gen.update_date("")
# set screensaver timeout
timeout = self._config.get("timeoutScreensaver")
self._send_mqtt_msg(f"timeout,{timeout}")
# set current screensaver brightness
self.update_screensaver_brightness(kwargs={"value": self.current_screensaver_brightness})
# send panel to screensaver
self._pages_gen.page_type("screensaver")
self.weather_update("")
@@ -72,7 +79,7 @@ class LuiController(object):
self._pages_gen.update_screensaver_weather(kwargs={"weather": we_name, "unit": unit})
def register_callbacks(self):
items = self._config.get_root_page().get_all_items_recursive()
items = self._config.get_root_page().get_all_item_names()
LOGGER.info(f"Registering callbacks for the following items: {items}")
for item in items:
if self._ha_api.entity_exists(item):
@@ -80,13 +87,15 @@ class LuiController(object):
def state_change_callback(self, entity, attribute, old, new, kwargs):
LOGGER.info(f"Got callback for: {entity}")
if entity in self._current_page.get_items():
LOGGER.info(f"Current page has the following items: {self._current_page.get_items()}")
if entity in self._current_page.get_all_item_names(recursive=False):
LOGGER.info(f"Callback Entity is on current page: {entity}")
self._pages_gen.render_page(self._current_page)
# send detail page update, just in case
if self._current_page.data.get("type", "unknown") in ["cardGrid", "cardEntities"]:
if entity.startswith("light"):
self._pages_gen.generate_light_detail_page(entity)
if entity.startswith("switch"):
if entity.startswith("cover"):
self._pages_gen.generate_shutter_detail_page(entity)
@@ -175,4 +184,4 @@ class LuiController(object):
# for climate page
if button_type == "tempUpd":
temp = int(value)/10
self._ha_api.get_entity(entity_id).call_service("set_temperature", temperature=temp)
self._ha_api.get_entity(entity_id).call_service("set_temperature", temperature=temp)

View File

@@ -132,10 +132,11 @@ class LuiPagesGen(object):
return f",text,{item},{icon_id},{icon_color},{name},{value}"
if item_type in ["button", "input_button"]:
icon_id = get_icon_id_ha("button", overwrite=icon)
return f",button,{item},{icon_id},17299,{name},PRESS"
text = get_translation(self._locale,"PRESS")
return f",button,{item},{icon_id},17299,{name},{text}"
if item_type == "scene":
icon_id = get_icon_id_ha("scene", overwrite=icon)
text = get_translation(self._locale,"PRESS")
text = get_translation(self._locale,"ACTIVATE")
return f",button,{item},{icon_id},17299,{name},{text}"
@@ -158,6 +159,7 @@ class LuiPagesGen(object):
current_temp = int(entity.attributes.get("current_temperature", 0)*10)
dest_temp = int(entity.attributes.get("temperature", 0)*10)
status = entity.attributes.get("hvac_action", "")
status = get_translation(self._locale,status)
min_temp = int(entity.attributes.get("min_temp", 0)*10)
max_temp = int(entity.attributes.get("max_temp", 0)*10)
step_temp = int(entity.attributes.get("target_temp_step", 0.5)*10)
@@ -274,4 +276,4 @@ class LuiPagesGen(object):
def send_message_page(self, id, heading, msg, b1, b2):
self._send_mqtt_msg(f"pageType,popupNotify")
self._send_mqtt_msg(f"entityUpdateDetail,|{id}|{heading}|65535|{b1}|65535|{b2}|65535|{msg}|65535|0")
self._send_mqtt_msg(f"entityUpdateDetail,|{id}|{heading}|65535|{b1}|65535|{b2}|65535|{msg}|65535|0")