UNPKG

iobroker.nspanel-lovelace-ui

Version:

NsPanel Lovelace UI is a Firmware for the nextion screen inside of NSPanel in the Design of Lovelace UI Design.

1,192 lines (1,191 loc) 121 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var pageItem_exports = {}; __export(pageItem_exports, { PageItem: () => PageItem }); module.exports = __toCommonJS(pageItem_exports); var import_Color = require("../const/Color"); var typePageItem = __toESM(require("../types/type-pageItem")); var tools = __toESM(require("../const/tools")); var import_icon_mapping = require("../const/icon_mapping"); var import_data_item = require("../controller/data-item"); var import_function_and_const = require("../types/function-and-const"); var import_baseClassPage = require("../classes/baseClassPage"); class PageItem extends import_baseClassPage.BaseTriggeredPage { defaultOnColor = import_Color.Color.White; defaultOffColor = import_Color.Color.Blue; config; dataItems; id; lastPopupType = void 0; parent; tempData = void 0; // use this to save some data while object is active tempInterval; confirmClick = "lock"; timeouts = {}; // for select - force next read of common updateCommon = { lastRequest: 0, counts: 0 }; constructor(config, options) { super({ name: config.name, adapter: config.adapter, panel: config.panel, dpInit: config.dpInit }); this.id = config.id; this.config = options; if (!config || !config.parent) { throw new Error(`PageItem ${this.id} has no parent page`); } this.parent = config && config.parent; this.name = `${this.parent.name}.${this.id}`; this.sleep = false; this.enums = options && "enums" in options && options.enums ? options.enums : ""; } static async getPageItem(config, options) { if (options === void 0) { return void 0; } if (config.panel.persistentPageItems[config.id]) { return config.panel.persistentPageItems[config.id]; } const p = new PageItem(config, options); await p.init(); return p; } async init() { var _a, _b, _c, _d, _e, _f; if (!this.config) { return; } const config = structuredClone(this.config); const tempItem = await this.parent.basePanel.statesControler.createDataItems( config.data, this, {}, "data", config.readOptions ); this.dataItems = { ...config, data: tempItem }; this.canBeHidden = !!((_a = this.dataItems.data) == null ? void 0 : _a.enabled); if (this.dataItems.data && "enabled" in this.dataItems.data && this.dataItems.data.enabled) { this.canBeHidden = true; } switch (this.dataItems.type) { case "number": case "button": case "switch": case "shutter2": case "empty": case "input_sel": case "light": case "light2": case "text": case "fan": { break; } case "shutter": { const data = this.dataItems.data; this.tempData = []; this.tempData[0] = data.up && data.up.writeable; this.tempData[1] = data.stop && data.stop.writeable; this.tempData[2] = data.down && data.down.writeable; this.tempData[3] = data.up2 && data.up2.writeable; this.tempData[4] = data.stop2 && data.stop2.writeable; this.tempData[5] = data.down2 && data.down2.writeable; const list = await this.getListCommands(data.setList); if (list) { for (let a = 0; a < 6; a++) { const test = list && list[a] && list[a].id && await this.parent.basePanel.statesControler.getObjectAsync(list[a].id); if (test && test.common && test.common.write) { this.tempData[a] = true; } } } if (data.entity1 && data.entity1.value) { if (data.entity1.value.type === "number" && data.entity1.minScale && data.entity1.maxScale && data.entity1.value && data.entity1.value.writeable || data.entity1.value.type === "boolean" && data.entity1.value && data.entity1.value.writeable) { this.tempData[1] = true; this.tempData[3] = true; } } if (data.entity2 && data.entity2.value) { if (data.entity2.value.type === "number" && data.entity2.minScale && data.entity2.maxScale && data.entity2.value && data.entity2.value.writeable) { this.tempData[3] = true; this.tempData[5] = true; } } break; } case "timer": { if (this.dataItems.role === "timer" && this.tempData === void 0) { if ((_d = (_c = (_b = this.dataItems.data.entity1) == null ? void 0 : _b.value) == null ? void 0 : _c.common) == null ? void 0 : _d.role) { if (["value.timer", "level.timer"].indexOf(this.dataItems.data.entity1.value.common.role) !== -1) { this.tempData = { status: "pause", role: "ex-timer" }; break; } this.tempData = { status: "pause", role: "ex-alarm" }; break; } this.tempData = { status: "pause", value: 0, role: "timer" }; if (!this.parent.basePanel.persistentPageItems[this.id]) { this.parent.basePanel.persistentPageItems[this.id] = this; } } break; } } if (["screensaver", "screensaver2", "screensaver3", "popupNotify", "popupNotify2"].indexOf(this.parent.card) !== -1) { if (!this.parent.basePanel.persistentPageItems[this.id]) { if (this.config.modeScr) { switch (this.config.modeScr) { case "left": case "bottom": case "indicator": case "alternate": case "favorit": break; case "mricon": break; case "time": case "date": this.neverDeactivateTrigger = true; break; } } this.parent.basePanel.persistentPageItems[this.id] = this; await this.controller.statesControler.activateTrigger(this); } } if (this.config.role === "alexa-speaker") { const id = (_e = this.parent.items[0].ident) != null ? _e : ""; const arr = id.split(".").slice(0, 3); const str = arr.join("."); const devices = str && arr.length === 3 ? await this.adapter.getObjectViewAsync("system", "device", { startkey: `${str}.`, endkey: `${str}${String.fromCharCode(65533)}` }) : { rows: [] }; this.tempData = []; if (devices && devices.rows && devices.rows.length > 0) { if (this.dataItems && this.dataItems.type === "input_sel") { const data = this.dataItems.data; let filter = await ((_f = data == null ? void 0 : data.valueList) == null ? void 0 : _f.getObject()) || null; filter = Array.isArray(filter) && filter.length > 0 ? filter : null; for (const instance of devices.rows) { if (instance && instance.value && instance.id && instance.id.split(".").length === 4) { if (await this.adapter.getForeignObjectAsync(`${instance.id}.Player`)) { const name = typeof instance.value.common.name === "object" ? instance.value.common.name.en : instance.value.common.name; if (!filter || filter.includes(name)) { this.log.debug(`Alexa device: ${name} deviceId: ${instance.id}`); this.tempData.push({ id: instance.id, name }); } } } } } this.log.debug(`Alexa devices found: ${this.tempData.length} frosm ${devices.rows.length}`); } } else if (this.config.role === "alexa-playlist" && this.dataItems && this.dataItems.type === "input_sel" && this.parent.card === "cardMedia") { const states = await this.adapter.getForeignStatesAsync( `${this.parent.currentItem ? this.parent.currentItem.ident : this.parent.items[0].ident}.Music-Provider.*` ); if (states) { this.tempData = Object.keys(states); } } } async getPageItemPayload() { var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga; await this.controller.statesControler.activateTrigger(this); this.lastPopupType = void 0; if (this.dataItems && this.config) { this.visibility = false; this.triggerParent = true; const entry = this.dataItems; const message = {}; message.intNameEntity = this.id; if (!await this.isEnabled()) { return ""; } switch (entry.type) { case "light": case "light2": { const item = entry.data; if (this.config.role === "volume.mute") { message.type = "light"; } else { message.type = (0, import_function_and_const.isCardGridType)(this.parent.card) && (this.config.role === "light" || this.config.role === "socket") ? "switch" : this.parent.basePanel.overrideLightPopup ? this.parent.basePanel.lightPopupV2 && this.parent.basePanel.meetsVersion("4.7.5") ? "light2" : "light" : entry.type; } const v = await tools.getValueEntryBoolean(item.entity1); const dimmer = (_a = item.dimmer && item.dimmer.value && await item.dimmer.value.getNumber()) != null ? _a : null; if (this.config.role === "volume.mute") { message.icon = await tools.getIconEntryValue(item.icon, !!v, "volume-high"); message.optionalValue = v ? "1" : "0"; message.iconColor = await tools.getIconEntryColor(item.icon, !!v, import_Color.Color.on, import_Color.Color.off); } else { let rgb = (_c = (_b = await tools.getRGBfromRGBThree(item)) != null ? _b : item.color && item.color.true && await item.color.true.getRGBValue()) != null ? _c : null; const nhue = (_d = item.hue && await item.hue.getNumber()) != null ? _d : null; if (rgb === null && nhue) { rgb = (_e = import_Color.Color.hsv2RGB(nhue, 1, 1)) != null ? _e : null; } message.icon = await tools.getIconEntryValue(item.icon, v, "", ""); let colorMode = !item.colorMode ? "none" : await item.colorMode.getBoolean() ? "hue" : "ct"; if (colorMode === "none") { const ctState = item.ct && item.ct.value && await item.ct.value.getState(); const colorState = (_j = (_i = (_h = (_g = (_f = item.Red && await item.Red.getState()) != null ? _f : item.Green && await item.Green.getState()) != null ? _g : item.Blue && await item.Blue.getState()) != null ? _h : item.color && item.color.true && await item.color.true.getState()) != null ? _i : item.hue && await item.hue.getState()) != null ? _j : null; if (ctState && colorState) { if (ctState.ts > colorState.ts) { colorMode = "ct"; } else { colorMode = "hue"; } } else if (ctState) { colorMode = "ct"; } else if (colorState) { colorMode = "hue"; } } const iconColor = dimmer != null ? ((_l = (_k = item.icon) == null ? void 0 : _k.true) == null ? void 0 : _l.color) ? await item.icon.true.color.getRGBValue() : import_Color.Color.Yellow : null; message.iconColor = (_n = (_m = colorMode === "hue" ? await tools.GetIconColor( rgb != null ? rgb : void 0, dimmer != null ? dimmer > 30 ? dimmer : 30 : v ) : await tools.getTemperaturColorFromValue(item.ct, dimmer != null ? dimmer : 100)) != null ? _m : iconColor ? await tools.GetIconColor(iconColor, dimmer != null ? dimmer > 30 ? dimmer : 30 : v) : await tools.getIconEntryColor(item.icon, dimmer != null ? dimmer : v, import_Color.Color.Yellow)) != null ? _n : ""; if (v) { message.optionalValue = "1"; } else { message.optionalValue = "0"; } } message.displayName = this.library.getTranslation( (_p = (_o = await tools.getEntryTextOnOff(item.headline, v)) != null ? _o : message.displayName) != null ? _p : "" ); return tools.getItemMesssage(message); break; } case "shutter": { const item = entry.data; message.type = "shutter"; let value = await tools.getValueEntryNumber(item.entity1); if (value === null) { value = await tools.getValueEntryBoolean(item.entity1); } else { value = !this.adapter.config.shutterClosedIsZero ? 100 - value : value; } if (value === null) { this.log.warn(`Entity ${this.config.role} has no value! No Actual or Set`); break; } message.icon = await tools.getIconEntryValue(item.icon, value, "window-open"); message.iconColor = await tools.getIconEntryColor(item.icon, value, import_Color.Color.White); const optionalValue = item.valueList ? await item.valueList.getObject() : [ "arrow-up", //up "stop", //stop "arrow-down" //down ]; let optionalValueC = Array.isArray(optionalValue) && optionalValue.every((a) => typeof a === "string") ? [...optionalValue] : ["", "", ""]; optionalValueC = optionalValueC.splice(0, 3).map((a) => a ? import_icon_mapping.Icons.GetIcon(a) : a); optionalValueC.forEach((a, i) => { if (a) { optionalValueC[i + 3] = this.tempData[i] ? "enable" : "disable"; } else { optionalValueC[i] = ""; optionalValueC[i + 3] = "disable"; } }); optionalValueC[3] = value === 0 ? "disable" : optionalValueC[3]; optionalValueC[5] = value === 100 ? "disable" : optionalValueC[5]; message.optionalValue = optionalValueC.join("|"); message.displayName = this.library.getTranslation( (_r = (_q = await tools.getEntryTextOnOff(item.headline, !!value)) != null ? _q : message.displayName) != null ? _r : "" ); return tools.getItemMesssage(message); } case "shutter2": { const item = entry.data; message.type = "shutter2"; let value = await tools.getValueEntryNumber(item.entity1); if (value === null) { value = await tools.getValueEntryBoolean(item.entity1); } else { value = !this.adapter.config.shutterClosedIsZero ? 100 - value : value; } if (value === null) { this.log.warn(`Entity ${this.config.role} has no value! No Actual or Set`); break; } message.icon = await tools.getIconEntryValue(item.icon, value, "window-open"); message.iconColor = await tools.getIconEntryColor(item.icon, value, import_Color.Color.White); const optionalValue = [ (item == null ? void 0 : item.up) ? "arrow-up" : "", //up (item == null ? void 0 : item.stop) ? "stop" : "", //stop (item == null ? void 0 : item.stop) ? "arrow-down" : "" //down ]; let optionalValueC = Array.isArray(optionalValue) && optionalValue.every((a) => typeof a === "string") ? [...optionalValue] : ["", "", ""]; optionalValueC = optionalValueC.splice(0, 3).map((a) => a ? import_icon_mapping.Icons.GetIcon(a) : a); optionalValueC.forEach((a, i) => { if (a) { optionalValueC[i + 3] = optionalValueC[i] ? "enable" : "disable"; } else { optionalValueC[i] = ""; optionalValueC[i + 3] = "disable"; } }); optionalValueC[3] = value === 0 ? "disable" : optionalValueC[3]; optionalValueC[5] = value === 100 ? "disable" : optionalValueC[5]; message.optionalValue = optionalValueC.join("|"); message.displayName = this.library.getTranslation( (_t = (_s = await tools.getEntryTextOnOff(item.headline, !!value)) != null ? _s : message.displayName) != null ? _t : "" ); return tools.getItemMesssage(message); } case "number": { if (entry.type === "number") { const item = entry.data; message.type = "number"; const number = (_u = await tools.getValueEntryNumber(item.entity1, false)) != null ? _u : 0; const value = (_v = item.switch1 && await item.switch1.getBoolean()) != null ? _v : null; message.displayName = this.library.getTranslation( (_w = await tools.getEntryTextOnOff(item.text, true)) != null ? _w : "" ); message.icon = entry.role === "textNotIcon" ? (_x = await tools.getIconEntryValue(item.icon, value, "", null, true)) != null ? _x : "" : (_y = await tools.getIconEntryValue(item.icon, value !== true, "")) != null ? _y : ""; message.iconColor = (_z = await tools.getIconEntryColor(item.icon, value !== true, import_Color.Color.HMIOn)) != null ? _z : ""; let min = item.entity1 && item.entity1.value && item.entity1.value.common.min; let max = item.entity1 && item.entity1.value && item.entity1.value.common.max; min = (_B = (_A = item.minValue1 && await item.minValue1.getNumber()) != null ? _A : min) != null ? _B : 0; max = (_D = (_C = item.maxValue1 && await item.maxValue1.getNumber()) != null ? _C : max) != null ? _D : 100; return tools.getPayloadRemoveTilde( message.type, message.intNameEntity, message.icon, message.iconColor, message.displayName, `${number}|${min}|${max}` ); } break; } /** * entity1 is value to calculate color * entity2 is display value */ case "text": case "button": case "switch": { if (entry.type === "text" || entry.type === "button" || entry.type === "switch") { const item = entry.data; let value = await tools.getValueEntryNumber(item.entity1, true); if (value === null) { value = await tools.getValueEntryBoolean(item.entity1); } if (value === null) { value = true; } if (entry.role === "text.states") { const key = value ? "true" : "false"; const dataitem = ((_E = item.text) == null ? void 0 : _E[key]) ? (0, import_data_item.isDataItem)(item.text[key]) ? item.text[key] : item.text[key].value : null; const states = dataitem ? await dataitem.getCommonStates() : null; if (states && dataitem) { const v = await dataitem.getString(); if (v != null && states[v]) { message.displayName = (_F = this.library.getTranslation(states[v])) != null ? _F : ""; } } } else { message.displayName = this.library.getTranslation( (_G = await tools.getEntryTextOnOff(item.text, !!value)) != null ? _G : "" ); } if (entry.type === "switch") { message.optionalValue = (value != null ? value : true) ? "1" : "0"; } else if (entry.type === "button") { message.optionalValue = (value != null ? value : true) ? "1" : "0"; if ((0, import_function_and_const.isCardEntitiesType)(this.parent.card)) { message.optionalValue = (_H = this.library.getTranslation(await tools.getEntryTextOnOff(item.text1, !!value))) != null ? _H : message.optionalValue; } } else { switch (entry.role) { case "2values": { message.optionalValue = ``; const val1 = await tools.getValueEntryNumber(item.entity1); const val2 = await tools.getValueEntryNumber(item.entity2); const unit1 = item.entity1 && item.entity1.unit && await item.entity1.unit.getString(); const unit2 = item.entity2 && item.entity2.unit && await item.entity2.unit.getString(); if (val1 !== null && val2 !== null) { message.optionalValue = String(val1) + (unit1 != null ? unit1 : "") + String(val2) + (unit2 != null ? unit2 : ""); if (typeof value === "number") { value = val1 + val2 / 2; } } break; } case "4values": { let val = await tools.getValueEntryString(item.entity1); value = true; if (val === null) { value = false; val = await tools.getValueEntryString(item.entity2); if (val === null) { value = true; val = await tools.getValueEntryString(item.entity3); if (val === null) { value = false; val = await tools.getValueEntryString(item.entity4); } } } if (val) { message.optionalValue = this.library.getTranslation(val); } else { message.optionalValue = ""; } break; } default: { message.optionalValue = this.library.getTranslation( (_J = (_I = await tools.getValueEntryString(item.entity2)) != null ? _I : await tools.getEntryTextOnOff(item.text1, value)) != null ? _J : "" ); } } } if (entry.type === "button" && entry.data.confirm) { if (this.confirmClick === "unlock") { if ((0, import_function_and_const.isCardEntitiesType)(this.parent.card)) { message.optionalValue = (_K = await entry.data.confirm.getString()) != null ? _K : message.optionalValue; } this.confirmClick = Date.now(); } else { this.confirmClick = "lock"; } } message.icon = await tools.getIconEntryValue(item.icon, value, "home"); switch (entry.role) { case "textNotIcon": { message.icon = (_L = await tools.getIconEntryValue(item.icon, value, "", null, true)) != null ? _L : ""; break; } case "iconNotText": { message.icon = (_M = await tools.getIconEntryValue(item.icon, value, "", null, false)) != null ? _M : ""; break; } case "battery": { const val = (_N = await tools.getValueEntryBoolean(item.entity3)) != null ? _N : false; message.icon = (_O = await tools.getIconEntryValue(item.icon, val, "", "", false)) != null ? _O : ""; break; } case "combined": { message.icon = (_P = await tools.getIconEntryValue(item.icon, value, "", null, false)) != null ? _P : ""; message.icon += (_Q = await tools.getIconEntryValue(item.icon, value, "", null, true)) != null ? _Q : ""; break; } default: { message.icon = (_S = await tools.getIconEntryValue( item.icon, !!value, "", null, (_R = !(0, import_function_and_const.isCardEntitiesType)(this.parent.card) && !this.parent.card.startsWith("screens")) != null ? _R : false )) != null ? _S : ""; } } const additionalId = entry.data.additionalId ? await entry.data.additionalId.getString() : ""; message.iconColor = await tools.getIconEntryColor(item.icon, value != null ? value : true, import_Color.Color.HMIOn); return tools.getPayloadRemoveTilde( entry.type, message.intNameEntity + additionalId, message.icon, message.iconColor, (_T = message.displayName) != null ? _T : "", message.optionalValue ); } break; } case "input_sel": { const item = entry.data; message.type = "input_sel"; let value = (_U = await tools.getValueEntryNumber(item.entityInSel)) != null ? _U : await tools.getValueEntryBoolean(item.entityInSel); if (entry.role === "alexa-speaker") { value = this.parent.currentItem === this.parent.items[0]; } message.icon = await tools.getIconEntryValue(item.icon, !!(value != null ? value : true), "gesture-tap-button"); message.iconColor = (_V = await tools.getIconEntryColor(item.icon, !!(value != null ? value : true), import_Color.Color.HMIOff)) != null ? _V : import_Color.Color.HMIOn; message.displayName = this.library.getTranslation( (_X = (_W = await tools.getEntryTextOnOff(item.headline, !!(value != null ? value : true))) != null ? _W : message.displayName) != null ? _X : "" ); message.optionalValue = this.library.getTranslation( (_Y = await tools.getEntryTextOnOff(item.text, !!(value != null ? value : true), true)) != null ? _Y : "PRESS" ); return tools.getItemMesssage(message); break; } case "fan": { if (entry.type === "fan") { const item = entry.data; message.type = "fan"; const value = (_Z = await tools.getValueEntryBoolean(item.entity1)) != null ? _Z : null; message.displayName = this.library.getTranslation( (_$ = (__ = await tools.getEntryTextOnOff(item.headline, true)) != null ? __ : message.displayName) != null ? _$ : "" ); message.icon = (_aa = await tools.getIconEntryValue(item.icon, value, "")) != null ? _aa : ""; message.iconColor = (_ba = await tools.getIconEntryColor(item.icon, value, import_Color.Color.HMIOn)) != null ? _ba : ""; return tools.getPayloadRemoveTilde( message.type, message.intNameEntity, message.icon, message.iconColor, message.displayName, value ? "1" : "0" ); } } break; /** * 3 Funktionen * 1. Countdown * 2. Wecker stellen * 3. Countdown anzeigen */ case "timer": { if (entry.type === "timer") { const item = entry.data; message.type = "timer"; const value = (_da = (_ca = item.entity1 && item.entity1.value && await tools.getValueEntryNumber(item.entity1)) != null ? _ca : this.tempData && this.tempData.time) != null ? _da : 0; if (value !== null) { let opt = ""; if (this.tempData) { switch (this.tempData.role) { case "ex-timer": { opt = new Date((/* @__PURE__ */ new Date()).setHours(0, 0, 0, value)).toLocaleTimeString("de", { hour: "2-digit", minute: "2-digit", second: "2-digit" }); break; } case "ex-alarm": { opt = new Date((/* @__PURE__ */ new Date()).setHours(0, 0, 0, value)).toLocaleTimeString("de", { hour: "2-digit", minute: "2-digit", second: "2-digit" }); break; } case "timer": { opt = new Date( (/* @__PURE__ */ new Date()).setHours(0, 0, this.tempData.time || 0, 0) ).toLocaleTimeString("de", { hour: "2-digit", minute: "2-digit", second: "2-digit" }); break; } } } const s = item.setValue2 && await item.setValue2.getNumber(); let v = !!value; if (s != null) { v = s > 1; } message.iconColor = await tools.getIconEntryColor(item.icon, v, import_Color.Color.White); message.icon = await tools.getIconEntryValue(item.icon, v, "gesture-tap-button"); message.optionalValue = this.library.getTranslation( (_ea = await tools.getEntryTextOnOff(item.text, value !== 0)) != null ? _ea : opt ); message.displayName = this.library.getTranslation( (_ga = (_fa = await tools.getEntryTextOnOff(item.headline, true)) != null ? _fa : message.displayName) != null ? _ga : "" ); return tools.getPayloadRemoveTilde( message.type, message.intNameEntity, message.icon, message.iconColor, message.displayName, message.optionalValue ); } } break; } case "empty": { return tools.getPayloadRemoveTilde("", "delete", "", "", "", ""); } break; } } this.log.warn( `Something went wrong on ${this.id} type: ${this.config && this.config.type} role: ${this.dataItems && this.dataItems.role} dataitems.type: ${this.dataItems && this.dataItems.type}!` ); return "~~~~~"; } getDetailPayload(message) { var _a; this.triggerParent = false; if (!message.type) { return ""; } switch (message.type) { case "2Sliders": { let result = { type: "2Sliders", icon: "", entityName: "test", slidersColor: "disable", buttonState: "disable", slider1Pos: "disable", slider2Pos: "disable", hueMode: false, hue_translation: "", slider2Translation: "", slider1Translation: "", popup: false }; result = { ...result, ...Object.fromEntries(Object.entries(message).filter(([_, v]) => v !== void 0)) }; return tools.getPayloadRemoveTilde( "entityUpdateDetail", result.entityName, (_a = result.icon) != null ? _a : "", result.slidersColor, result.buttonState === "disable" ? "disable" : result.buttonState ? "1" : "0", String(result.slider1Pos), String(result.slider2Pos), result.hueMode ? "enable" : "disable", result.hue_translation, result.slider2Translation, result.slider1Translation, result.popup ? "enable" : "disable" ); break; } case "insel": { let result = { type: "insel", entityName: "", headline: "", textColor: String(import_Color.Color.rgb_dec565(import_Color.Color.White)), currentState: "", list: "" }; result = { ...result, ...Object.fromEntries(Object.entries(message).filter(([_, v]) => v !== void 0)) }; return tools.getPayloadRemoveTilde( "entityUpdateDetail2", result.entityName, "", result.textColor, result.headline, result.currentState, result.list ); break; } case "popupThermo": { let result = { type: "popupThermo", entityName: "", headline: "", currentState: "", list: "" }; result = { ...result, ...Object.fromEntries(Object.entries(message).filter(([_, v]) => v !== void 0)) }; return tools.getPayloadRemoveTilde( result.headline, result.entityName, result.currentState, result.list ); break; } case "popupFan": { let result = { type: "popupFan", entityName: "", icon: "", iconColor: "", buttonstate: "", slider1: "", slider1Max: "", speedText: "", mode: "", modeList: "" }; result = { ...result, ...Object.fromEntries(Object.entries(message).filter(([_, v]) => v !== void 0)) }; return tools.getPayloadRemoveTilde( "entityUpdateDetail", result.entityName, result.icon, result.iconColor, result.buttonstate, result.slider1, result.slider1Max, result.speedText, result.mode, result.modeList ); break; } case "popupTimer": { let result = { type: "popupTimer", entityName: "", iconColor: "", minutes: "", seconds: "", editable: "0", action1: "", action2: "", action3: "", text1: "", text2: "", text3: "" }; result = { ...result, ...Object.fromEntries(Object.entries(message).filter(([_, v]) => v !== void 0)) }; return tools.getPayloadRemoveTilde( "entityUpdateDetail", result.entityName, "", result.iconColor, result.entityName, result.minutes, result.seconds, result.editable, result.action1, result.action2, result.action3, result.text1, result.text2, result.text3 ); break; } case "popupShutter": { let result = { type: "popupShutter", entityName: "", pos1: "", text2: "", pos1text: "", icon: "", iconL1: "", iconM1: "", iconR1: "", statusL1: "disable", statusM1: "disable", statusR1: "disable", pos2text: "", iconL2: "", iconM2: "", iconR2: "", statusL2: "disable", statusM2: "disable", statusR2: "disable", pos2: "disable" }; result = { ...result, ...Object.fromEntries(Object.entries(message).filter(([_, v]) => v !== void 0)) }; return tools.getPayloadRemoveTilde( "entityUpdateDetail", result.entityName, result.pos1, result.text2, result.pos1text, result.icon, result.iconL1, result.iconM1, result.iconR1, result.statusL1, result.statusM1, result.statusR1, result.pos2text, result.iconL2, result.iconM2, result.iconR2, result.statusL2, result.statusM2, result.statusR2, result.pos2 ); } case "popupShutter2": { let result = { type: "popupShutter2", entityName: "", pos1: "", text2: "", pos1text: "", icon: "", iconT1: "", iconM1: "", iconB1: "", statusT1: "disable", statusM1: "disable", statusB1: "disable", iconT2: "", iconT2Color: "", iconT2Enable: "disable", iconM2: "", iconM2Color: "", iconM2Enable: "disable", iconB2: "", iconB2Color: "", iconB2Enable: "disable", shutterTyp: "shutter", shutterClosedIsZero: this.adapter.config.shutterClosedIsZero ? "1" : "0" }; result = { ...result, ...Object.fromEntries(Object.entries(message).filter(([_, v]) => v !== void 0)) }; return tools.getPayloadRemoveTilde( "entityUpdateDetail", result.entityName, result.pos1, result.text2, result.pos1text, result.icon, result.iconT1, result.iconM1, result.iconB1, result.statusT1, result.statusM1, result.statusB1, result.iconT2, result.iconT2Color, result.iconT2Enable, result.iconM2, result.iconM2Color, result.iconM2Enable, result.iconB2, result.iconB2Color, result.iconB2Enable, result.shutterTyp, result.shutterClosedIsZero ); } case "popupSlider": { let result = { type: "popupSlider", entityName: "", tSlider1: "", tIconS1M: "", tIconS1P: "", hSlider1CurVal: "", hSlider1MinVal: "", hSlider1MaxVal: "", hSlider1ZeroVal: "", hSlider1Step: "", hSlider1Visibility: "disable", tSlider2: "", tIconS2M: "", tIconS2P: "", hSlider2CurVal: "", hSlider2MinVal: "", hSlider2MaxVal: "", hSlider2ZeroVal: "", hSlider2Step: "", hSlider2Visibility: "disable", tSlider3: "", tIconS3M: "", tIconS3P: "", hSlider3CurVal: "", hSlider3MinVal: "", hSlider3MaxVal: "", hSlider3ZeroVal: "", hSlider3Step: "", hSlider3Visibility: "disable" }; result = { ...result, ...Object.fromEntries(Object.entries(message).filter(([_, v]) => v !== void 0)) }; return tools.getPayloadRemoveTilde( "entityUpdateDetail", result.entityName, result.tSlider1, result.tIconS1M, result.tIconS1P, result.hSlider1CurVal, result.hSlider1MinVal, result.hSlider1MaxVal, result.hSlider1ZeroVal, result.hSlider1Step, result.hSlider1Visibility, result.tSlider2, result.tIconS2M, result.tIconS2P, result.hSlider2CurVal, result.hSlider2MinVal, result.hSlider2MaxVal, result.hSlider2ZeroVal, result.hSlider2Step, result.hSlider2Visibility, result.tSlider3, result.tIconS3M, result.tIconS3P, result.hSlider3CurVal, result.hSlider3MinVal, result.hSlider3MaxVal, result.hSlider3ZeroVal, result.hSlider3Step, result.hSlider3Visibility ); } } return ""; } async isEnabled() { var _a, _b, _c; if (this.config && this.dataItems) { const entry = this.dataItems; if ((_a = entry.data) == null ? void 0 : _a.enabled) { if (((_b = this.config) == null ? void 0 : _b.role) === "isDismissiblePerEvent") { if ((_c = this.tempData) == null ? void 0 : _c.isDismissiblePerEvent) { return false; } } const val = await tools.getEnabled(entry.data.enabled); return val != null ? val : true; } } return true; } async onStateChange(_dp, _state) { var _a, _b, _c; if (_state.old.val !== _state.new.val) { if (((_a = this.config) == null ? void 0 : _a.role) === "isDismissiblePerEvent") { if ((_c = (_b = this.dataItems) == null ? void 0 : _b.data) == null ? void 0 : _c.enabled) { if (Array.isArray(this.dataItems.data.enabled)) { let found = false; for (const en of this.dataItems.data.enabled) { if (en && "dp" in en.options && en.options.dp === _dp) { found = true; } } if (found) { const val = await tools.getEnabled(this.dataItems.data.enabled); if (!val) { this.tempData = { ...this.tempData, isDismissiblePerEvent: false }; } } } else { const en = this.dataItems.data.enabled; if ("dp" in en.options && en.options.dp === _dp) { const val = await tools.getEnabled(en); if (!val) { this.tempData = { ...this.tempData, isDismissiblePerEvent: false }; } } } } } } } getGlobalDismissibleID() { var _a, _b; if (((_a = this.config) == null ? void 0 : _a.role) === "isDismissiblePerEvent") { return ((_b = this.config) == null ? void 0 : _b.dismissibleIDGlobal) || null; } return null; } setDismissiblePerEvent() { var _a; if (((_a = this.config) == null ? void 0 : _a.role) === "isDismissiblePerEvent") { this.tempData = { ...this.tempData, isDismissiblePerEvent: true }; } } async GeneratePopup(mode) { var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba; if (!this.config || !this.dataItems) { return null; } const entry = this.dataItems; let message = {}; message.entityName = this.id; this.visibility = true; this.lastPopupType = mode; switch (mode) { case "popupLightNew": case "popupLight": { switch (this.config.role) { case "light": case "socket": case "dimmer": case "hue": case "ct": case "rgbThree": case "rgbSingle": case "rgb.hex": case "volume.mute": default: { message.type = "2Sliders"; if (message.type !== "2Sliders" || entry.type !== "light") { return null; } const item = entry.data; message.buttonState = (_a = await tools.getValueEntryBoolean(item.entity1)) != null ? _a : "disable"; const dimmer = item.dimmer && item.dimmer.value && await item.dimmer.value.getNumber(); if (dimmer != null && item.dimmer) { if (item.dimmer.minScale != void 0 && item.dimmer.maxScale) { message.slider1Pos = Math.trunc( import_Color.Color.scale( dimmer, await item.dimmer.minScale.getNumber(), await item.dimmer.maxScale.getNumber(), 0, 100 ) ); } else if (((_c = (_b = item.dimmer.value) == null ? void 0 : _b.common) == null ? void 0 : _c.min) !== void 0 && ((_e = (_d = item.dimmer.value) == null ? void 0 : _d.common) == null ? void 0 : _e.max)) { message.slider1Pos = Math.trunc( import_Color.Color.scale( dimmer, item.dimmer.value.common.min, item.dimmer.value.common.max, 0, 100 ) ); } else { message.slider1Pos = dimmer; } } if (message.buttonState !== "disable") { message.icon = await tools.getIconEntryValue(item.icon, message.buttonState, "", ""); } if (this.config.role !== "volume.mute") { message.slidersColor = (_g = await tools.getIconEntryColor( item.icon, message.slider1Pos === void 0 || message.slider1Pos === "disable" ? null : (_f = message.slider1Pos) != null ? _f : message.buttonState === true, import_Color.Color.White )) != null ? _g : "disable"; let rgb = null; switch (this.config.role) { case "socket": case "light": case "dimmer": case "ct": break; case "hue": { const nhue = (_h = item.hue && await item.hue.getNumber()) != null ? _h : null; if (nhue != null) { rgb = (_i = import_Color.Color.hsv2RGB(nhue, 1, 1)) != null ? _i : null; } break; } case "rgbThree": { rgb = (_j = await tools.getRGBfromRGBThree(item)) != null ? _j : null; break; } case "rgbSingle": { rgb = (_k = item.color && item.color.true && await item.color.true.getRGBValue()) != null ? _k : null; break; } case "rgb.hex": { rgb = (_l = item.color && item.color.true && await item.color.true.getRGBValue()) != null ? _l : null; break; } } message.slider2Pos = "disable"; if (item.White) { const val = await tools.getScaledNumber(item.White); message.slider2Pos = val != null ? val : "disable"; } else if (item.ct && item.ct.value) { const ct = await tools.getSliderCTFromValue(item.ct); if (ct !== null) { message.slider2Pos = parseInt(ct); } } let colorMode = !item.colorMode ? "none" : await item.colorMode.getBoolean() ? "hue" : "ct"; if (colorMode === "none") { const ctState = item.ct && item.ct.value && await item.ct.value.getState(); const colorState = (_q = (_p = (_o = (_n = (_m = item.Red && await item.Red.getState()) != null ? _m : item.Green && await item.Green.getState()) != null ? _n : item.Blue && await item.Blue.getState()) != null ? _o : item.color && item.color.true && await item.color.true.getState()) != null ? _p : item.hue && await item.hue.getState()) != null ? _q : null; if (ctState && colorState) { if (ctState.ts > colorState.ts) { colorMode = "ct"; } else { colorMode = "hue"; } } else if (ctState) { colorMode = "ct"; } else if (colorState) { colorMode = "hue"; } } message.hueMode = rgb !== null; if (rgb !== null && colorMode === "hue") { message.slidersColor = await tools.GetIconColor( rgb, message.slider1Pos !== "disable" && message.slider1Pos != null ? message.slider1Pos > 30 ? message.slider1Pos : 30 : message.buttonState !== "disable" && message.buttonState !== false ); } if (message.slider2Pos !== "disable" && colorMode === "ct") { message.slidersColor = (_r = await tools.getTemperaturColorFromValue(item.ct, dimmer != null ? dimmer : 100)) != null ? _r : ""; } message.popup = !!((_s = item.entityInSel) == null ? void 0 : _s.value); message.slider2Translation = (_t = item.text2 && item.text2.true && await item.text2.true.getString()) != null ? _t : void 0; message.hue_translation = (_u = item.text3 && item.text3.true && await item.text3.true.getString()) != null ? _u : void 0; } else { message.slider2Pos = "disable"; message.slidersColor = (_v = await tools.getIconEntryColor( item.icon, message.buttonState !== false, import_Color.Color.White )) != null ? _v : "disable"; } message.slider1Translation = (_w = item.text1 && item.text1.true && await item.text1.true.getString()) != null ? _w : void 0; if (message.slider1Translation !== void 0) { message.slider1Translation = this.library.getTranslation(message.slider1Translation);