mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2025-12-21 06:54:24 +01:00
implement cardqr
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
#!/usr/bin/env bashio
|
||||
# ==============================================================================
|
||||
# Take down the S6 supervision tree when example fails
|
||||
# s6-overlay docs: https://github.com/just-containers/s6-overlay
|
||||
# ==============================================================================
|
||||
|
||||
declare APP_EXIT_CODE=${1}
|
||||
|
||||
if [[ "${APP_EXIT_CODE}" -ne 0 ]] && [[ "${APP_EXIT_CODE}" -ne 256 ]]; then
|
||||
bashio::log.warning "Halt add-on with exit code ${APP_EXIT_CODE}"
|
||||
echo "${APP_EXIT_CODE}" > /run/s6-linux-init-container-results/exitcode
|
||||
exec /run/s6/basedir/bin/halt
|
||||
fi
|
||||
|
||||
bashio::log.info "Service restart after closing"
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/command/with-contenv bashio
|
||||
# shellcheck shell=bash
|
||||
# ==============================================================================
|
||||
# Take down the S6 supervision tree when mqtt manager fails
|
||||
# ==============================================================================
|
||||
declare exit_code
|
||||
readonly exit_code_container=$(</run/s6-linux-init-container-results/exitcode)
|
||||
readonly exit_code_service="${1}"
|
||||
readonly exit_code_signal="${2}"
|
||||
readonly service="AppDaemon"
|
||||
|
||||
bashio::log.info \
|
||||
"Service ${service} exited with code ${exit_code_service}" \
|
||||
"(by signal ${exit_code_signal})"
|
||||
|
||||
if [[ "${exit_code_service}" -eq 256 ]]; then
|
||||
if [[ "${exit_code_container}" -eq 0 ]]; then
|
||||
echo $((128 + $exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
|
||||
fi
|
||||
[[ "${exit_code_signal}" -eq 15 ]] && exec /run/s6/basedir/bin/halt
|
||||
elif [[ "${exit_code_service}" -ne 0 ]]; then
|
||||
if [[ "${exit_code_container}" -eq 0 ]]; then
|
||||
echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode
|
||||
fi
|
||||
exec /run/s6/basedir/bin/halt
|
||||
fi
|
||||
@@ -3,7 +3,7 @@ import ha_icons
|
||||
import ha_colors
|
||||
from libs.localization import get_translation
|
||||
import panel_cards
|
||||
|
||||
import logging
|
||||
|
||||
class HAEntity(panel_cards.Entity):
|
||||
def __init__(self, locale, config, panel):
|
||||
@@ -183,21 +183,23 @@ class HAEntity(panel_cards.Entity):
|
||||
|
||||
return f"~{entity_type_panel}~iid.{self.iid}~{icon_char}~{color}~{name}~{value}"
|
||||
|
||||
|
||||
class EntitiesCard(panel_cards.Card):
|
||||
class HACard(panel_cards.Card):
|
||||
def __init__(self, locale, config, panel):
|
||||
super().__init__(locale, config, panel)
|
||||
# Generate Entity for each Entity in Config
|
||||
self.entities = []
|
||||
if "entities" in config:
|
||||
for e in config.get("entities"):
|
||||
# print(e)
|
||||
iid, entity = entity_factory(locale, e, panel)
|
||||
self.entities.append(entity)
|
||||
|
||||
def get_iid_entities(self):
|
||||
return [(e.iid, e.entity_id) for e in self.entities]
|
||||
|
||||
def render(self):
|
||||
def get_entities(self):
|
||||
return [e.entity_id for e in self.entities]
|
||||
|
||||
def gen_nav(self):
|
||||
leftBtn = "delete~~~~~"
|
||||
if self.iid_prev:
|
||||
leftBtn = panel_cards.Entity(self.locale,
|
||||
@@ -216,11 +218,30 @@ class EntitiesCard(panel_cards.Card):
|
||||
'color': [255, 255, 255],
|
||||
}, self.panel
|
||||
).render()[1:]
|
||||
result = f"{self.title}~{leftBtn}~{rightBtn}"
|
||||
result = f"{leftBtn}~{rightBtn}"
|
||||
return result
|
||||
|
||||
class EntitiesCard(HACard):
|
||||
def __init__(self, locale, config, panel):
|
||||
super().__init__(locale, config, panel)
|
||||
|
||||
def render(self):
|
||||
result = f"{self.title}~{self.gen_nav()}"
|
||||
for e in self.entities:
|
||||
result += e.render()
|
||||
return result
|
||||
|
||||
class QRCard(HACard):
|
||||
def __init__(self, locale, config, panel):
|
||||
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)
|
||||
result = f"{self.title}~{self.gen_nav()}~{self.qrcode}"
|
||||
for e in self.entities:
|
||||
result += e.render()
|
||||
return result
|
||||
|
||||
class Screensaver(panel_cards.Card):
|
||||
def __init__(self, locale, config, panel):
|
||||
@@ -239,8 +260,11 @@ def card_factory(locale, settings, panel):
|
||||
match settings["type"]:
|
||||
case 'cardEntities' | 'cardGrid':
|
||||
card = EntitiesCard(locale, settings, panel)
|
||||
case 'cardQR':
|
||||
card = QRCard(locale, settings, panel)
|
||||
case _:
|
||||
card = panel_cards.Card(locale, settings, panel)
|
||||
logging.error("card type %s not implemented", settings["type"])
|
||||
return "NotImplemented", None
|
||||
return card.iid, card
|
||||
|
||||
|
||||
|
||||
@@ -29,13 +29,15 @@ class LovelaceUIPanel:
|
||||
# generate cards for input settings
|
||||
for c in self.settings.get("cards"):
|
||||
iid, card = card_factory(self.settings["locale"], c, self)
|
||||
self.cards[iid] = card
|
||||
# collect nav keys of cards
|
||||
if card.navigate_key:
|
||||
self.navigate_keys[card.navigate_key] = iid
|
||||
# collect iids of entities
|
||||
for e in card.get_iid_entities():
|
||||
self.entity_iids[e[0]] = e[1]
|
||||
# Check if we acually got a card
|
||||
if card:
|
||||
self.cards[iid] = card
|
||||
# collect nav keys of cards
|
||||
if card.navigate_key:
|
||||
self.navigate_keys[card.navigate_key] = iid
|
||||
# collect iids of entities
|
||||
for e in card.get_iid_entities():
|
||||
self.entity_iids[e[0]] = e[1]
|
||||
|
||||
# setup prev and next iids
|
||||
top_level_cards = list(self.cards.values())
|
||||
@@ -92,9 +94,9 @@ class LovelaceUIPanel:
|
||||
return self.hidden_cards[iid]
|
||||
|
||||
def ha_event_callback(self, entity_id):
|
||||
logging.debug(f"{entity_id} updated/state changed")
|
||||
# TODO: Check if entity is on current card
|
||||
libs.panel_cmd.entityUpd(self.sendTopic, self.current_card.render())
|
||||
#logging.debug(f"{entity_id} updated/state changed")
|
||||
if entity_id in self.current_card.get_entities():
|
||||
libs.panel_cmd.entityUpd(self.sendTopic, self.current_card.render())
|
||||
|
||||
def customrecv_event_callback(self, msg):
|
||||
logging.debug("Recv Message from NsPanel: %s", msg)
|
||||
|
||||
Reference in New Issue
Block a user