diff --git a/build.js b/build.js index f6b905f..f96453e 100644 --- a/build.js +++ b/build.js @@ -6,7 +6,7 @@ const DIST_DIR = 'dist'; const OUTPUT_FILE = path.join(DIST_DIR, 'power-flux-card.js'); // Ensure dist dir exists -if (!fs.existsSync(DIST_DIR)){ +if (!fs.existsSync(DIST_DIR)) { fs.mkdirSync(DIST_DIR); } @@ -24,17 +24,17 @@ const cardTranslations = {}; langFiles.forEach(file => { const langCode = file.replace('lang-', '').replace('.js', ''); - + let content = fs.readFileSync(path.join(SRC_DIR, file), 'utf8'); // Remove export default content = content.replace('export default', '').trim(); if (content.endsWith(';')) { content = content.slice(0, -1); } - + // Assign to a variable langDefinitions += `const lang_${langCode} = ${content};\n`; - + // Add to merge logic mergeScript += `editorTranslations['${langCode}'] = lang_${langCode}.editor;\n`; mergeScript += `cardTranslations['${langCode}'] = lang_${langCode}.card;\n`; diff --git a/dist/power-flux-card.js b/dist/power-flux-card.js index d958ace..200e84a 100644 --- a/dist/power-flux-card.js +++ b/dist/power-flux-card.js @@ -14,6 +14,7 @@ const lang_de = { "editor.consumers_section": "Zusätzliche Verbraucher", "editor.options_section": "Darstellung & Optionen", "editor.flow_rate_title": "Flussraten (W) an Röhren anzeigen", + "editor.invert_battery": "Wert umkehren (+/-)", "editor.label_toggle": "Label im Kreis anzeigen", "editor.compact_view": "Kompakte Ansicht (evcc)", "editor.hide_inactive": "Inaktive Röhren ausblenden", @@ -42,6 +43,7 @@ const lang_en = { "editor.consumers_section": "Additional Consumers", "editor.options_section": "Appearance & Options", "editor.flow_rate_title": "Show Flow Rates (W) on pipes", + "editor.invert_battery": "Invert Power Value (+/-)", "editor.label_toggle": "Show Label in Bubble", "editor.compact_view": "Compact View (evcc)", "editor.hide_inactive": "Hide Inactive Pipes", @@ -69,17 +71,30 @@ cardTranslations['en'] = lang_en.card; + + + +const editorTranslations = { + "en": lang_en.editor, + "de": lang_de.editor +}; + +const cardTranslations = { + "en": lang_en.card, + "de": lang_de.card +}; + const fireEvent = (node, type, detail, options) => { - options = options || {}; - detail = detail === null || detail === undefined ? {} : detail; - const event = new Event(type, { - bubbles: options.bubbles === undefined ? true : options.bubbles, - cancelable: Boolean(options.cancelable), - composed: options.composed === undefined ? true : options.composed, - }); - event.detail = detail; - node.dispatchEvent(event); - return event; + options = options || {}; + detail = detail === null || detail === undefined ? {} : detail; + const event = new Event(type, { + bubbles: options.bubbles === undefined ? true : options.bubbles, + cancelable: Boolean(options.cancelable), + composed: options.composed === undefined ? true : options.composed, + }); + event.detail = detail; + node.dispatchEvent(event); + return event; }; const LitElement = customElements.get("ha-lit-element") || Object.getPrototypeOf(customElements.get("home-assistant-main")); @@ -87,83 +102,84 @@ const html = LitElement.prototype.html; const css = LitElement.prototype.css; class PowerFluxCardEditor extends LitElement { - - static get properties() { - return { - hass: {}, - _config: { state: true }, - _subView: { state: true } // Controls which sub-page is open (null = main) - }; - } - setConfig(config) { - this._config = config; - } - - _localize(key) { - const lang = this.hass && this.hass.language ? this.hass.language : 'en'; - const dict = editorTranslations[lang] || editorTranslations['en']; - return dict[key] || editorTranslations['en'][key] || key; - } - - _valueChanged(ev) { - if (!this._config || !this.hass) return; - - const target = ev.target; - const key = target.configValue || this._currentConfigValue; - - let value; - if (target.tagName === 'HA-SWITCH') { - value = target.checked; - } else if (ev.detail && 'value' in ev.detail) { - value = ev.detail.value; - } else { - value = target.value; - } - - if (value === null || value === undefined) { - value = ""; + static get properties() { + return { + hass: {}, + _config: { state: true }, + _subView: { state: true } // Controls which sub-page is open (null = main) + }; } - if (key) { - const entityKeys = [ - 'solar', 'grid', 'grid_export', - 'battery', 'battery_soc', - 'consumer_1', 'consumer_2', 'consumer_3' - ]; + setConfig(config) { + this._config = config; + } - let newConfig = { ...this._config }; + _localize(key) { + const lang = this.hass && this.hass.language ? this.hass.language : 'en'; + const dict = editorTranslations[lang] || editorTranslations['en']; + return dict[key] || editorTranslations['en'][key] || key; + } - if (entityKeys.includes(key)) { - const currentEntities = newConfig.entities || {}; - const newEntities = { ...currentEntities, [key]: value }; - newConfig.entities = newEntities; + _valueChanged(ev) { + if (!this._config || !this.hass) return; + + const target = ev.target; + const key = target.configValue || this._currentConfigValue; + + let value; + if (target.tagName === 'HA-SWITCH') { + value = target.checked; + } else if (ev.detail && 'value' in ev.detail) { + value = ev.detail.value; } else { - newConfig[key] = value; - - if (key === 'show_comet_tail' && value === true) { - newConfig.show_dashed_line = false; - } - if (key === 'show_dashed_line' && value === true) { - newConfig.show_comet_tail = false; - } + value = target.value; } - this._config = newConfig; - fireEvent(this, "config-changed", { config: this._config }); + if (value === null || value === undefined) { + value = ""; + } + + if (key) { + const entityKeys = [ + 'solar', 'grid', 'grid_export', + 'battery', 'battery_soc', + 'house', + 'consumer_1', 'consumer_2', 'consumer_3' + ]; + + let newConfig = { ...this._config }; + + if (entityKeys.includes(key)) { + const currentEntities = newConfig.entities || {}; + const newEntities = { ...currentEntities, [key]: value }; + newConfig.entities = newEntities; + } else { + newConfig[key] = value; + + if (key === 'show_comet_tail' && value === true) { + newConfig.show_dashed_line = false; + } + if (key === 'show_dashed_line' && value === true) { + newConfig.show_comet_tail = false; + } + } + + this._config = newConfig; + fireEvent(this, "config-changed", { config: this._config }); + } } - } - _goSubView(view) { - this._subView = view; - } + _goSubView(view) { + this._subView = view; + } - _goBack() { - this._subView = null; - } + _goBack() { + this._subView = null; + } - static get styles() { - return css` + static get styles() { + return css` .card-config { display: flex; flex-direction: column; @@ -241,12 +257,12 @@ class PowerFluxCardEditor extends LitElement { margin: 10px 0; } `; - } + } - // --- SUBVIEW RENDERING --- + // --- SUBVIEW RENDERING --- - _renderSolarView(entities, entitySelectorSchema, textSelectorSchema, iconSelectorSchema) { - return html` + _renderSolarView(entities, entitySelectorSchema, textSelectorSchema, iconSelectorSchema) { + return html`