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,215 lines 124 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 config_manager_exports = {}; __export(config_manager_exports, { ConfigManager: () => ConfigManager }); module.exports = __toCommonJS(config_manager_exports); var import_Color = require("../const/Color"); var configManagerConst = __toESM(require("../const/config-manager-const")); var import_states_controller = require("../controller/states-controller"); var import_pageQR = require("../pages/pageQR"); var import_pagePower = require("../pages/pagePower"); var import_readme = require("../tools/readme"); var import_pages = require("../types/pages"); var Types = __toESM(require("../types/types")); var import_library = require("./library"); var import_navigation = require("./navigation"); class ConfigManager extends import_library.BaseClass { //private test: ConfigManager.DeviceState; colorOn = import_Color.Color.On; colorOff = import_Color.Color.Off; colorDefault = import_Color.Color.Off; dontWrite = false; extraConfigLogging = false; scriptVersion = "0.8.2"; breakingVersion = "0.6.0"; statesController; constructor(adapter, dontWrite = false) { super(adapter, "config-manager"); this.dontWrite = dontWrite; this.statesController = new import_states_controller.StatesControler(adapter); } /** * Sets the script configuration for the panel. * * @param configuration - The configuration object to set. * @returns - A promise that resolves to an array of messages indicating the result of the operation. * * This method performs the following steps: * 1. Merges the provided configuration with the default configuration. * 2. Validates the configuration. * 3. Checks if the script version meets the required version. * 4. Configures the panel settings including topic, name, and colors. * 5. Configures the screensaver and pages. * 6. Sets up navigation for the panel. * 7. Ensures unique page names and handles duplicates. * 8. Updates the adapter's foreign object with the new configuration. * * If any errors occur during the process, they are logged and included in the returned messages.. */ async setScriptConfig(configuration) { configuration.advancedOptions = Object.assign( configManagerConst.defaultConfig.advancedOptions || {}, configuration.advancedOptions || {} ); const config = Object.assign(configManagerConst.defaultConfig, configuration); if (!config || !configManagerConst.isConfig(config, this.adapter)) { this.log.error( `Invalid configuration from Script: ${config ? config.panelName || config.panelTopic || JSON.stringify(config) : "undefined"}` ); return { messages: ["Invalid configuration"], panelConfig: void 0 }; } let messages = []; this.log.info(`Start converting configuration for ${config.panelName || config.panelTopic}`); const version = config.version.split(".").map((item, i) => parseInt(item) * Math.pow(100, 2 - i)).reduce((a, b) => a + b); const requiredVersion = this.scriptVersion.split(".").map((item, i) => parseInt(item) * Math.pow(100, 2 - i)).reduce((a, b) => a + b); const breakingVersion = this.breakingVersion.split(".").map((item, i) => parseInt(item) * Math.pow(100, 2 - i)).reduce((a, b) => a + b); if (version < breakingVersion) { messages.push( `Update Script! Panel for Topic: ${config.panelTopic} - Script version ${config.version} is too low! Aborted! Required version is >=${this.breakingVersion}!` ); this.log.error(messages[messages.length - 1]); return { messages: ["Invalid configuration"], panelConfig: void 0 }; } if (version < requiredVersion) { messages.push( `Update Script! Panel for Topic: ${config.panelTopic} Script version ${config.version} is lower than the required version ${this.scriptVersion}!` ); this.log.warn(messages[messages.length - 1]); } else if (version > requiredVersion) { messages.push( `Update Adapter! Panel for Topic: ${config.panelTopic} Script version ${config.version} is higher than the required version ${this.scriptVersion}!` ); this.log.warn(messages[messages.length - 1]); } else { messages.push(`Panel for Topic: ${config.panelTopic} Script version ${config.version} is correct!`); } if (config.advancedOptions && config.advancedOptions.extraConfigLogging) { this.extraConfigLogging = true; config.advancedOptions.extraConfigLogging = false; } config.subPages = config.subPages.filter( (item) => config.pages.findIndex((item2) => item.uniqueName === item2.uniqueName) === -1 ); let panelConfig = { pages: [], navigation: [] }; if (!config.panelTopic) { this.log.error(`Required field panelTopic is missing in ${config.panelName || "unknown"}!`); messages.push("Required field panelTopic is missing"); return { messages, panelConfig: void 0 }; } panelConfig.updated = true; if (config.panelTopic.endsWith(".cmnd.CustomSend")) { panelConfig.topic = config.panelTopic.split(".").slice(0, -2).join("."); } else { panelConfig.topic = config.panelTopic; } if (config.panelName) { panelConfig.name = config.panelName; } else { panelConfig.name = `NSPanel-${config.panelTopic}`; } if (config.defaultOnColor) { this.colorOn = import_Color.Color.convertScriptRGBtoRGB(config.defaultOnColor); } if (config.defaultOffColor) { this.colorOff = import_Color.Color.convertScriptRGBtoRGB(config.defaultOffColor); } try { const screensaver = await this.getScreensaverConfig(config); if (screensaver && screensaver.config && (screensaver.config.card === "screensaver" || screensaver.config.card === "screensaver2" || screensaver.config.card === "screensaver3") && config.advancedOptions) { screensaver.config.screensaverSwipe = !!config.advancedOptions.screensaverSwipe; screensaver.config.screensaverIndicatorButtons = !!config.advancedOptions.screensaverIndicatorButtons; } panelConfig.pages.push(screensaver); } catch (error) { messages.push(`Screensaver configuration error - ${error}`); this.log.warn(messages[messages.length - 1]); } if (config.pages.length > 0) { for (let a = 0; a < config.pages.length; a++) { const page = config.pages[a]; let uniqueID = ""; if (page.type === void 0) { uniqueID = page.native.uniqueID || ""; } else { uniqueID = page.uniqueName || ""; } if (uniqueID === "") { continue; } panelConfig.navigation.push({ name: uniqueID, left: void 0, right: void 0, page: uniqueID }); } const nav = panelConfig.navigation; if (nav && nav.length > 0) { const index = nav.findIndex((item) => item.name === "main"); if (index !== -1) { const item = nav.splice(index, 1)[0]; nav.unshift(item); } } if (panelConfig.navigation.length > 1) { panelConfig.navigation = panelConfig.navigation.filter((item) => item != null); panelConfig.navigation = panelConfig.navigation.map((item, index, array) => { if (index === 0) { return { ...item, left: { single: array[array.length - 1].name }, right: { single: array[index + 1].name } }; } else if (index === array.length - 1) { return { ...item, left: { single: array[index - 1].name }, right: { single: array[0].name } }; } return { ...item, left: { single: array[index - 1].name }, right: { single: array[index + 1].name } }; }); panelConfig.navigation[panelConfig.navigation.length - 1].right = { single: "///service" }; panelConfig.navigation[0].left = { single: "///service" }; } } const names = []; let double = false; for (const page of config.pages) { if (page && page.type !== void 0) { if (names.includes(page.uniqueName)) { double = true; this.log.error(messages[messages.length - 1]); messages.push(`Abort - double uniqueName ${page.uniqueName} in config!`); } else { names.push(page.uniqueName); } } } if (double) { return { messages, panelConfig: void 0 }; } ({ panelConfig, messages } = await this.getPageConfig(config, panelConfig, messages)); const nav1 = config.navigation; const nav2 = panelConfig.navigation; if (nav1 != null && (0, import_navigation.isNavigationItemConfigArray)(nav1) && (0, import_navigation.isNavigationItemConfigArray)(nav2)) { panelConfig.navigation = nav1.concat(nav2); panelConfig.navigation = panelConfig.navigation.filter( (a, p) => a && panelConfig.navigation.findIndex((b) => b && a && b.name === a.name) === p ); } if (configManagerConst.isButton(config.buttonLeft)) { panelConfig.buttons = panelConfig.buttons || { left: null, right: null }; panelConfig.buttons.left = config.buttonLeft; } else { messages.push(`Button left wrong configured!`); this.log.warn(messages[messages.length - 1]); } if (configManagerConst.isButton(config.buttonRight)) { panelConfig.buttons = panelConfig.buttons || { left: null, right: null }; panelConfig.buttons.right = config.buttonRight; } else { messages.push(`Button right wrong configured!`); this.log.warn(messages[messages.length - 1]); } if (panelConfig.pages.length === 0) { messages.push(`No pages found! This needs to be fixed!`); this.log.error(messages[messages.length - 1]); } else if (panelConfig.navigation.length === 0) { messages.push(`No navigation items found! This needs to be fixed!`); this.log.error(messages[messages.length - 1]); } else if (panelConfig.navigation.findIndex((item) => item && item.name === "main") === -1) { messages.push(`No entry found for \u2018main\u2019 in the navigation!`); this.log.warn(messages[messages.length - 1]); } const obj = await this.adapter.getForeignObjectAsync(this.adapter.namespace); if (obj && !this.dontWrite) { if (!obj.native.scriptConfigRaw || !Array.isArray(obj.native.scriptConfigRaw)) { obj.native.scriptConfigRaw = []; } obj.native.scriptConfigRaw = obj.native.scriptConfigRaw.filter( (item, i) => obj.native.scriptConfigRaw.findIndex((item2) => item2.panelTopic === item.panelTopic) === i ); obj.native.scriptConfigRaw = obj.native.scriptConfigRaw.filter( (item) => item.panelTopic !== configuration.panelTopic ); obj.native.scriptConfigRaw = obj.native.scriptConfigRaw.filter( (item) => this.adapter.config.panels.findIndex((a) => a.topic === item.panelTopic) !== -1 ); obj.native.scriptConfig = obj.native.scriptConfig || []; obj.native.scriptConfig = obj.native.scriptConfig.filter( (item, i) => obj.native.scriptConfig.findIndex((item2) => item2.topic === item.topic) === i ); obj.native.scriptConfig = obj.native.scriptConfig.filter((item) => item.topic !== panelConfig.topic); obj.native.scriptConfig = obj.native.scriptConfig.filter( (item) => this.adapter.config.panels.findIndex((a) => a.topic === item.topic) !== -1 ); obj.native.scriptConfigRaw.push(configuration); obj.native.scriptConfig.push(panelConfig); await this.adapter.setForeignObjectAsync(this.adapter.namespace, obj); } messages.push(`done`); return { messages: messages.map((a) => a.replaceAll("Error: ", "")), panelConfig }; } async getPageConfig(config, panelConfig, messages) { if (panelConfig.pages === void 0) { panelConfig.pages = []; } if (config.pages) { for (const page of config.pages.concat(config.subPages || [])) { if (!page) { continue; } if (page.type === void 0 && page.native) { if ((config.subPages || []).includes(page)) { const left = page.prev || page.parent || void 0; const right = page.next || page.home || void 0; if (left || right) { const navItem = { name: page.native.uniqueID || "", left: left ? page.prev ? { single: left } : { double: left } : void 0, right: right ? page.next ? { single: right } : { double: right } : void 0, page: page.native.uniqueID }; panelConfig.navigation.push(navItem); } else { const msg = `Page: ${page.native.uniqueID || "unknown"} dont have any navigation!`; messages.push(msg); continue; } } if (page.heading) { page.native.config = page.native.config || {}; page.native.config.data = page.native.config.data || {}; page.native.config.data.headline = await this.getFieldAsDataItemConfig(page.heading); } panelConfig.pages.push(page.native); continue; } if (page.type !== "cardGrid" && page.type !== "cardGrid2" && page.type !== "cardGrid3" && page.type !== "cardEntities" && page.type !== "cardThermo" && page.type !== "cardQR" && page.type !== "cardPower") { const msg = `${page.heading || "unknown"} with card type ${page.type} not implemented yet!..`; messages.push(msg); this.log.warn(msg); continue; } if (!page.uniqueName) { messages.push( `Page ${"heading" in page && page.heading ? page.heading : page.type || "unknown"} has no uniqueName!` ); this.log.error(messages[messages.length - 1]); continue; } if ((config.subPages || []).includes(page)) { const left = page.prev || page.parent || void 0; let right = page.next || page.home || void 0; if (!left && !right) { const msg = `Page: ${page.uniqueName} dont have any navigation! Node 'main' provisionally added as home!`; messages.push(msg); this.log.warn(msg); page.home = "main"; right = page.home; } if (left || right) { const navItem = { name: page.uniqueName, left: left ? page.prev ? { single: left } : { double: left } : void 0, right: right ? page.next ? { single: right } : { double: right } : void 0, page: page.uniqueName }; panelConfig.navigation.push(navItem); } } if (page.type === "cardQR") { if (!Array.isArray(this.adapter.config.pageQRdata)) { messages.push(`No pageQR configured in Admin for ${page.uniqueName}`); this.log.warn(messages[messages.length - 1]); continue; } const index = this.adapter.config.pageQRdata.findIndex((item) => item.pageName === page.uniqueName); if (index === -1) { messages.push(`No pageQRdata found for ${page.uniqueName}`); this.log.warn(messages[messages.length - 1]); continue; } panelConfig.pages.push(await import_pageQR.PageQR.getQRPageConfig(this.adapter, index, this)); continue; } if (page.type === "cardPower") { if (!Array.isArray(this.adapter.config.pagePowerdata)) { messages.push(`No pagePower configured in Admin for ${page.uniqueName}`); this.log.warn(messages[messages.length - 1]); continue; } const index = this.adapter.config.pagePowerdata.findIndex( (item) => item.pageName === page.uniqueName ); if (index === -1) { messages.push(`No pagePowerdata found for ${page.uniqueName}`); this.log.warn(messages[messages.length - 1]); continue; } panelConfig.pages.push(await import_pagePower.PagePower.getPowerPageConfig(this.adapter, index, this)); continue; } let gridItem = { dpInit: "", alwaysOn: page.alwaysOnDisplay ? typeof page.alwaysOnDisplay === "boolean" ? "always" : "action" : "none", uniqueID: page.uniqueName || "", useColor: false, config: { card: page.type, data: { headline: await this.getFieldAsDataItemConfig(page.heading || "") } }, pageItems: [] }; if (gridItem.config.card === "cardGrid" || gridItem.config.card === "cardGrid2" || gridItem.config.card === "cardGrid3" || gridItem.config.card === "cardEntities") { gridItem.config.scrollType = "page"; } try { if (page.type === "cardThermo") { ({ gridItem, messages } = await this.getPageThermo(page, gridItem, messages)); } } catch (error) { messages.push( `Configuration error in page ${page.heading || "unknown"} with uniqueName ${page.uniqueName} - ${error}` ); this.log.warn(messages[messages.length - 1]); continue; } if (page.items) { for (let a = 0; a < page.items.length; a++) { const item = page.items[a]; if (!item) { continue; } if (page.type === "cardThermo" && a === 0) { continue; } try { const temp = await this.getPageItemConfig(item, page, messages); const itemConfig = temp.itemConfig; messages = temp.messages; if (itemConfig && gridItem.pageItems) { gridItem.pageItems.push(itemConfig); } } catch (error) { messages.push( `Configuration error in page ${page.heading || "unknown"} with uniqueName ${page.uniqueName} - ${error}` ); this.log.warn(messages[messages.length - 1]); } } panelConfig.pages.push(gridItem); } } } return { panelConfig, messages }; } async getPageThermo(page, gridItem, messages) { var _a, _b, _c, _d, _e, _f, _g; if (page.type !== "cardThermo" || !gridItem.config || gridItem.config.card !== "cardThermo") { return { gridItem, messages }; } if (!page.items || !page.items[0]) { const msg = `${page.uniqueName}: Thermo page has no item or item 0 has no id!`; messages.push(msg); this.log.warn(msg); return { gridItem, messages }; } const item = page.items[0]; if (!item || !item.id || item.id.endsWith(".")) { const msg = `${page.uniqueName} id: ${page.items[0].id} is invalid!`; messages.push(msg); this.log.error(msg); return { gridItem, messages }; } const o = await this.adapter.getForeignObjectAsync(item.id); if (!o || !o.common || !o.common.role) { const msg = `${page.uniqueName} id: ${page.items[0].id} has a invalid object!`; messages.push(msg); this.log.error(msg); return { gridItem, messages }; } const role = o.common.role; if (role !== "thermostat" && role !== "airCondition") { const msg = `${page.uniqueName} id: ${page.items[0].id} role '${role}' not supported for cardThermo!`; messages.push(msg); this.log.error(msg); return { gridItem, messages }; } let foundedStates; try { foundedStates = await this.searchDatapointsForItems( configManagerConst.requiredScriptDataPoints, role, item.id, messages ); } catch { return { gridItem, messages }; } gridItem.dpInit = item.id; gridItem = { ...gridItem, card: "cardThermo", alwaysOn: "none", useColor: false, items: void 0, config: { card: "cardThermo", data: { headline: await this.getFieldAsDataItemConfig(page.heading || "thermostat"), mixed1: { value: { type: "const", constVal: "Temperature" } }, mixed2: foundedStates[role].ACTUAL ? { value: foundedStates[role].ACTUAL, factor: { type: "const", constVal: 1 }, decimal: { type: "const", constVal: 1 }, unit: item.unit != null ? await this.getFieldAsDataItemConfig(item.unit) : void 0 } : void 0, mixed3: foundedStates[role].HUMIDITY ? { value: { type: "const", constVal: "Humidity" } } : void 0, mixed4: foundedStates[role].HUMIDITY ? { value: foundedStates[role].HUMIDITY, factor: { type: "const", constVal: 1 }, decimal: { type: "const", constVal: 0 }, unit: { type: "const", constVal: "%" } } : void 0, tempStep: item.stepValue != null ? await this.getFieldAsDataItemConfig(item.stepValue) : void 0, minTemp: item.minValue != null ? await this.getFieldAsDataItemConfig(item.minValue) : void 0, maxTemp: item.maxValue != null ? await this.getFieldAsDataItemConfig(item.maxValue) : void 0, unit: item.unit != null ? await this.getFieldAsDataItemConfig(item.unit) : void 0, set1: foundedStates[role].SET, set2: role === "airCondition" ? foundedStates[role].SET2 : void 0 } }, pageItems: [] }; gridItem.pageItems = gridItem.pageItems || []; if (role === "thermostat" || role === "airCondition" && !foundedStates[role].MODE) { if (foundedStates[role].AUTOMATIC && !foundedStates[role].MANUAL) { foundedStates[role].MANUAL = JSON.parse(JSON.stringify(foundedStates[role].AUTOMATIC)); if (foundedStates[role].MANUAL.type === "triggered") { foundedStates[role].MANUAL.read = "return !val"; foundedStates[role].MANUAL.write = "return !val"; } } else if (!foundedStates[role].AUTOMATIC && foundedStates[role].MANUAL) { foundedStates[role].AUTOMATIC = JSON.parse(JSON.stringify(foundedStates[role].MANUAL)); if (foundedStates[role].AUTOMATIC.type === "triggered") { foundedStates[role].AUTOMATIC.read = "return !val"; foundedStates[role].AUTOMATIC.write = "return !val"; } } if (foundedStates[role].AUTOMATIC) { gridItem.pageItems.push({ role: "button", type: "button", dpInit: "", data: { icon: { true: { value: { type: "const", constVal: "alpha-a-circle" }, color: { type: "const", constVal: import_Color.Color.activated } }, false: { value: { type: "const", constVal: "alpha-a-circle-outline" }, color: { type: "const", constVal: import_Color.Color.deactivated } } }, entity1: { value: foundedStates[role].AUTOMATIC, set: foundedStates[role].AUTOMATIC } } }); } if (foundedStates[role].MANUAL) { gridItem.pageItems.push({ role: "button", type: "button", dpInit: "", data: { icon: { true: { value: { type: "const", constVal: "alpha-m-circle" }, color: { type: "const", constVal: import_Color.Color.activated } }, false: { value: { type: "const", constVal: "alpha-m-circle-outline" }, color: { type: "const", constVal: import_Color.Color.deactivated } } }, entity1: { value: foundedStates[role].MANUAL, set: foundedStates[role].MANUAL } } }); } if (foundedStates[role].OFF) { gridItem.pageItems.push({ role: "button", type: "button", dpInit: "", data: { icon: { true: { value: { type: "const", constVal: "power-off" }, color: { type: "const", constVal: import_Color.Color.activated } }, false: { value: { type: "const", constVal: "power-off" }, color: { type: "const", constVal: import_Color.Color.deactivated } } }, entity1: { value: foundedStates[role].OFF, set: foundedStates[role].OFF } } }); } } else if ((_a = foundedStates[role]) == null ? void 0 : _a.MODE) { let states = ["OFF", "AUTO", "COOL", "HEAT", "ECO", "FAN", "DRY"]; if (foundedStates[role].MODE.dp) { const o2 = await this.adapter.getForeignObjectAsync(foundedStates[role].MODE.dp); if ((_b = o2 == null ? void 0 : o2.common) == null ? void 0 : _b.states) { states = o2.common.states; } } const tempItem = { role: "button", type: "button", dpInit: "", data: { icon: { true: { value: { type: "const", constVal: "power-off" }, color: { type: "const", constVal: import_Color.Color.activated } }, false: { value: void 0, color: { type: "const", constVal: import_Color.Color.deactivated } } }, entity1: { value: { ...foundedStates[role].MODE, read: `return val == index}` }, set: { ...foundedStates[role].MODE, write: `return index}` } } } }; if (((_d = (_c = tempItem == null ? void 0 : tempItem.data) == null ? void 0 : _c.icon) == null ? void 0 : _d.true) && ((_f = (_e = tempItem == null ? void 0 : tempItem.data) == null ? void 0 : _e.icon) == null ? void 0 : _f.false) && ((_g = tempItem == null ? void 0 : tempItem.data) == null ? void 0 : _g.entity1)) { let index = typeof states == "object" ? Array.isArray(states) ? states.findIndex((item2) => item2 === "OFF") : states.OFF !== void 0 ? "OFF" : -1 : -1; if (index != -1) { tempItem.data.icon.true.value = { type: "const", constVal: "power-off" }; tempItem.data.entity1.value = { ...foundedStates[role].MODE, read: `return val == ${index}` }; tempItem.data.entity1.set = { ...foundedStates[role].MODE, write: `return ${index}` }; gridItem.pageItems.push(JSON.parse(JSON.stringify(tempItem))); } index = typeof states == "object" ? Array.isArray(states) ? states.findIndex((item2) => item2 === "AUTO") : states.AUTO !== void 0 ? "AUTO" : -1 : -1; if (index != -1) { tempItem.data.icon.true.value = { type: "const", constVal: "alpha-a-circle" }; tempItem.data.icon.false.value = { type: "const", constVal: "alpha-a-circle-outline" }; tempItem.data.entity1.value = { ...foundedStates[role].MODE, read: `return val == ${index}` }; tempItem.data.entity1.set = { ...foundedStates[role].MODE, write: `return ${index}` }; gridItem.pageItems.push(JSON.parse(JSON.stringify(tempItem))); } index = typeof states == "object" ? Array.isArray(states) ? states.findIndex((item2) => item2 === "COOL") : states.COOL !== void 0 ? "COOL" : -1 : -1; if (index != -1) { tempItem.data.icon.true.value = { type: "const", constVal: "snowflake" }; tempItem.data.entity1.value = { ...foundedStates[role].MODE, read: `return val == ${index}` }; tempItem.data.entity1.set = { ...foundedStates[role].MODE, write: `return ${index}` }; gridItem.pageItems.push(JSON.parse(JSON.stringify(tempItem))); } let token = "HEAT"; index = typeof states == "object" ? Array.isArray(states) ? states.findIndex((item2) => item2 === token) : states[token] !== void 0 ? token : -1 : -1; if (index != -1) { tempItem.data.icon.true.value = { type: "const", constVal: "fire" }; tempItem.data.entity1.value = { ...foundedStates[role].MODE, read: `return val == ${index}` }; tempItem.data.entity1.set = { ...foundedStates[role].MODE, write: `return ${index}` }; gridItem.pageItems.push(JSON.parse(JSON.stringify(tempItem))); } token = "ECO"; index = typeof states == "object" ? Array.isArray(states) ? states.findIndex((item2) => item2 === token) : states[token] !== void 0 ? token : -1 : -1; if (index != -1) { tempItem.data.icon.true.value = { type: "const", constVal: "alpha-e-circle-outline" }; tempItem.data.entity1.value = { ...foundedStates[role].MODE, read: `return val == ${index}` }; tempItem.data.entity1.set = { ...foundedStates[role].MODE, write: `return ${index}` }; gridItem.pageItems.push(JSON.parse(JSON.stringify(tempItem))); } token = "FAN_ONLY"; index = typeof states == "object" ? Array.isArray(states) ? states.findIndex((item2) => item2 === token) : states[token] !== void 0 ? token : -1 : -1; if (index != -1) { tempItem.data.icon.true.value = { type: "const", constVal: "fan" }; tempItem.data.entity1.value = { ...foundedStates[role].MODE, read: `return val == ${index}` }; tempItem.data.entity1.set = { ...foundedStates[role].MODE, write: `return ${index}` }; gridItem.pageItems.push(JSON.parse(JSON.stringify(tempItem))); } token = "DRY"; index = typeof states == "object" ? Array.isArray(states) ? states.findIndex((item2) => item2 === token) : states[token] !== void 0 ? token : -1 : -1; if (index != -1) { tempItem.data.icon.true.value = { type: "const", constVal: "water-percent" }; tempItem.data.entity1.value = { ...foundedStates[role].MODE, read: `return val == ${index}` }; tempItem.data.entity1.set = { ...foundedStates[role].MODE, write: `return ${index}` }; gridItem.pageItems.push(JSON.parse(JSON.stringify(tempItem))); } } } if (foundedStates[role].POWER) { gridItem.pageItems.push({ role: "button", type: "button", dpInit: "", data: { icon: { true: { value: { type: "const", constVal: "power-standby" }, color: { type: "const", constVal: import_Color.Color.activated } }, false: { value: { type: "const", constVal: "power-standby" }, color: { type: "const", constVal: import_Color.Color.deactivated } } }, entity1: { value: foundedStates[role].POWER, set: foundedStates[role].POWER } } }); } if (foundedStates[role].BOOST) { gridItem.pageItems.push({ role: "button", type: "button", dpInit: "", data: { icon: { true: { value: { type: "const", constVal: "fast-forward-60" }, color: { type: "const", constVal: import_Color.Color.activated } }, false: { value: { type: "const", constVal: "fast-forward-60" }, color: { type: "const", constVal: import_Color.Color.deactivated } } }, entity1: { value: foundedStates[role].BOOST, set: foundedStates[role].BOOST } } }); } if (foundedStates[role].WINDOWOPEN) { gridItem.pageItems.push({ role: "indicator", type: "button", dpInit: "", data: { icon: { true: { value: { type: "const", constVal: "window-open-variant" }, color: { type: "const", constVal: import_Color.Color.open } }, false: { value: { type: "const", constVal: "window-closed-variant" }, color: { type: "const", constVal: import_Color.Color.close } } }, entity1: { value: foundedStates[role].WINDOWOPEN } } }); } if (foundedStates[role].PARTY) { gridItem.pageItems.push({ role: "button", type: "button", dpInit: "", data: { icon: { true: { value: { type: "const", constVal: "party-popper" }, color: { type: "const", constVal: import_Color.Color.activated } }, false: { value: { type: "const", constVal: "party-popper" }, color: { type: "const", constVal: import_Color.Color.deactivated } } }, entity1: { value: foundedStates[role].PARTY, set: foundedStates[role].PARTY } } }); } if (foundedStates[role].MAINTAIN) { gridItem.pageItems.push({ role: "indicator", type: "button", dpInit: "", data: { icon: { true: { value: { type: "const", constVal: "account-wrench" }, color: { type: "const", constVal: import_Color.Color.bad } }, false: { value: { type: "const", constVal: "account-wrench" }, color: { type: "const", constVal: import_Color.Color.deactivated } } }, entity1: { value: foundedStates[role].MAINTAIN } } }); } if (foundedStates[role].UNREACH) { gridItem.pageItems.push({ role: "indicator", type: "button", dpInit: "", data: { icon: { true: { value: { type: "const", constVal: "wifi-off" }, color: { type: "const", constVal: import_Color.Color.bad } }, false: { value: { type: "const", constVal: "wifi" }, color: { type: "const", constVal: import_Color.Color.good } } }, entity1: { value: foundedStates[role].UNREACH } } }); } if (foundedStates[role].MAINTAIN) { gridItem.pageItems.push({ role: "indicator", type: "button", dpInit: "", data: { icon: { true: { value: { type: "const", constVal: "account-wrench" }, color: { type: "const", constVal: import_Color.Color.true } }, false: { value: { type: "const", constVal: "account-wrench" }, color: { type: "const", constVal: import_Color.Color.deactivated } } }, entity1: { value: foundedStates[role].MAINTAIN } } }); } if (foundedStates[role].LOWBAT) { gridItem.pageItems.push({ role: "indicator", type: "button", dpInit: "", data: { icon: { true: { value: { type: "const", constVal: "battery-low" }, color: { type: "const", constVal: import_Color.Color.bad } }, false: { value: { type: "const", constVal: "battery-high" }, color: { type: "const", constVal: import_Color.Color.good } } }, entity1: { value: foundedStates[role].LOWBAT } } }); } if (foundedStates[role].ERROR) { gridItem.pageItems.push({ role: "indicator", type: "button", dpInit: "", data: { icon: { true: { value: { type: "const", constVal: "alert-circle" }, color: { type: "const", constVal: import_Color.Color.bad } }, false: { value: { type: "const", constVal: "alert-circle" }, color: { type: "const", constVal: import_Color.Color.deactivated } } }, entity1: { value: foundedStates[role].ERROR } } }); } if (foundedStates[role].VACATION) { gridItem.pageItems.push({ role: "indicator", type: "button", dpInit: "", data: { icon: { true: { value: { type: "const", constVal: "palm-tree" }, color: { type: "const", constVal: import_Color.Color.activated } }, false: { value: { type: "const", constVal: "palm-tree" }, color: { type: "const", constVal: import_Color.Color.deactivated } } }, entity1: { value: foundedStates[role].VACATION } } }); } if (foundedStates[role].WORKING) { gridItem.pageItems.push({ role: "indicator", type: "button", dpInit: "", data: { icon: { true: { value: { type: "const", constVal: "briefcase-check" }, color: { type: "const", constVal: import_Color.Color.activated } }, false: { value: { type: "const", constVal: "briefcase-check" }, color: { type: "const", constVal: import_Color.Color.deactivated } } }, entity1: { value: foundedStates[role].WORKING } } }); } if (item.setThermoAlias) { if (item.popupThermoMode1 && item.setThermoAlias[0] && await this.existsState(item.setThermoAlias[0])) { gridItem.pageItems.push({ role: "", type: "input_sel", dpInit: "", data: { entityInSel: { value: { type: "triggered", dp: item.setThermoAlias[0] } }, color: { true: await this.getIconColor(item.onColor, this.colorOn), false: await this.getIconColor(item.onColor, this.colorOn) }, headline: item.name ? await this.getFieldAsDataItemConfig(item.name) : void 0, valueList: { type: "const", constVal: item.popupThermoMode1 } } }); } if (item.popupThermoMode2 && item.setThermoAlias[1] && await this.existsState(item.setThermoAlias[1])) { gridItem.pageItems.push({ role: "", type: "input_sel", dpInit: "", data: { entityInSel: { value: { type: "triggered", dp: item.setThermoAlias[1] } }, color: { true: await this.getIconColor(item.onColor, this.colorOn), false: await this.getIconColor(item.onColor, this.colorOn) }, headline: item.name ? await this.getFieldAsDataItemConfig(item.name) : void 0, valueList: { type: "const", constVal: item.popupThermoMode2 } } }); } if (item.popupThermoMode3 && item.setThermoAlias[2] && await this.existsState(item.setThermoAlias[2])) { gridItem.pageItems.push({ role: "", type: "input_sel", dpInit: "", data: { entityInSel: { value: { type: "triggered", dp: item.setThermoAlias[2] } }, color: { true: await this.getIconColor(item.onColor, this.colorOn), false: await this.getIconColor(item.onColor, this.colorOn) }, headline: item.name ? await this.getFieldAsDataItemConfig(item.name) : void 0, valueList: { type: "const", constVal: item.popupThermoMode3 } } }); } } return { gridItem, messages }; } async getPageNaviItemConfig(item, page) { var _a, _b; if (!(page.type === "cardGrid" || page.type === "cardGrid2" || page.type === "cardGrid3" || page.type === "cardEntities") || !item.targetPage || !item.navigate) { this.log.warn(`Page type ${page.type} not supported for navigation item!`); return void 0; } let itemConfig = void 0; const specialRole = page.type === "cardGrid" || page.type === "cardGrid2" || page.type === "cardGrid3" ? "textNotIcon" : "iconNotText"; const obj = item.id && !item.id.endsWith(".") ? await this.adapter.getForeignObjectAsync(item.id) : void 0; if (obj && (!obj.common || !obj.common.role)) { throw new Error(`Role missing in ${page.uniqueName}.${item.id}!`); } const role = obj ? obj.common.role : null; const commonName = obj && obj.common ? typeof obj.common.name === "string" ? obj.common.name : obj.common.name[this.library.getLocalLanguage()] : void 0; const getButtonsTextTrue = async (item2, def1) => { return item2.buttonText ? await this.getFieldAsDataItemConfig(item2.buttonText) : await this.existsState(`${item2.id}.BUTTONTEXT`) ? { type: "triggered", dp: `${item2.id}.BUTTONTEXT` } : await this.getFieldAsDataItemConfig(item2.name || commonName || def1); }; const getButtonsTextFalse = async (item2, def1 = "") => { return item2.buttonTextOff ? await this.getFieldAsDataItemConfig(item2.buttonTextOff) : await this.existsState(`${item2.id}.BUTTONTEXTOFF`) ? { type: "triggered", dp: `${item2.id}.BUTTONTEXTOFF` } : item2.buttonText ? await this.getFieldAsDataItemConfig(item2.buttonText) : await this.existsState(`${item2.id}.BUTTONTEXT`) ? { type: "triggered", dp: `${item2.id}.BUTTONTEXT` } : await this.getFieldAsDataItemConfig(item2.name || commonName || def1); }; const text = { true: await getButtonsTextTrue(item, role || ""), false: await getButtonsTextFalse(item, role || ""), textSize: item.fontSize ? { type: "const", constVal: item.fontSize } : void 0, prefix: item.prefixName ? await this.getFieldAsDataItemConfig(item.prefixName) : void 0, suffix: item.suffixName ? await this.getFieldAsDataItemConfig(item.suffixName) : void 0 }; if (!item.id) { return { type: "button", data: { setNavi: item.targetPage ? await this.getFieldAsDataItemConfig(item.targetPage) : void 0, icon: { true: { value: { type: "const", constVal: item.icon || "gesture-tap-button" }, color: await this.getIconColor(item.onColor, this.colorOn) }, scale: Types.isIconColorScaleElement(item.colorScale) ? { type: "const", constVal: item.colorScale } : void 0, maxBri: void 0, minBri: void 0 }, text1: { true: { type: "const", constVal: "press" } }, text } }; } if (obj && (!obj.common || !obj.common.role) || role == null) { throw new Error(`Role missing in ${page.uniqueName}.${item.id}!`); } if (!configManagerConst.requiredScriptDataPoints[role]) { this.log.warn(`Channel role ${role} not supported!`); throw new Error(`Channel role ${role} not supported!`); } const foundedStates = await this.searchDatapointsForItems( configManagerConst.requiredScriptDataPoints, role, item.id, [] ); switch (role) { case "socket": { let icon; let icon2; if (item.role) { switch (item.role) { case "socket": { icon = "power-socket-de"; icon2 = "power-socket-de"; break; } } } icon = item.icon || icon || "power"; icon2 = item.icon2 || icon2 || icon || "power-standby"; const tempItem = { type: "button", role: "button", data: { icon: { true: { value: { type: "const", constVal: icon }, color: await this.getIconColor(item.onColor, this.colorOn) }, false: { value: { type: "const", constVal: icon2 }, color: await this.getIconColor(item.offColor, this.colorOff) }, scale: Types.isIconColorScaleElement(item.colorScale) ? { type: "const", constVal: item.colorScale } : void 0, maxBri: void 0, minBri: void 0 }, text1: { true: { type: "const", constVal: "on" }, false: { type: "const", constVal: "off" } }, text, entity1: { value: foundedStates[role].ACTUAL }, setNavi: item.targetPage ? await this.getFieldAsDataItemConfig(item.targetPage) : void 0 } }; itemConfig = tempItem; break; } case "light": case "dimmer": case "hue": case "rgb": case "rgbSingle": case "ct": { const tempItem = { type: "button", role: role === "rgb" ? "rgbThree" : role, data: { icon: { true: { value: { type: "const", constVal: item.icon || "lightbulb" }, color: await this.getIconColor(item.onColor, this.colorOn) }, false: { value: { type: "const", constVal: item.icon2 || item.icon || "lightbulb-outline" }, color: await this.getIconColor(item.offColor, this.colorOff) }, scale: Types.isIconColorScaleElement(item.colorScale) ? { type: "const", constVal: item.colorScale } : void 0, maxBri: void 0, minBri: void 0 }, text1: { true: { type: "const", constVal: "on" }, false: { type: "const", constVal: "off" } }, text, entity1: role === "dimmer" || role == "hue" ? { value: foundedStates[role].ON_ACTUAL } : { value: foundedStates[role].ACTUAL }, setNavi: item.targetPage ? await this.getFieldAsDataItemConfig(item.targetPage) : void 0 } }; itemConfig = tempItem; break; } case void 0: case "button": { const tempItem = { type: "button", role: "button", data: { icon: { true: { value: { type: "const", constVal: item.icon || "gesture-tap-button" }, color: await this.getIconColor(item.onColor, this.colorOn) }, false: { value: { type: "const", constVal: item.icon2 || item.icon || "gesture-tap-button" }, color: await this.getIconColor(item.offColor, this.colorOff) }, scale: Types.isIconColorScaleElement(item.colorScale) ? { type: "const", constVal: item.colorScale } : void 0, maxBri: void 0, minBri: void 0 }, text1: { true: { type: "const", constVal: "on" }, false: { type: "const", constVal: "off" } }, text, entity1: { value: foundedStates[role].ACTUAL }, setNavi: item.targetPage ? await this.getFieldAsDataItemConfig(item.targetPage) : void 0 } }; itemConfig = tempItem; break; } case "value.humidity": case "humidity": { let commonUnit = ""; if (foundedStates[role].ACTUAL && foundedStates[role].ACTUAL.dp) { const o = await this.adapter.getForeignObjectAsync(foundedStates[role].ACTUAL.dp); if (o && o.common && o.common.unit) { commonUnit = o.common.unit; } } itemConfig = { type: "button", dpInit: item.id, role: specialRole, template: "button.humidity", data: { entity1: { value: foundedStates[role].ACTUAL, unit: item.unit || commonUnit ? { type: "const", constVal: item.unit || commonUnit } : void 0 }, icon: { true: { value: item.icon ? { type: "const", constVal: item.icon } : void 0, color: await this.getIco