Skip to content

Commit

Permalink
Fix editor
Browse files Browse the repository at this point in the history
  • Loading branch information
wrfz committed Nov 12, 2024
1 parent a95a183 commit 2e0cfb0
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 208 deletions.
50 changes: 27 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,30 @@ Erstelle als nächstes ein hpsu-dashboard-card als ein Fullscreen - **Panel** mi
cards:
- type: custom:hpsu-dashboard-card
entities:
t_aussen_1: sensor.rotex_aussentemperatur
t_aussen_2: sensor.rotex_t_aussen
expansions_ventil: sensor.rotex_expansionsventil
kondensat: sensor.rotex_temperatur_fl_ssigkeitsleitung
umwaelzpumpe: sensor.rotex_umwaelzpumpe
umwaelzpumpe_an_aus: binary_sensor.rotex_status_kesselpumpe
durchfluss: sensor.rotex_durchfluss
ruecklauf_1: sensor.rotex_ruecklauftemperatur_heizung
ruecklauf_2: sensor.rotex_r_cklauftemperatur
verdampfer: sensor.rotex_lamellenw_rmetauscher_temperatur
vorlauf_1: sensor.rotex_heizkreis_vorlauf_tv
vorlauf_2: sensor.rotex_vorlauftemeratur_tv
vorlauf_soll: sensor.rotex_vorlauf_soll
wasserdruck: sensor.rotex_wasserdruck
vorlauf_bh_1: sensor.rotex_vorlauftemperatur_heizung_tvbh
vorlauf_bh_2: sensor.rotex_vorlauftemeratur_tvbh
kompressor_an_aus: binary_sensor.rotex_status_kompressor
luefter: sensor.rotex_ventilatordrehzahl
verdichter: sensor.rotex_kompressor_drehzahl
speicher: sensor.rotex_warmwassertemperatur
speicher_soll: select.rotex_t_ww_soll1
mischer: sensor.rotex_dhw_mischer_position
bypass: sensor.rotex_bpv
aussen_temperatur: sensor.hpsu_can_aussentemperatur
t_aussen: sensor.hpsu_can_t_aussen
expansions_ventil: sensor.hpsu_uart_expansionsventil
kondensat: sensor.hpsu_uart_temperatur_fl_ssigkeitsleitung
umwaelzpumpe: sensor.hpsu_can_umwaelzpumpe
umwaelzpumpe_an_aus: binary_sensor.hpsu_can_status_kesselpumpe
durchfluss: sensor.hpsu_can_durchfluss
ruecklauf_1: sensor.hpsu_can_ruecklauftemperatur_heizung
ruecklauf_2: sensor.hpsu_uart_r_cklauftemperatur
verdampfer: sensor.hpsu_uart_lamellenw_rmetauscher_temperatur
vorlauf_1: sensor.hpsu_can_heizkreis_vorlauf_tv
vorlauf_2: sensor.hpsu_uart_vorlauftemeratur_tv
vorlauf_soll: sensor.hpsu_can_vorlauf_soll
wasserdruck: sensor.hpsu_can_wasserdruck
vorlauf_bh_1: sensor.hpsu_can_vorlauftemperatur_heizung_tvbh
vorlauf_bh_2: sensor.hpsu_uart_vorlauftemeratur_tvbh
kompressor_an_aus: binary_sensor.hpsu_can_status_kompressor
luefter: sensor.hpsu_uart_ventilatordrehzahl
verdichter: sensor.hpsu_uart_kompressor_drehzahl
speicher: sensor.hpsu_can_warmwassertemperatur
speicher_soll: select.hpsu_can_t_ww_soll1
mischer: sensor.hpsu_can_dhw_mischer_position
bypass: sensor.hpsu_can_bpv
betriebsmodus: select.hpsu_can_betriebsmodus
thermische_leistung: sensor.hpsu_can_thermische_leistung
betriebsart: sensor.hpsu_can_betriebsart

136 changes: 0 additions & 136 deletions dist/hpsu-dashboard-card-editor.js

This file was deleted.

155 changes: 145 additions & 10 deletions dist/hpsu-dashboard-card.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
//import { LitElement, html, css } from "lit";
import { LitElement, html, css } from "https://unpkg.com/[email protected]/lit-element.js?module";


const entities_configuration = [
{ id: "aussen_temperatur", label: "Außentemperatur", type: "sensor", rectId: "aussentemp_val", offset: 6, category: "Reihe 1", unit: "°C" },
{ id: "t_aussen", label: "T-Außen", type: "sensor", rectId: "taussen_val", offset: 6, unit: "°C" },
{ id: "expansions_ventil", label: "Elektonisches Expansionsventil", type: "sensor", rectId: "eev_val", offset: 6, unit: "%" },
{ id: "kondensat", label: "Kondensat", type: "sensor", rectId: "Kondensat-Value", offset: 6, unit: "°C" },
{ id: "umwaelzpumpe", label: "Umwälzpumpe", type: "sensor", rectId: "Umwaelzpumpe-Value", offset: 6, unit: "%" },
{ id: "umwaelzpumpe_an_aus", label: "Status Umwälzpumpe", type: "binary_sensor", rectId: "circ_pump_rect", offset: 2, fontSize: "30px" },
{ id: "durchfluss", label: "Durchfluss", type: "sensor", rectId: "Durchfluss-Value", offset: 6 },
{ id: "ruecklauf_1", label: "Rücklauf CAN", type: "sensor", rectId: "Ruecklauf-1-Value", offset: 6, unit: "°C" },
{ id: "ruecklauf_2", label: "Rücklauf UART", type: "sensor", rectId: "Ruecklauf-2-Value", offset: 6, unit: "°C" },
{ id: "verdampfer", label: "Verdampfer", type: "sensor", rectId: "Verdampfer-Value", offset: 6, category: "Reihe 2", unit: "°C" },
{ id: "vorlauf_1", label: "Vorlauf CAN", type: "sensor", rectId: "Vorlauf-1-Value", offset: 6, unit: "°C" },
{ id: "vorlauf_2", label: "Vorlauf UART", type: "sensor", rectId: "Vorlauf-2-Value", offset: 6, unit: "°C" },
{ id: "vorlauf_soll", label: "Vorlauf Soll", type: "sensor", rectId: "Vorlauf-Soll-Value", offset: 6, unit: "°C" },
{ id: "wasserdruck", label: "Wasserdruck", type: "sensor", rectId: "Druck-Value", offset: 6 },
{ id: "vorlauf_bh_1", label: "VorlaufBH CAN", type: "sensor", rectId: "Vorlauf-BH-1-Value", offset: 6, unit: "°C" },
{ id: "vorlauf_bh_2", label: "VorlaufBH UART", type: "sensor", rectId: "Vorlauf-BH-2-Value", offset: 6, unit: "°C" },
{ id: "kompressor_an_aus", label: "Status Kompressor", type: "binary_sensor", rectId: "comp_rect", offset: 2, fontSize: "40px" },
{ id: "luefter", label: "Lüfter", type: "sensor", rectId: "Luefter-Value", offset: 6, category: "Reihe 3", unit: "RPM" },
{ id: "verdichter", label: "Verdichter", type: "sensor", rectId: "Verdichter-Value", offset: 6, unit: "RPM" },
{ id: "speicher", label: "Speicher Ist", type: "sensor", rectId: "Speicher-Value", offset: 6, unit: "°C" },
{ id: "speicher_soll", label: "Speicher Soll", type: "select", rectId: "Speicher-Soll-Value", offset: 6, unit: "°C" },
{ id: "mischer", label: "Mischer", type: "sensor", rectId: "DHW-Mixer-Value", offset: 6, unit: "%", fontSize: "40px" },
{ id: "bypass", label: "Bypass", type: "sensor", rectId: "Bypass-Value", offset: 6, unit: "%", fontSize: "40px" },
{ id: "betriebsmodus", label: "Betriebsmodus", type: "select", rectId: "info_1", offset: 6, fontSize: "40px", align: "left", "suffix": "Modus: " },
{ id: "betriebsart", label: "Betriebsart", type: "text_sensor", rectId: "info_2", offset: 6, fontSize: "40px", align: "left", "suffix": "Betriebsart: " },
{ id: "thermische_leistung", label: "Thermische Leistung", type: "sensor", rectId: "info_3", offset: 6, fontSize: "40px", align: "left", "suffix": "Therm. Leistung: " }
];

//////////////////////////////////////////////////////////////////
/////////////////////// HPSUDashboardCard ////////////////////////
//////////////////////////////////////////////////////////////////

class HPSUDashboardCard extends HTMLElement {
inititialized = false;

Expand All @@ -7,7 +44,7 @@ class HPSUDashboardCard extends HTMLElement {
throw new Error("Required entities field is missing");
}

this.entities_configuration = await this.loadModule();
this.entities_configuration = entities_configuration;
this.entities_configuration = this.entities_configuration.map(
(entity) => {
entity.entityId = config.entities[entity.id];
Expand Down Expand Up @@ -312,17 +349,115 @@ class HPSUDashboardCard extends HTMLElement {
console.log(url);
return url;
}
}

//////////////////////////////////////////////////////////////////
//////////////////// HpsuDashboardCardEditor /////////////////////
//////////////////////////////////////////////////////////////////

class HpsuDashboardCardEditor extends LitElement {

static get properties() {
return {
config: { type: Object },
entities: { type: Array }
};
}

constructor() {
super();
this.entities = []; // Initialisiere das Array für die Entities
}

async setConfig(config) {
const cardHelpers = await window.loadCardHelpers();
const entitiesCard = await cardHelpers.createCardElement({ type: "entities", entities: [] });

// Lade den Editor über die statische Methode getConfigElement
const editorElement = entitiesCard.constructor.getConfigElement();

this.entities_configuration = entities_configuration;
this.entities_configuration = this.entities_configuration.map(
(entity) => {
entity.entityId = config.entities[entity.id];
return entity;
}
);
this.config = config;

async loadModule() {
console.log(">> loadModule");
try {
const url = this.makeURL("modules.js");
const module = await import(url);
return module.entities_configuration;
} catch (error) {
console.error("Modul konnte nicht geladen werden:", error);
// Füge den Editor dem DOM hinzu
//this.shadowRoot.appendChild(editorElement);
}

render() {
if (!this.config) return html``;

return html`
${this.entities_configuration.map(
(entity) => {
return html`
${(entity.category) ? html`<h2>${entity.category}</h2>` : ""}
<ha-entity-picker
allow-custom-entity
data-id=${entity.id}
label=${entity.label}
.value=${entity.entityId}
.curValue=${entity.entityId}
.hass=${this.hass}
.includeDomains=${entity.type}
.includeUnitOfMeasurement=${entity.unit}
.disabled=false
.createDomains=false
@value-changed=${this._entityChanged}
></ha-entity-picker>`;
}
)}
`;
}

_entityChanged(event) {
event.stopPropagation();

const entityId = event.target.getAttribute("data-id");
this.config.entities[entityId] = event.detail.value;
this.dispatchEvent(new CustomEvent('config-changed', { detail: { config: this.config } }));
}

static get styles() {
return css`
.card-config {
display: flex;
flex-direction: column;
padding: 16px;
}
h2 {
font-size: 20px;
margin-bottom: 16px;
}
paper-input {
margin-bottom: 16px; /* Abstand zwischen den Eingabefeldern */
}
`;
}

getKyeByValue(map, searchValue) {
for (let [key, value] of map.entries()) {
if (value === searchValue) {
return key;
}
}
return null;
}
}

customElements.define("hpsu-dashboard-card", HPSUDashboardCard);

customElements.define("hpsu-dashboard-card", HPSUDashboardCard);
customElements.define('hpsu-dashboard-card-editor', HpsuDashboardCardEditor);

window.customCards = window.customCards || [];
window.customCards.push({
type: 'hpsu-dashboard-card',
name: 'HPSU Dashboard Card',
description: 'Eine Karte für das HPSU Dashboard.',
editor: 'hpsu-dashboard-card-editor'
});
Loading

0 comments on commit 2e0cfb0

Please sign in to comment.