This commit is contained in:
joBr99
2023-11-30 17:14:41 +01:00
parent 04ffd6257e
commit ba637cf11e
4 changed files with 104 additions and 59 deletions

View File

@@ -1,6 +1,6 @@
# https://developers.home-assistant.io/docs/add-ons/configuration#add-on-config
name: NSPanel Lovelace UI Addon
version: "4.7.55"
version: "4.7.56"
slug: nspanel-lovelace-ui
description: NSPanel Lovelace UI Addon
services:

View File

@@ -625,7 +625,7 @@ def card_factory(locale, settings, panel):
return "NotImplemented", None
return card.iid, card
def detail_open(locale, detail_type, ha_entity_id, entity_id, sendTopic=None):
def detail_open(locale, detail_type, ha_entity_id, entity_id, sendTopic=None, options_list=None):
data = libs.home_assistant.get_entity_data(ha_entity_id)
if data:
state = data.get("state")
@@ -763,8 +763,25 @@ def detail_open(locale, detail_type, ha_entity_id, entity_id, sendTopic=None):
return f'{entity_id}~~{icon_color}~{switch_val}~{speed}~{speedMax}~{speed_translation}~{preset_mode}~{preset_modes}'
case 'popupThermo' | 'climate':
print(f"not implemented {detail_type}")
case 'popupInSel' | 'input_select' | 'select':
print(f"not implemented {detail_type}")
case 'popupInSel' | 'input_select' | 'select' | 'media_player':
options = []
icon_color = 0
icon_color = ha_colors.get_entity_color(detail_type, state, attributes)
state = state
if detail_type in ["input_select", "select"]:
options = attributes.get("options", [])
elif detail_type == "light":
if options_list is not None:
options = options_list
else:
options = attributes.get("effect_list", [])[:15]
elif detail_type == "media_player":
state = attributes.get("source", "")
options = attributes.get("source_list", [])
options = "?".join(options)
return f"{entity_id}~~{icon_color}~{detail_type}~{state}~{options}~"
case 'popupTimer' | 'timer':
icon_color = ha_colors.get_entity_color("timer", state, attributes)
if state in ["idle", "paused"]:

View File

@@ -1,46 +1,49 @@
import logging
def init(mqtt_client_from_manager):
global mqtt_client
mqtt_client = mqtt_client_from_manager
def custom_send(topic, msg):
global mqtt_client
mqtt_client.publish(topic, msg)
logging.debug("Sent Message to NsPanel (%s): %s", topic, msg)
def page_type(topic, target_page):
if target_page == "cardUnlock":
target_page = "cardAlarm"
custom_send(topic, f"pageType~{target_page}")
def send_time(topic, time, addTimeText=""):
custom_send(topic, f"time~{time}~{addTimeText}")
def send_date(topic, date):
custom_send(topic, f"date~{date}")
def entityUpd(topic, data):
custom_send(topic, f"entityUpd~{data}")
def weatherUpdate(topic, data):
custom_send(topic, f"weatherUpdate~{data}")
def timeout(topic, timeout):
custom_send(topic, f"timeout~{timeout}")
def dimmode(topic, dimValue, dimValueNormal, backgroundColor, fontColor, featExperimentalSliders):
if dimValue==dimValueNormal:
dimValue=dimValue-1
custom_send(topic, f"dimmode~{dimValue}~{dimValueNormal}~{backgroundColor}~{fontColor}~{featExperimentalSliders}")
def entityUpdateDetail(topic, data):
custom_send(topic, f"entityUpdateDetail~{data}")
def statusUpdate(topic, data):
import logging
def init(mqtt_client_from_manager):
global mqtt_client
mqtt_client = mqtt_client_from_manager
def custom_send(topic, msg):
global mqtt_client
mqtt_client.publish(topic, msg)
logging.debug("Sent Message to NsPanel (%s): %s", topic, msg)
def page_type(topic, target_page):
if target_page == "cardUnlock":
target_page = "cardAlarm"
custom_send(topic, f"pageType~{target_page}")
def send_time(topic, time, addTimeText=""):
custom_send(topic, f"time~{time}~{addTimeText}")
def send_date(topic, date):
custom_send(topic, f"date~{date}")
def entityUpd(topic, data):
custom_send(topic, f"entityUpd~{data}")
def weatherUpdate(topic, data):
custom_send(topic, f"weatherUpdate~{data}")
def timeout(topic, timeout):
custom_send(topic, f"timeout~{timeout}")
def dimmode(topic, dimValue, dimValueNormal, backgroundColor, fontColor, featExperimentalSliders):
if dimValue==dimValueNormal:
dimValue=dimValue-1
custom_send(topic, f"dimmode~{dimValue}~{dimValueNormal}~{backgroundColor}~{fontColor}~{featExperimentalSliders}")
def entityUpdateDetail(topic, data):
custom_send(topic, f"entityUpdateDetail~{data}")
def entityUpdateDetail2(topic, data):
custom_send(topic, f"entityUpdateDetail2~{data}")
def statusUpdate(topic, data):
custom_send(topic, f"statusUpdate~{data}")

View File

@@ -132,10 +132,17 @@ class LovelaceUIPanel:
if etype in ['light', 'timer', 'cover', 'input_select', 'select', 'fan']:
# figure out iid of entity
entity_id_iid = ""
for e in self.current_card.get_iid_entities():
if entity_id == e[1]:
entity_id_iid = f'iid.{e[0]}'
libs.panel_cmd.entityUpdateDetail(self.sendTopic, detail_open(self.settings["locale"], etype, entity_id, entity_id_iid, sendTopic=self.sendTopic))
for e in self.current_card.entities:
if entity_id == e.entity_id:
entity_id_iid = e.iid
effectList = None
if etype=="light":
effectList = e.config.get("effectList")
if etype in ['input_select', 'media_player']:
libs.panel_cmd.entityUpdateDetail2(self.sendTopic, detail_open(self.settings["locale"], etype, entity_id, entity_id_iid, sendTopic=self.sendTopic, options_list=effectList))
else:
libs.panel_cmd.entityUpdateDetail(self.sendTopic, detail_open(self.settings["locale"], etype, entity_id, entity_id_iid, sendTopic=self.sendTopic, options_list=effectList))
involved_entities = ha_control.calculate_dim_values(
self.settings.get("sleepTracking"),
@@ -150,6 +157,8 @@ class LovelaceUIPanel:
def render_current_page(self, switchPages=False, requested=False):
if not self.current_card:
return
if switchPages:
libs.panel_cmd.page_type(self.sendTopic, self.current_card.type)
if requested:
@@ -180,6 +189,13 @@ class LovelaceUIPanel:
featExperimentalSliders = self.settings.get("featExperimentalSliders", 0)
libs.panel_cmd.dimmode(self.sendTopic, dimValue, dimValueNormal, backgroundColor, fontColor, featExperimentalSliders)
def get_default_card(self, card_iid):
defaultCard = self.settings.get("defaultCard")
if defaultCard:
card = self.searchCard(card_iid)
if card:
return card
return list(self.cards.values())[0]
def customrecv_event_callback(self, msg):
logging.debug("Recv Message from NsPanel (%s): %s", self.name, msg)
@@ -217,8 +233,7 @@ class LovelaceUIPanel:
# in case privious_cards is empty add a default card
if len(self.privious_cards) == 0:
self.privious_cards.append(
list(self.cards.values())[0]) # TODO: Impelement default card config
self.privious_cards.append(self.get_default_card)
self.current_card = self.privious_cards.pop()
self.render_current_page(switchPages=True)
return
@@ -236,8 +251,9 @@ class LovelaceUIPanel:
case 'navigate':
card_iid = entity_id.split(".")[1]
if card_iid == "UP":
if len(self.privious_cards) == 0:
self.privious_cards.append(self.get_default_card)
self.current_card = self.privious_cards.pop()
# TODO Handle privious_cards empty with default card
self.render_current_page(switchPages=True)
else:
self.privious_cards.append(self.current_card)
@@ -260,6 +276,15 @@ class LovelaceUIPanel:
# 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]
libs.panel_cmd.entityUpdateDetail(self.sendTopic, detail_open(self.settings["locale"], msg[2], entity_id, msg[3], sendTopic=self.sendTopic))
for e in self.current_card.entities:
if e.iid == iid:
entity_id = e.entity_id
effectList = None
if entity_id.startswith("light"):
effectList = e.config.get("effectList")
if entity_id.split(".")[0] in ['input_select', 'media_player']:
libs.panel_cmd.entityUpdateDetail2(self.sendTopic, detail_open(self.settings["locale"], msg[2], entity_id, msg[3], sendTopic=self.sendTopic, options_list=effectList))
else:
libs.panel_cmd.entityUpdateDetail(self.sendTopic, detail_open(self.settings["locale"], msg[2], entity_id, msg[3], sendTopic=self.sendTopic))