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,130 lines 204 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_pagePower = require("../pages/pagePower"); var import_pageChart = require("../pages/pageChart"); var import_readme = require("../tools/readme"); var globals = __toESM(require("../types/function-and-const")); var import_function_and_const = require("../types/function-and-const"); var import_library = require("../controller/library"); var import_navigation = require("./navigation"); var fs = __toESM(require("fs")); var import_path = __toESM(require("path")); var import_pageThermo2 = require("../pages/pageThermo2"); var import_pageMedia = require("../pages/pageMedia"); var import_type_pageItem = require("../types/type-pageItem"); var import_tools = require("../const/tools"); class ConfigManager extends import_library.BaseClass { //private test: ConfigManager.DeviceState; //colorOn: RGB = Color.On; //colorOff: RGB = Color.Off; colorDefault = import_Color.Color.Off; dontWrite = false; extraConfigLogging = false; 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) { if (!configuration || typeof configuration !== "object") { this.log.error(`Invalid configuration from Script: ${configuration || "undefined"}`); return { messages: ["Abort: Invalid configuration"], panelConfig: void 0 }; } if (configManagerConst.isGlobalConfig(configuration)) { let panelConfig2 = { pages: [], navigation: [], scriptVersion: "" }; let messages2 = []; const tempConfig = { ...configuration, pages: [] }; ({ panelConfig: panelConfig2, messages: messages2 } = await this.getPageConfig(tempConfig, panelConfig2, messages2)); const obj2 = await this.adapter.getForeignObjectAsync(this.adapter.namespace); if (obj2 && !this.dontWrite) { obj2.native = obj2.native || {}; obj2.native.globalConfigRaw = configuration; await this.adapter.setForeignObject(this.adapter.namespace, obj2); } messages2.push(`done`); return { messages: messages2.map((a) => a.replaceAll("Error: ", "")), panelConfig: panelConfig2 }; } configuration.advancedOptions = { ...configManagerConst.defaultConfig.advancedOptions || {}, ...configuration.advancedOptions || {} }; const config = { ...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: ["Abort: Invalid configuration"], panelConfig: void 0 }; } const panelItem = this.adapter.config.panels.find((item) => item.topic === config.panelTopic); if (!panelItem) { this.log.error(`Panel for Topic: ${config.panelTopic} not found in adapter config!`); return { messages: [ `Abort: Topic: ${config.panelTopic} not found in Adapter configuration! Maybe wrong topic?!` ], panelConfig: void 0 }; } let messages = []; this.log.debug(`Start converting configuration for ${config.panelName || config.panelTopic}`); let file = void 0; if (fs.existsSync(import_path.default.join(__dirname, "../../script"))) { file = fs.readFileSync(import_path.default.join(__dirname, "../../script/example_sendTo_script_iobroker.ts"), "utf8"); } const vTemp = (file == null ? void 0 : file.match(/const.version.+'(\d\.\d\.\d)';/)) || []; const scriptVersion = vTemp[1] ? vTemp[1] : ""; const version = (0, import_tools.getVersionAsNumber)(config.version); const requiredVersion = (0, import_tools.getVersionAsNumber)(scriptVersion); const breakingVersion = (0, import_tools.getVersionAsNumber)(this.breakingVersion); if (version < breakingVersion) { messages.push( `Update Script! Panel for Topic: ${config.panelTopic} - name: ${panelItem.name} Script version ${config.version} is too low! Aborted! Required version is >=${this.breakingVersion}!` ); this.log.error(messages[messages.length - 1]); return { messages, panelConfig: void 0 }; } if (version < requiredVersion) { messages.push( `Update Script! Panel for Topic: ${config.panelTopic} name: ${panelItem.name} Script version ${config.version} is lower than the required version ${scriptVersion}!` ); this.log.warn(messages[messages.length - 1]); } else if (version > requiredVersion) { messages.push( `Update Adapter! Panel for Topic: ${config.panelTopic} name: ${panelItem.name} Script version ${config.version} is higher than the required version ${scriptVersion}!` ); this.log.warn(messages[messages.length - 1]); } else { messages.push( `Panel for Topic: ${config.panelTopic} name: ${panelItem.name} Script version ${config.version} is correct!` ); } { const navigationAdjustRun = (oldUniqueName, newUniqueName, pages, renamedPages, maxRun = 3, indexRun = 0, runPrefix = "") => { if (!oldUniqueName || !newUniqueName || oldUniqueName === newUniqueName) { return pages; } if (indexRun++ > maxRun) { this.log.warn( `navigationAdjustRun for ${oldUniqueName} to ${newUniqueName} aborted - maxRun ${maxRun} reached!` ); return pages; } const pageIndex = pages.findIndex((item) => item.uniqueName === oldUniqueName); if (pageIndex === -1) { return pages; } let page = pages[pageIndex]; if (!page) { return pages; } renamedPages[oldUniqueName] = newUniqueName; page = { ...structuredClone(page), uniqueName: newUniqueName }; pages.push(page); if ("items" in page && page.items) { for (let i = 0; i < page.items.length; i++) { const item = page.items[i]; if (item && item.navigate && item.targetPage) { const origin = item.targetPage; for (const key in renamedPages) { const value = renamedPages[key]; if (origin === value) { item.targetPage = value; continue; } } if (renamedPages[item.targetPage]) { item.targetPage = renamedPages[item.targetPage]; continue; } const newName = `${runPrefix}_${item.targetPage}_copy_nav_${Math.floor(Math.random() * 1e5)}`; if (pages.findIndex((it) => it.uniqueName === newName) === -1) { pages = navigationAdjustRun( item.targetPage, newName, pages, renamedPages, maxRun, indexRun, runPrefix ); } item.targetPage = newName; } } } for (const t of ["next", "prev", "home", "parent"]) { const tag = t; if (page[tag] === oldUniqueName) { for (const key in renamedPages) { const value = renamedPages[key]; if (page[tag] === value) { continue; } } if (renamedPages[page[tag]]) { page[tag] = renamedPages[page[tag]]; continue; } const newName = `${runPrefix}_${page[tag]}_copy_nav_${Math.floor(Math.random() * 1e5)}`; if (pages.findIndex((it) => it.uniqueName === newName) === -1) { pages = navigationAdjustRun( page[tag], newName, pages, renamedPages, maxRun, indexRun, runPrefix ); } page[tag] = newName; } } return pages; }; const obj2 = await this.adapter.getForeignObjectAsync(this.adapter.namespace); if (obj2 && obj2.native && obj2.native.globalConfigRaw) { const globalConfig = obj2.native.globalConfigRaw; if (globalConfig && configManagerConst.isGlobalConfig(globalConfig)) { globalConfig.maxNavigationAdjustRuns = globalConfig.maxNavigationAdjustRuns && globalConfig.maxNavigationAdjustRuns > 0 ? globalConfig.maxNavigationAdjustRuns : 3; const removeGlobalPageIndexs = /* @__PURE__ */ new Set(); for (let i = 0; i < config.pages.length; i++) { const page = config.pages[i]; if (page && "globalLink" in page && page.globalLink) { const gIndex = globalConfig.subPages.findIndex((item) => item.uniqueName === page.globalLink); const gPage = gIndex !== -1 ? globalConfig.subPages[gIndex] : void 0; if (gPage) { for (const t of ["next", "prev"]) { const tag = t; if (gPage[tag] != null) { const gIndex2 = globalConfig.subPages.findIndex( (item) => item.uniqueName === gPage[tag] ); const index = config.pages.findIndex( (item) => "globalLink" in item && item.globalLink === gPage[tag] || item.uniqueName === gPage[tag] ); if (gIndex2 !== -1 && index === -1) { let msg = `Global page ${gPage.uniqueName} ${tag} link to subPage ${gPage[tag]}. `; if (tag === "next") { msg += `Remove ${gPage[tag]} from subPages and add to pages at index ${i + 1}!`; } else { msg += `This is not recommended! Prev navigation will "randomly" change the order of pages! Consider to remove it!`; } messages.push(msg); config.pages.splice(i + 1, 0, { globalLink: gPage[tag] }); } } } } } } for (let i = config.pages.length - 1; i >= 0; i--) { const page = config.pages[i]; if (page && "globalLink" in page && page.globalLink) { const gIndex = globalConfig.subPages.findIndex((item) => item.uniqueName === page.globalLink); let gPage = gIndex !== -1 ? globalConfig.subPages[gIndex] : void 0; if (gPage) { if (page.uniqueName != null && page.uniqueName !== gPage.uniqueName) { globalConfig.subPages = navigationAdjustRun( gPage.uniqueName, page.uniqueName, globalConfig.subPages, {}, globalConfig.maxNavigationAdjustRuns, 0, page.uniqueName ); const index = globalConfig.subPages.findIndex( (p) => p.uniqueName === page.uniqueName ); if (index !== -1) { gPage = globalConfig.subPages[index]; gPage.uniqueName = page.uniqueName; } } else { removeGlobalPageIndexs.add(gIndex); } config.pages[i] = { ...gPage, prev: void 0, next: void 0, home: void 0, parent: void 0 }; if (page.heading) { config.pages[i].heading = page.heading; } } else { config.pages.splice(i, 1); const msg = `Global page with uniqueName ${page.globalLink} not found!`; messages.push(msg); this.log.warn(msg); } } } for (let i = config.subPages.length - 1; i >= 0; i--) { const page = config.subPages[i]; if (page && "globalLink" in page && page.globalLink) { const gIndex = globalConfig.subPages.findIndex((item) => item.uniqueName === page.globalLink); let gPage = gIndex !== -1 ? globalConfig.subPages[gIndex] : void 0; if (gPage) { if (page.uniqueName != null && page.uniqueName !== gPage.uniqueName) { globalConfig.subPages = navigationAdjustRun( gPage.uniqueName, page.uniqueName, globalConfig.subPages, {}, globalConfig.maxNavigationAdjustRuns, 0, page.uniqueName ); const index = globalConfig.subPages.findIndex( (p) => p.uniqueName === page.uniqueName ); if (index !== -1) { gPage = globalConfig.subPages[index]; gPage.uniqueName = page.uniqueName; } } else { removeGlobalPageIndexs.add(gIndex); } const existNav = page.prev != null || page.parent != null || page.next != null || page.home != null; config.subPages[i] = { ...gPage, prev: existNav ? page.prev : gPage.prev, parent: existNav ? page.parent : gPage.parent, next: existNav ? page.next : gPage.next, home: existNav ? page.home : gPage.home }; if (page.heading) { config.subPages[i].heading = page.heading; } } else { config.subPages.splice(i, 1); const msg = `Global page with uniqueName ${page.globalLink} not found!`; messages.push(msg); this.log.warn(msg); } } } for (const index of Array.from(removeGlobalPageIndexs).sort((a, b) => b - a)) { globalConfig.subPages.splice(index, 1); } config.subPages = config.subPages.concat(globalConfig.subPages || []); config.navigation = (config.navigation || []).concat(globalConfig.navigation || []); config.nativePageItems = (config.nativePageItems || []).concat(globalConfig.nativePageItems || []); } } } 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: [], scriptVersion: config.version }; 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}`; } try { const result = await this.getScreensaverConfig(config, messages); const screensaver = result.configArray; messages = result.messages; 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 > 0) { panelConfig.navigation = panelConfig.navigation.filter((item) => item != null); if (panelConfig.navigation.length > 1) { 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; messages.push(`Abort - double uniqueName ${page.uniqueName} in config!`); this.log.error(messages[messages.length - 1]); } 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) { var _a, _b, _c, _d, _e, _f, _g; if (panelConfig.pages === void 0) { panelConfig.pages = []; } if (config.pages) { const scriptPages = config.pages.concat(config.subPages || []); for (const page of scriptPages) { if (!page) { continue; } if (page.type === void 0 && page.native) { if ((config.subPages || []).includes(page)) { let left = page.prev || page.parent || void 0; let right = page.next || page.home || void 0; if (left && left === page.uniqueName) { left = ""; messages.push( `Page: ${page.native.uniqueID || "unknown"} has left navigation to itself! Removed!` ); this.log.warn(messages[messages.length - 1]); } if (right && right === page.uniqueName) { right = ""; messages.push( `Page: ${page.native.uniqueID || "unknown"} has right navigation to itself! Removed!` ); this.log.warn(messages[messages.length - 1]); } 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 !== "cardThermo2" && page.type !== "cardPower" && page.type !== "cardChart" && page.type !== "cardLChart" && page.type !== "cardMedia" && page.type !== "cardSchedule") { 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); } } let gridItem = { dpInit: "", alwaysOn: page.alwaysOnDisplay ? typeof page.alwaysOnDisplay === "boolean" ? "always" : "action" : "none", uniqueID: page.uniqueName || "", hidden: page.hiddenByTrigger || false, config: { card: page.type, data: { headline: await this.getFieldAsDataItemConfig(page.heading || "") }, index: 0 }, pageItems: [] }; if ((((_a = gridItem.config) == null ? void 0 : _a.card) === "cardGrid" || ((_b = gridItem.config) == null ? void 0 : _b.card) === "cardGrid2" || ((_c = gridItem.config) == null ? void 0 : _c.card) === "cardGrid3" || ((_d = gridItem.config) == null ? void 0 : _d.card) === "cardEntities" || ((_e = gridItem.config) == null ? void 0 : _e.card) === "cardSchedule" || ((_f = gridItem.config) == null ? void 0 : _f.card) === "cardThermo2" || ((_g = gridItem.config) == null ? void 0 : _g.card) === "cardMedia") && (page.type === "cardGrid" || page.type === "cardGrid2" || page.type === "cardGrid3" || page.type === "cardEntities" || page.type === "cardSchedule" || page.type === "cardThermo2" || page.type === "cardMedia")) { gridItem.config.scrollType = page.scrollType || "page"; gridItem.config.scrollPresentation = page.scrollPresentation || "classic"; if (globals.isPageMenuConfig(gridItem.config) && gridItem.config.scrollPresentation === "auto") { gridItem.config.scrollAutoTiming = "scrollAutoTiming" in page && page.scrollAutoTiming || 15; } } try { if (page.type === "cardThermo") { ({ gridItem, messages } = await this.getPageThermo(page, gridItem, messages)); } } catch (error) { messages.push( `Configuration error in page thermo ${page.heading || "unknown"} with uniqueName ${page.uniqueName} - ${error}` ); this.log.warn(messages[messages.length - 1]); continue; } try { if (page.type === "cardThermo2") { ({ gridItem, messages } = await import_pageThermo2.PageThermo2.getPage(this, page, gridItem, messages)); } } catch (error) { messages.push( `Configuration error in page thermo2 ${page.heading || "unknown"} with uniqueName ${page.uniqueName} - ${error}` ); this.log.warn(messages[messages.length - 1]); continue; } try { if (page.type === "cardMedia") { ({ gridItem, messages } = await import_pageMedia.PageMedia.getPage(this, page, gridItem, messages)); } } catch (error) { messages.push( `Configuration error in page media ${page.heading || "unknown"} with uniqueName ${page.uniqueName} - ${error}` ); this.log.warn(messages[messages.length - 1]); 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; } try { ({ gridItem, messages } = await import_pagePower.PagePower.getPowerPageConfig( this, page, index, gridItem, messages )); } catch (error) { messages.push( `Configuration error in page power ${page.heading || "unknown"} with uniqueName ${page.uniqueName} - ${error}` ); this.log.warn(messages[messages.length - 1]); continue; } } if (page.type === "cardChart" || page.type === "cardLChart") { if (!Array.isArray(this.adapter.config.pageChartdata)) { messages.push(`No pageChart configured in Admin for ${page.uniqueName}`); this.log.warn(messages[messages.length - 1]); continue; } const index = this.adapter.config.pageChartdata.findIndex( (item) => item.pageName === page.uniqueName ); if (index === -1) { messages.push(`No pageChartdata found for ${page.uniqueName}`); this.log.warn(messages[messages.length - 1]); continue; } try { ({ gridItem, messages } = await import_pageChart.PageChart.getChartPageConfig( this, index, gridItem, messages, page )); } catch (error) { messages.push( `Configuration error in page chart ${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); } if (temp.pageConfig) { temp.pageConfig.parent = page.uniqueName; scriptPages.push(temp.pageConfig); config.subPages.push(temp.pageConfig); } } catch (error) { messages.push( `Configuration error in page ${page.heading || "unknown"} with uniqueName ${page.uniqueName} pageitem - ${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 || !("id" in item) || !item.id || item.id.endsWith(".")) { const msg = `${page.uniqueName} id: ${"id" in item ? item.id : "invalid"} 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: ${item.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: ${item.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", 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: "Humidity2" } } : 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