implement templtates for brightness

This commit is contained in:
joBr99
2023-12-13 16:50:28 +01:00
parent 2fb1855842
commit 4b73e20b9b
4 changed files with 19 additions and 33 deletions

View File

@@ -52,6 +52,8 @@ class HAEntity(panel_cards.Entity):
self.state = data.get("state")
self.attributes = data.get("attributes", [])
else:
self.state = "not found"
self.attributes = []
return "~text~iid.404~X~6666~not found~"
# HA Entities
@@ -304,8 +306,6 @@ class QRCard(HACard):
super().__init__(locale, config, panel)
self.qrcode = config.get("qrCode", "https://www.youtube.com/watch?v=dQw4w9WgXcQ")
def render(self):
# TODO: Render QRCode as HomeAssistant Template
#qrcode = apis.ha_api.render_template(qrcode)
if self.qrcode.startswith("ha:"):
self.qrcode = libs.home_assistant.get_template(self.qrcode)[3:]
result = f"{self.title}~{self.gen_nav()}~{self.qrcode}"
@@ -475,6 +475,8 @@ class AlarmCard(HACard):
main_entity = self.entities[0]
main_entity.render()
print(main_entity.state)
icon = get_icon_char("shield-off")
color = rgb_dec565([255,255,255])
supported_modes = []

View File

@@ -17,6 +17,10 @@ def calculate_dim_values(sleepTracking, sleepTrackingZones, sleepBrightness, scr
if sleepBrightness:
if isinstance(sleepBrightness, int):
dimmode = sleepBrightness
elif isinstance(sleepBrightness, list):
logging.error("list style config for sleepBrightness no longer supported")
elif sleepBrightness.startswith("ha:"):
dimmode = int(float(libs.home_assistant.get_template(sleepBrightness)[3:]))
elif libs.home_assistant.is_existent(sleepBrightness):
involved_entities.append(sleepBrightness)
dimmode = int(float(libs.home_assistant.get_entity_data(sleepBrightness).get('state', 10)))
@@ -24,6 +28,10 @@ def calculate_dim_values(sleepTracking, sleepTrackingZones, sleepBrightness, scr
if screenBrightness:
if isinstance(screenBrightness, int):
dimValueNormal = screenBrightness
elif isinstance(screenBrightness, list):
logging.error("list style config for screenBrightness no longer supported")
elif screenBrightness.startswith("ha:"):
dimValueNormal = int(float(libs.home_assistant.get_template(screenBrightness)[3:]))
elif libs.home_assistant.is_existent(screenBrightness):
involved_entities.append(screenBrightness)
dimValueNormal = int(float(libs.home_assistant.get_entity_data(screenBrightness).get('state', 100)))
@@ -217,30 +225,6 @@ def handle_buttons(entity_id, btype, value, entity_config=None):
case _:
logging.error("Not implemented: %s", btype)
# # for cardUnlock
# if button_type == "cardUnlock-unlock":
# curCard = self._config.get_card_by_uuid(
# entity_id.replace('navigate.', ''))
# if curCard is not None:
# if int(curCard.raw_config.get("pin")) == int(value):
# dstCard = self._config.search_card(
# curCard.raw_config.get("destination"))
# if dstCard is not None:
# if dstCard.hidden:
# self._previous_cards.append(self._current_card)
# self._current_card = dstCard
# self._pages_gen.render_card(self._current_card)
# if button_type == "opnSensorNotify":
# msg = ""
# entity = apis.ha_api.get_entity(entity_id)
# if "open_sensors" in entity.attributes and entity.attributes.open_sensors is not None:
# for e in entity.attributes.open_sensors:
# msg += f"- {apis.ha_api.get_entity(e).attributes.friendly_name}\r\n"
# self._pages_gen.send_message_page(
# "opnSensorNotifyRes", "", msg, "", "")
def call_ha_service(entity_id, service, service_data = {}):
etype = entity_id.split(".")[0]
libs.home_assistant.call_service(

View File

@@ -41,3 +41,7 @@ def entityUpdateDetail2(msg_out_queue, topic, data):
def statusUpdate(msg_out_queue, topic, data):
custom_send(msg_out_queue, topic, f"statusUpdate~{data}")
def send_message_page(msg_out_queue, topic, ident, heading, msg, b1, b2):
page_type(msg_out_queue, topic, "popupNotify")
custom_send(msg_out_queue, topic, f"entityUpdateDetail~{ident}~{heading}~65535~{b1}~65535~{b2}~65535~{msg}~65535~0")

View File

@@ -7,7 +7,7 @@ from scheduler import Scheduler
import scheduler.trigger as trigger
import time
import babel.dates
from ha_cards import Screensaver, EntitiesCard, card_factory, detail_open
from ha_cards import Screensaver, card_factory, detail_open
import ha_control
class LovelaceUIPanel:
@@ -76,6 +76,8 @@ class LovelaceUIPanel:
ha_control.wait_for_ha_cache()
#request templates on cards
libs.home_assistant.cache_template(self.settings.get("sleepBrightness"))
libs.home_assistant.cache_template(self.settings.get("screenBrightness"))
for c in self.cards.values():
if hasattr(c, "qrcode"):
if c.qrcode.startswith("ha:"):
@@ -242,12 +244,6 @@ class LovelaceUIPanel:
self.render_current_page(switchPages=True)
return
# replace iid with real entity id
#if entity_id.startswith("iid."):
# iid = entity_id.split(".")[1]
# if iid in self.entity_iids:
# entity_id = self.entity_iids[iid]
# replace iid with real entity id
if entity_id.startswith("iid."):
iid = entity_id.split(".")[1]