From 5d84b59bbdd522f1d58a40e79c6cd7cb01d17bf5 Mon Sep 17 00:00:00 2001 From: Armilar <102996011+Armilar@users.noreply.github.com> Date: Wed, 18 Sep 2024 09:44:59 +0200 Subject: [PATCH] v4.4.0.4 - Update NsPanelTs.ts v4.4.0.2 Calculated energy consumption in relation to dimming mode and relay state (not the energy consumption of the outputs) v4.4.0.3 Check prefix '.tele.' in config.NSPanelReceiveTopic v4.4.0.4 New Feature: Hidden Carts --- ioBroker/NsPanelTs.ts | 7232 +++++++++++++++++++++++------------------ 1 file changed, 4071 insertions(+), 3161 deletions(-) diff --git a/ioBroker/NsPanelTs.ts b/ioBroker/NsPanelTs.ts index d824a6f7..ae5c191b 100644 --- a/ioBroker/NsPanelTs.ts +++ b/ioBroker/NsPanelTs.ts @@ -1,6 +1,6 @@ /*----------------------------------------------------------------------- -TypeScript v4.4.0.1 zur Steuerung des SONOFF NSPanel mit dem ioBroker by @Armilar / @TT-Tom / @ticaki / @Britzelpuf / @Sternmiere / @ravenS0ne -- abgestimmt auf TFT 53 / v4.4.0 / BerryDriver 9 / Tasmota 14.0.0 +TypeScript v4.4.0.4 zur Steuerung des SONOFF NSPanel mit dem ioBroker by @Armilar / @TT-Tom / @ticaki / @Britzelpuf / @Sternmiere / @ravenS0ne +- abgestimmt auf TFT 53 / v4.4.0 / BerryDriver 9 / Tasmota 14.2.0 @joBr99 Projekt: https://github.com/joBr99/nspanel-lovelace-ui/tree/main/ioBroker NsPanelTs.ts (dieses TypeScript in ioBroker) Stable: https://github.com/joBr99/nspanel-lovelace-ui/blob/main/ioBroker/NsPanelTs.ts icon_mapping.ts: https://github.com/joBr99/nspanel-lovelace-ui/blob/main/ioBroker/icon_mapping.ts (TypeScript muss in global liegen) @@ -118,11 +118,14 @@ ReleaseNotes: - 10.02.2024 - v4.3.3.43 Fix: cardGrid2 => 9 Entities for Layout 'us-p' issue #1167 - 11.02.2024 - v4.3.3.43 Fix VolumeSlider - 05.05.2024 - v4.3.3.44 Fix MQTT-Port-check - - 13.05.2024 - v4.4.0.0 TFT 54 / 4.4.0 - - 13.05.2024 - v4.4.0.1 TFT 53 / 4.4.0 + - 13.05.2024 - v4.4.0.0 TFT 54 / 4.4.0 + - 19.05.2024 - v4.4.0.1 TFT 53 / 4.4.0 + - 13.06.2024 - v4.4.0.2 Calculated energy consumption in relation to dimming mode and relay state (not the energy consumption of the outputs) + - 13.06.2024 - v4.4.0.3 Check prefix '.tele.' in config.NSPanelReceiveTopic + - 13.09.2024 - v4.4.0.4 New Feature: Hidden Carts Todo: - - XX.XX.XXXX - v5.0.0 Change the bottomScreensaverEntity (rolling) if more than 6 entries are defined + - XX.12.2024 - v5.0.0 ioBroker Adapter *************************************************************************************************************** * DE: Für die Erstellung der Aliase durch das Skript, muss in der JavaScript Instanz "setObject" gesetzt sein! * @@ -728,6 +731,7 @@ let NSPanel_Service_SubPage: PageType = 'items': [ /*PageItem*/{ id: AliasPath + 'Config.ScripgtDebugStatus', name: findLocaleServMenu('debugmode_offon') ,icon: 'code-tags-check', offColor: HMIOff, onColor: HMIOn}, /*PageItem*/{ id: AliasPath + 'Config.MQTT.portCheck', name: findLocaleServMenu('port_check_offon') ,icon: 'check-network', offColor: HMIOff, onColor: HMIOn}, + /*PageItem*/{ id: AliasPath + 'Config.hiddenCards', name: findLocaleServMenu('hiddencards_offon'), icon: 'check-network', offColor: HMIOff, onColor: HMIOn }, ] }; @@ -988,7 +992,7 @@ export const config: Config = { // _________________________________ DE: Ab hier keine Konfiguration mehr _____________________________________ // _________________________________ EN: No more configuration from here _____________________________________ -const scriptVersion: string = 'v4.4.0.1'; +const scriptVersion: string = 'v4.4.0.4'; const tft_version: string = 'v4.4.0'; const desired_display_firmware_version = 53; const berry_driver_version = 9; @@ -1001,18 +1005,19 @@ let vwIconColor: number[] = []; let weatherForecast: boolean; let pageCounter: number = 0; let alwaysOn: boolean = false; +let valueHiddenCards = getState(NSPanel_Path + 'Config.hiddenCards').val; -let buttonToggleState: {[key: string]: boolean} = {}; +let buttonToggleState: { [key: string]: boolean } = {}; const axios = require('axios'); const dayjs = require('dayjs'); -const moment = require('moment'); +const moment = require('moment'); const parseFormat = require('moment-parseformat'); moment.locale(getState(NSPanel_Path + 'Config.locale').val); -const scheduleList:{[key:string]: any} = {}; +const scheduleList: { [key: string]: any } = {}; -const globalTextColor: any = White; +const globalTextColor: any = White; const Sliders2: number = 0; let checkBlindActive: boolean = false; @@ -1020,17 +1025,54 @@ async function Init_dayjs() { try { //Loading dayjs const dayjs = require('dayjs'); - const dayjsLanguages: any = ['en','de','nl','da','es','fr','it','ru','nb','nn', - 'pl','pt','af','ar','bg','ca','cs','el','et','fa', - 'fi','he','hr','hu','hy-am','id','is','lb','lt','ro', - 'sk','sl','sv','th','tr','uk','vi','zh-cn','zh-tw'] - for (let i=0; i> is not reachable. Please Check Parameters!','error'); + log('Config-Parameter: << config.panelRecvTopic - ' + config.panelRecvTopic + ' >> is not reachable. Please Check Parameters!', 'error'); + } + if (config.panelRecvTopic.indexOf('.tele.') < 0) { + log('Config-Parameter: << config.panelRecvTopic - ' + config.panelRecvTopic + ' >> does not refer to the prefix .tele. Please Check Parameters!', 'error'); } if (existsObject(config.panelSendTopic) == false) { const n = config.panelSendTopic.split('.'); const a = n.shift(); const i = n.shift(); - + if (a === 'mqtt' && !isNaN(Number(i))) { - sendTo(`${a}.${i}`, 'sendMessage2Client', {topic: n.join('/'), message: buildNSPanelString('time', '12:00')}); + sendTo(`${a}.${i}`, 'sendMessage2Client', { topic: n.join('/'), message: buildNSPanelString('time', '12:00') }); await sleep(500); } - if (await existsObjectAsync(config.panelSendTopic) == false) { - log('Config-Parameter: << config.panelSendTopic - ' + config.panelSendTopic + ' >> is not reachable. Please Check Parameters!','error'); + if ((await existsObjectAsync(config.panelSendTopic)) == false) { + log('Config-Parameter: << config.panelSendTopic - ' + config.panelSendTopic + ' >> is not reachable. Please Check Parameters!', 'error'); stopScript(scriptName); } } if (weatherAdapterInstance.substring(0, weatherAdapterInstance.length - 3) == 'daswetter') { - if (existsObject(weatherAdapterInstance + 'NextHours.Location_1.Day_1.current.symbol_value') == false) { - log('Weather adapter: << weatherAdapterInstance - ' + weatherAdapterInstance + ' >> is not installed. Please Check Adapter!','error'); + if (existsObject(weatherAdapterInstance + 'NextHours.Location_1.Day_1.current.symbol_value') == false) { + log('Weather adapter: << weatherAdapterInstance - ' + weatherAdapterInstance + ' >> is not installed. Please Check Adapter!', 'error'); } } if (weatherAdapterInstance.substring(0, weatherAdapterInstance.length - 3) == 'accuweather') { - if (existsObject(weatherAdapterInstance + 'Current.WeatherIcon') == false) { - log('Weather adapter: << weatherAdapterInstance - ' + weatherAdapterInstance + ' >> is not installed. Please Check Adapter!','error'); + if (existsObject(weatherAdapterInstance + 'Current.WeatherIcon') == false) { + log('Weather adapter: << weatherAdapterInstance - ' + weatherAdapterInstance + ' >> is not installed. Please Check Adapter!', 'error'); } } - let weatherAdapterInstanceArray: any = weatherAdapterInstance.split("."); + let weatherAdapterInstanceArray: any = weatherAdapterInstance.split('.'); weatherAdapterInstanceNumber = weatherAdapterInstanceArray[1]; - if (Debug) log('Number of weatherAdapterInstance: ' + weatherAdapterInstanceNumber,'info'); + if (Debug) log('Number of weatherAdapterInstance: ' + weatherAdapterInstanceNumber, 'info'); const adapterList = $('system.adapter.*.alive'); - adapterList.each(function(id, i) { + adapterList.each(function (id, i) { id = id.substring(0, id.lastIndexOf('.')); - if(existsObject(id)) { + if (existsObject(id)) { let common = getObject(id).common; if (common.name == 'javascript') { javaScriptVersion = common.version; setIfExists(NSPanel_Path + 'IoBroker.JavaScriptVersion', 'v' + javaScriptVersion, null, true); setIfExists(NSPanel_Path + 'IoBroker.ScriptName', (name as unknown as string).split('.').slice(2).join('.'), null, true); let jsVersion = common.version.split('.'); - let jsV = 10*parseInt(jsVersion[0]) + parseInt(jsVersion[1]); - if (jsV<61) log('JS-Adapter: ' + common.name + ' must be at least v6.1.3. Currently: v' + common.version, 'error'); - } + let jsV = 10 * parseInt(jsVersion[0]) + parseInt(jsVersion[1]); + if (jsV < 61) log('JS-Adapter: ' + common.name + ' must be at least v6.1.3. Currently: v' + common.version, 'error'); + } } }); - + const hostList = $('system.host.*.nodeCurrent'); - hostList.each(function(id, i) { + hostList.each(function (id, i) { nodeVersion = getState(id).val; - setIfExists(NSPanel_Path + 'IoBroker.NodeJSVersion', 'v' + nodeVersion, null , true); - let nodeJSVersion = (getState(id).val).split('.'); + setIfExists(NSPanel_Path + 'IoBroker.NodeJSVersion', 'v' + nodeVersion, null, true); + let nodeJSVersion = getState(id).val.split('.'); if (parseInt(nodeJSVersion[0]) < 18) { - log('nodeJS must be at least v18.X.X. Currently: v' + getState(id).val + '! Please Update your System! --> iob nodejs-update 18', ); + log('nodeJS must be at least v18.X.X. Currently: v' + getState(id).val + '! Please Update your System! --> iob nodejs-update 18'); } - if (parseInt(nodeJSVersion[0])%2 != 0) { - log('nodeJS does not have an even version number. An odd version number is a developer version. Please correct nodeJS version','info'); + if (parseInt(nodeJSVersion[0]) % 2 != 0) { + log('nodeJS does not have an even version number. An odd version number is a developer version. Please correct nodeJS version', 'info'); } }); - if (config.mrIcon1ScreensaverEntity.ScreensaverEntity != null && existsObject(config.mrIcon1ScreensaverEntity.ScreensaverEntity) == false ) { - log('mrIcon1ScreensaverEntity data point in the config not available - please adjust','warn'); - } + if (config.mrIcon1ScreensaverEntity.ScreensaverEntity != null && existsObject(config.mrIcon1ScreensaverEntity.ScreensaverEntity) == false) { + log('mrIcon1ScreensaverEntity data point in the config not available - please adjust', 'warn'); + } if (config.mrIcon2ScreensaverEntity.ScreensaverEntity != null && existsObject(config.mrIcon2ScreensaverEntity.ScreensaverEntity) == false) { - log('mrIcon2ScreensaverEntity data point in the config not available - please adjust','warn'); - } + log('mrIcon2ScreensaverEntity data point in the config not available - please adjust', 'warn'); + } if (CheckEnableSetObject()) { - log('setObjects enabled - create Alias Channels possible','info'); + log('setObjects enabled - create Alias Channels possible', 'info'); isSetOptionActive = true; - } else { + } else { log('setObjects disabled - Please enable setObjects in JS-Adapter Instance - create Alias Channels not possible', 'warn'); - } - } catch (err: any) { - log('error at function CheckConfigParameters: ' + err.message, 'warn'); + } + } catch (err: any) { + log('error at function CheckConfigParameters: ' + err.message, 'warn'); } } CheckConfigParameters(); @@ -1145,19 +1189,23 @@ async function InitIoBrokerInfo() { if (isSetOptionActive) { // Script Version await createStateAsync(NSPanel_Path + 'IoBroker.ScriptVersion', scriptVersion, { type: 'string', write: false }); - setObject(AliasPath + 'IoBroker.ScriptVersion', {type: 'channel', common: {role: 'info', name:'Version NSPanelTS'}, native: {}}); + setObject(AliasPath + 'IoBroker.ScriptVersion', { type: 'channel', common: { role: 'info', name: 'Version NSPanelTS' }, native: {} }); await createAliasAsync(AliasPath + 'IoBroker.ScriptVersion.ACTUAL', NSPanel_Path + 'IoBroker.ScriptVersion', true, { type: 'string', role: 'state', name: 'ACTUAL' }); // NodeJS Verion await createStateAsync(NSPanel_Path + 'IoBroker.NodeJSVersion', 'v' + nodeVersion, { type: 'string', write: false }); - setObject(AliasPath + 'IoBroker.NodeJSVersion', {type: 'channel', common: {role: 'info', name:'Version NodeJS'}, native: {}}); + setObject(AliasPath + 'IoBroker.NodeJSVersion', { type: 'channel', common: { role: 'info', name: 'Version NodeJS' }, native: {} }); await createAliasAsync(AliasPath + 'IoBroker.NodeJSVersion.ACTUAL', NSPanel_Path + 'IoBroker.NodeJSVersion', true, { type: 'string', role: 'state', name: 'ACTUAL' }); // JavaScript Version await createStateAsync(NSPanel_Path + 'IoBroker.JavaScriptVersion', 'v' + javaScriptVersion, { type: 'string', write: false }); - setObject(AliasPath + 'IoBroker.JavaScriptVersion', {type: 'channel', common: {role: 'info', name:'Version JavaScript Instanz'}, native: {}}); - await createAliasAsync(AliasPath + 'IoBroker.JavaScriptVersion.ACTUAL', NSPanel_Path + 'IoBroker.JavaScriptVersion', true, { type: 'string', role: 'state', name: 'ACTUAL' }); + setObject(AliasPath + 'IoBroker.JavaScriptVersion', { type: 'channel', common: { role: 'info', name: 'Version JavaScript Instanz' }, native: {} }); + await createAliasAsync(AliasPath + 'IoBroker.JavaScriptVersion.ACTUAL', NSPanel_Path + 'IoBroker.JavaScriptVersion', true, { + type: 'string', + role: 'state', + name: 'ACTUAL', + }); // ScriptName await createStateAsync(NSPanel_Path + 'IoBroker.ScriptName', 'v' + javaScriptVersion, { type: 'string', write: false }); - setObject(AliasPath + 'IoBroker.ScriptName', {type: 'channel', common: {role: 'info', name:'Scriptname'}, native: {}}); + setObject(AliasPath + 'IoBroker.ScriptName', { type: 'channel', common: { role: 'info', name: 'Scriptname' }, native: {} }); await createAliasAsync(AliasPath + 'IoBroker.ScriptName.ACTUAL', NSPanel_Path + 'IoBroker.ScriptName', true, { type: 'string', role: 'state', name: 'ACTUAL' }); } setIfExists(NSPanel_Path + 'IoBroker.ScriptVersion', scriptVersion, null, true); @@ -1171,32 +1219,35 @@ async function CheckDebugMode() { try { if (isSetOptionActive) { await createStateAsync(NSPanel_Path + 'Config.ScripgtDebugStatus', false, { type: 'boolean', write: true }); - setObject(AliasPath + 'Config.ScripgtDebugStatus', {type: 'channel', common: {role: 'socket', name:'ScripgtDebugStatus'}, native: {}}); - await createAliasAsync(AliasPath + 'Config.ScripgtDebugStatus.ACTUAL', NSPanel_Path + 'Config.ScripgtDebugStatus', true, { type: 'boolean', role: 'switch', name: 'ACTUAL' }); + setObject(AliasPath + 'Config.ScripgtDebugStatus', { type: 'channel', common: { role: 'socket', name: 'ScripgtDebugStatus' }, native: {} }); + await createAliasAsync(AliasPath + 'Config.ScripgtDebugStatus.ACTUAL', NSPanel_Path + 'Config.ScripgtDebugStatus', true, { + type: 'boolean', + role: 'switch', + name: 'ACTUAL', + }); await createAliasAsync(AliasPath + 'Config.ScripgtDebugStatus.SET', NSPanel_Path + 'Config.ScripgtDebugStatus', true, { type: 'boolean', role: 'switch', name: 'SET' }); } - if(getState(NSPanel_Path + 'Config.ScripgtDebugStatus').val){ + if (getState(NSPanel_Path + 'Config.ScripgtDebugStatus').val) { Debug = true; - log('Debug mode activated','info'); - }else{ + log('Debug mode activated', 'info'); + } else { Debug = false; - log('Debug mode disabled','info'); + log('Debug mode disabled', 'info'); } - } catch (err: any) { - log('error at function CheckDebugModus: ' + err.message,'warn'); - } + log('error at function CheckDebugModus: ' + err.message, 'warn'); + } } CheckDebugMode(); async function CheckMQTTPorts() { try { - let instanceName: string = config.panelRecvTopic.substring(0,6); + let instanceName: string = config.panelRecvTopic.substring(0, 6); if (isSetOptionActive) { await createStateAsync(NSPanel_Path + 'Config.MQTT.portCheck', true, { type: 'boolean', write: true }); - setObject(AliasPath + 'Config.MQTT.portCheck', {type: 'channel', common: {role: 'socket', name:'mqttPortCheck'}, native: {}}); + setObject(AliasPath + 'Config.MQTT.portCheck', { type: 'channel', common: { role: 'socket', name: 'mqttPortCheck' }, native: {} }); await createAliasAsync(AliasPath + 'Config.MQTT.portCheck.ACTUAL', NSPanel_Path + 'Config.MQTT.portCheck', true, { type: 'boolean', role: 'switch', name: 'ACTUAL' }); await createAliasAsync(AliasPath + 'Config.MQTT.portCheck.SET', NSPanel_Path + 'Config.MQTT.portCheck', true, { type: 'boolean', role: 'switch', name: 'SET' }); } @@ -1205,56 +1256,57 @@ async function CheckMQTTPorts() { let adapterArray: any = []; let portArray: any = []; exec('iob l i --port --enabled', async (error, result, stderr) => { - if (error == null){ + if (error == null) { if (result != undefined) { log('Start MQTT-Port-Check -------------------------------------', 'info'); let resultString1 = result.split('+'); - for (let i: number = 1; i < resultString1.length -1; i++) { - let resultString2: any = resultString1[i].split(':') + for (let i: number = 1; i < resultString1.length - 1; i++) { + let resultString2: any = resultString1[i].split(':'); if (Debug) log(`MQTT-PORT-Check Result ` + JSON.stringify(resultString2)); let adapterInstanceName: string = resultString2[0].substring(16); let adapterInstancePort: string = ''; - if (resultString2[2].match("port") != null) { + if (resultString2[2].match('port') != null) { adapterInstancePort = resultString2[3].substring(1, 5); - } else { adapterInstancePort = 'Kein Port gefunden'; } - log('-- '+ adapterInstanceName + ' - ' + adapterInstancePort, 'info'); + } else { + adapterInstancePort = 'Kein Port gefunden'; + } + log('-- ' + adapterInstanceName + ' - ' + adapterInstancePort, 'info'); adapterArray[i] = adapterInstanceName.trim(); portArray[i] = adapterInstancePort.trim(); } let mqttInstance = adapterArray.indexOf(instanceName); - - const mqttConfig = getObject(`system.adapter.${adapterArray[mqttInstance]}`) + + const mqttConfig = getObject(`system.adapter.${adapterArray[mqttInstance]}`); if (mqttConfig && mqttConfig.native && mqttConfig.native.type == 'client') { - log('- MQTT-Port-Check OK: Instance of Adapter: ' +adapterArray[mqttInstance] + ' is running as client!','info'); + log('- MQTT-Port-Check OK: Instance of Adapter: ' + adapterArray[mqttInstance] + ' is running as client!', 'info'); } else { for (let j: number = 1; j < portArray.length; j++) { if (portArray[j] == portArray[mqttInstance] && adapterArray[j] == adapterArray[mqttInstance]) { log('- MQTT-Port-Check OK: Instance of Adapter: ' + adapterArray[j] + ' is running on Port:' + portArray[j], 'info'); - } else if (portArray[j] == portArray[mqttInstance] && adapterArray[j] != adapterArray[mqttInstance]) { + } else if (portArray[j] == portArray[mqttInstance] && adapterArray[j] != adapterArray[mqttInstance]) { log('Instance of Adapter: ' + adapterArray[j] + ' is running on same Port:' + portArray[j] + ' as ' + adapterArray[mqttInstance], 'warn'); log('Please Change Port of Instance: ' + adapterArray[j], 'warn'); } } } - log('End MQTT-Port-Check ---------------------------------------','info'); + log('End MQTT-Port-Check ---------------------------------------', 'info'); } - - } else if (error.toString().substring(0,21) == 'exec is not available') { + } else if (error.toString().substring(0, 21) == 'exec is not available') { log('MQTT-Portcheck not possible - exec is not available. Please enable exec option in JS-Adapter instance settings', 'warn'); log('MQTT-Portcheck nicht möglich - exec ist nicht verfügbar. Bitte Haken bei -- Kommando Exec erlauben -- in JS-Adapter-Instanz setzen', 'warn'); - } + } }); } - } catch (err: any) { - log('error at function CheckMQTTPorts: ' + err.message, 'warn'); + } catch (err: any) { + log('error at function CheckMQTTPorts: ' + err.message, 'warn'); } } CheckMQTTPorts(); async function Init_Release() { - const FWVersion = [41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56]; - const FWRelease = ['3.3.1','3.4.0','3.5.0','3.5.X','3.6.0','3.7.3','3.8.0','3.8.3','3.9.4','4.0.5','4.1.4','4.2.1','4.4.0','4.4.0','4.5.0','4.6.0']; + const FWVersion = [41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56]; + const FWRelease = ['3.3.1', '3.4.0', '3.5.0', '3.5.X', '3.6.0', '3.7.3', '3.8.0', '3.8.3', '3.9.4', '4.0.5', '4.1.4', '4.2.1', '4.4.0', '4.4.0', '4.5.0', '4.6.0']; try { if (existsObject(NSPanel_Path + 'Display_Firmware.desiredVersion') == false) { await createStateAsync(NSPanel_Path + 'Display_Firmware.desiredVersion', desired_display_firmware_version, { type: 'number', write: false }); @@ -1282,18 +1334,26 @@ async function Init_Release() { if (isSetOptionActive) { await createStateAsync(NSPanel_Path + 'Display_Firmware.TFT.currentVersion', currentFW + ' / v' + FWRelease[findFWIndex], { type: 'string', write: false }); await createStateAsync(NSPanel_Path + 'Display_Firmware.TFT.desiredVersion', desired_display_firmware_version, { type: 'string', write: false }); - setObject(AliasPath + 'Display_Firmware.TFT.currentVersion', {type: 'channel', common: {role: 'info', name:'current TFT-Version'}, native: {}}); - setObject(AliasPath + 'Display_Firmware.TFT.desiredVersion', {type: 'channel', common: {role: 'info', name:'desired TFT-Version'}, native: {}}); - await createAliasAsync(AliasPath + 'Display_Firmware.TFT.currentVersion.ACTUAL', NSPanel_Path + 'Display_Firmware.TFT.currentVersion', true, { type: 'string', role: 'state', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Display_Firmware.TFT.desiredVersion.ACTUAL', NSPanel_Path + 'Display_Firmware.TFT.desiredVersion', true, { type: 'string', role: 'state', name: 'ACTUAL' }); + setObject(AliasPath + 'Display_Firmware.TFT.currentVersion', { type: 'channel', common: { role: 'info', name: 'current TFT-Version' }, native: {} }); + setObject(AliasPath + 'Display_Firmware.TFT.desiredVersion', { type: 'channel', common: { role: 'info', name: 'desired TFT-Version' }, native: {} }); + await createAliasAsync(AliasPath + 'Display_Firmware.TFT.currentVersion.ACTUAL', NSPanel_Path + 'Display_Firmware.TFT.currentVersion', true, { + type: 'string', + role: 'state', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'Display_Firmware.TFT.desiredVersion.ACTUAL', NSPanel_Path + 'Display_Firmware.TFT.desiredVersion', true, { + type: 'string', + role: 'state', + name: 'ACTUAL', + }); } } else { //Create TFT DP's await setStateAsync(NSPanel_Path + 'Display_Firmware.TFT.currentVersion', currentFW + ' / v' + FWRelease[findFWIndex], true); await setStateAsync(NSPanel_Path + 'Display_Firmware.TFT.desiredVersion', desired_display_firmware_version + ' / ' + tft_version, true); } - } catch (err: any) { - log('error at function Init_Release: ' + err.message, 'warn'); + } catch (err: any) { + log('error at function Init_Release: ' + err.message, 'warn'); } } Init_Release(); @@ -1303,35 +1363,71 @@ async function InitConfigParameters() { if (isSetOptionActive) { // alternativeScreensaverLayout (socket) await createStateAsync(NSPanel_Path + 'Config.Screensaver.alternativeScreensaverLayout', false, { type: 'boolean', write: true }); - setObject(AliasPath + 'Config.Screensaver.alternativeScreensaverLayout', {type: 'channel', common: {role: 'socket', name:'alternativeScreensaverLayout'}, native: {}}); - await createAliasAsync(AliasPath + 'Config.Screensaver.alternativeScreensaverLayout.ACTUAL', NSPanel_Path + 'Config.Screensaver.alternativeScreensaverLayout', true, { type: 'boolean', role: 'switch', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Config.Screensaver.alternativeScreensaverLayout.SET', NSPanel_Path + 'Config.Screensaver.alternativeScreensaverLayout', true, { type: 'boolean', role: 'switch', name: 'SET' }); + setObject(AliasPath + 'Config.Screensaver.alternativeScreensaverLayout', { type: 'channel', common: { role: 'socket', name: 'alternativeScreensaverLayout' }, native: {} }); + await createAliasAsync(AliasPath + 'Config.Screensaver.alternativeScreensaverLayout.ACTUAL', NSPanel_Path + 'Config.Screensaver.alternativeScreensaverLayout', true, { + type: 'boolean', + role: 'switch', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'Config.Screensaver.alternativeScreensaverLayout.SET', NSPanel_Path + 'Config.Screensaver.alternativeScreensaverLayout', true, { + type: 'boolean', + role: 'switch', + name: 'SET', + }); await createStateAsync(NSPanel_Path + 'Config.Screensaver.ScreensaverAdvanced', false, { type: 'boolean', write: true }); - setObject(AliasPath + 'Config.Screensaver.ScreensaverAdvanced', {type: 'channel', common: {role: 'socket', name:'ScreensaverAdvanced'}, native: {}}); - await createAliasAsync(AliasPath + 'Config.Screensaver.ScreensaverAdvanced.ACTUAL', NSPanel_Path + 'Config.Screensaver.ScreensaverAdvanced', true, { type: 'boolean', role: 'switch', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Config.Screensaver.ScreensaverAdvanced.SET', NSPanel_Path + 'Config.Screensaver.ScreensaverAdvanced', true, { type: 'boolean', role: 'switch', name: 'SET' }); + setObject(AliasPath + 'Config.Screensaver.ScreensaverAdvanced', { type: 'channel', common: { role: 'socket', name: 'ScreensaverAdvanced' }, native: {} }); + await createAliasAsync(AliasPath + 'Config.Screensaver.ScreensaverAdvanced.ACTUAL', NSPanel_Path + 'Config.Screensaver.ScreensaverAdvanced', true, { + type: 'boolean', + role: 'switch', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'Config.Screensaver.ScreensaverAdvanced.SET', NSPanel_Path + 'Config.Screensaver.ScreensaverAdvanced', true, { + type: 'boolean', + role: 'switch', + name: 'SET', + }); // autoWeatherColorScreensaverLayout (socket) await createStateAsync(NSPanel_Path + 'Config.Screensaver.autoWeatherColorScreensaverLayout', true, { type: 'boolean', write: true }); - setObject(AliasPath + 'Config.Screensaver.autoWeatherColorScreensaverLayout', {type: 'channel', common: {role: 'socket', name:'alternativeScreensaverLayout'}, native: {}}); - await createAliasAsync(AliasPath + 'Config.Screensaver.autoWeatherColorScreensaverLayout.ACTUAL', NSPanel_Path + 'Config.Screensaver.autoWeatherColorScreensaverLayout', true, { type: 'boolean', role: 'switch', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Config.Screensaver.autoWeatherColorScreensaverLayout.SET', NSPanel_Path + 'Config.Screensaver.autoWeatherColorScreensaverLayout', true, { type: 'boolean', role: 'switch', name: 'SET' }); + setObject(AliasPath + 'Config.Screensaver.autoWeatherColorScreensaverLayout', { type: 'channel', common: { role: 'socket', name: 'alternativeScreensaverLayout' }, native: {} }); + await createAliasAsync(AliasPath + 'Config.Screensaver.autoWeatherColorScreensaverLayout.ACTUAL', NSPanel_Path + 'Config.Screensaver.autoWeatherColorScreensaverLayout', true, < + iobJS.StateCommon + >{ type: 'boolean', role: 'switch', name: 'ACTUAL' }); + await createAliasAsync(AliasPath + 'Config.Screensaver.autoWeatherColorScreensaverLayout.SET', NSPanel_Path + 'Config.Screensaver.autoWeatherColorScreensaverLayout', true, < + iobJS.StateCommon + >{ type: 'boolean', role: 'switch', name: 'SET' }); // timeoutScreensaver 0-60 (Slider) await createStateAsync(NSPanel_Path + 'Config.Screensaver.timeoutScreensaver', 10, { type: 'number', write: true }); - setObject(AliasPath + 'Config.Screensaver.timeoutScreensaver', {type: 'channel', common: {role: 'slider', name:'timeoutScreensaver'}, native: {}}); - await createAliasAsync(AliasPath + 'Config.Screensaver.timeoutScreensaver.ACTUAL', NSPanel_Path + 'Config.Screensaver.timeoutScreensaver', true, { type: 'number', role: 'value', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Config.Screensaver.timeoutScreensaver.SET', NSPanel_Path + 'Config.Screensaver.timeoutScreensaver', true, { type: 'number', role: 'level', name: 'SET' }); + setObject(AliasPath + 'Config.Screensaver.timeoutScreensaver', { type: 'channel', common: { role: 'slider', name: 'timeoutScreensaver' }, native: {} }); + await createAliasAsync(AliasPath + 'Config.Screensaver.timeoutScreensaver.ACTUAL', NSPanel_Path + 'Config.Screensaver.timeoutScreensaver', true, { + type: 'number', + role: 'value', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'Config.Screensaver.timeoutScreensaver.SET', NSPanel_Path + 'Config.Screensaver.timeoutScreensaver', true, { + type: 'number', + role: 'level', + name: 'SET', + }); // screenSaverDoubleClick (socket) await createStateAsync(NSPanel_Path + 'Config.Screensaver.screenSaverDoubleClick', true, { type: 'boolean', write: true }); - setObject(AliasPath + 'Config.Screensaver.screenSaverDoubleClick', {type: 'channel', common: {role: 'socket', name:'screenSaverDoubleClick'}, native: {}}); - await createAliasAsync(AliasPath + 'Config.Screensaver.screenSaverDoubleClick.ACTUAL', NSPanel_Path + 'Config.Screensaver.screenSaverDoubleClick', true, { type: 'boolean', role: 'switch', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Config.Screensaver.screenSaverDoubleClick.SET', NSPanel_Path + 'Config.Screensaver.screenSaverDoubleClick', true, { type: 'boolean', role: 'switch', name: 'SET' }); + setObject(AliasPath + 'Config.Screensaver.screenSaverDoubleClick', { type: 'channel', common: { role: 'socket', name: 'screenSaverDoubleClick' }, native: {} }); + await createAliasAsync(AliasPath + 'Config.Screensaver.screenSaverDoubleClick.ACTUAL', NSPanel_Path + 'Config.Screensaver.screenSaverDoubleClick', true, { + type: 'boolean', + role: 'switch', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'Config.Screensaver.screenSaverDoubleClick.SET', NSPanel_Path + 'Config.Screensaver.screenSaverDoubleClick', true, { + type: 'boolean', + role: 'switch', + name: 'SET', + }); if (existsObject(NSPanel_Path + 'Config.locale') == false) { - // en-US, de-DE, nl-NL, da-DK, es-ES, fr-FR, it-IT, ru-RU, etc. + // en-US, de-DE, nl-NL, da-DK, es-ES, fr-FR, it-IT, ru-RU, etc. await createStateAsync(NSPanel_Path + 'Config.locale', 'de-DE', { type: 'string', write: true }); setStateAsync(NSPanel_Path + 'Config.locale', 'de-DE'); } @@ -1344,38 +1440,111 @@ async function InitConfigParameters() { // locale Tastensensor popupInSel buttonSensor if (existsObject(NSPanel_Path + 'Config.localeNumber') == false) { await createStateAsync(NSPanel_Path + 'Config.localeNumber', 1, { type: 'number', write: true }); - setObject(AliasPath + 'Config.localeNumber', {type: 'channel', common: {role: 'buttonSensor', name:'localeNumber'}, native: {}}); + setObject(AliasPath + 'Config.localeNumber', { type: 'channel', common: { role: 'buttonSensor', name: 'localeNumber' }, native: {} }); await createAliasAsync(AliasPath + 'Config.localeNumber.VALUE', NSPanel_Path + 'Config.localeNumber', true, { type: 'number', role: 'state', name: 'VALUE' }); } // temperatureUnit popupInSel buttonSensor if (existsObject(NSPanel_Path + 'Config.temperatureUnitNumber') == false) { await createStateAsync(NSPanel_Path + 'Config.temperatureUnitNumber', 0, { type: 'number', write: true }); - setObject(AliasPath + 'Config.temperatureUnitNumber', {type: 'channel', common: {role: 'buttonSensor', name:'temperatureUnitNumber'}, native: {}}); - await createAliasAsync(AliasPath + 'Config.temperatureUnitNumber.VALUE', NSPanel_Path + 'Config.temperatureUnitNumber', true, { type: 'number', role: 'state', name: 'VALUE' }); + setObject(AliasPath + 'Config.temperatureUnitNumber', { type: 'channel', common: { role: 'buttonSensor', name: 'temperatureUnitNumber' }, native: {} }); + await createAliasAsync(AliasPath + 'Config.temperatureUnitNumber.VALUE', NSPanel_Path + 'Config.temperatureUnitNumber', true, { + type: 'number', + role: 'state', + name: 'VALUE', + }); + } + // Trigger DP for hiddenCards (with hiddenByTrigger) + if (existsObject(NSPanel_Path + 'Config.hiddenCards') == false) { + await createStateAsync(NSPanel_Path + 'Config.hiddenCards', false, { type: 'boolean', write: true }); + setObject(AliasPath + 'Config.hiddenCards', { type: 'channel', common: { role: 'socket', name: 'hiddenCards' }, native: {} }); + await createAliasAsync(AliasPath + 'Config.hiddenCards.ACTUAL', NSPanel_Path + 'Config.hiddenCards', true, { + type: 'boolean', + role: 'switch', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'Config.hiddenCards.SET', NSPanel_Path + 'Config.hiddenCards', true, { + type: 'boolean', + role: 'switch', + name: 'SET', + }); + } else { + getState(NSPanel_Path + 'Config.hiddenCards').val ? log('hidden Cards activated', 'info') : log('hidden Cards disabled', 'info'); } } - } catch (err: any) { - log('error at function InitConfigParameters: ' + err.message, 'warn'); + } catch (err: any) { + log('error at function InitConfigParameters: ' + err.message, 'warn'); } } InitConfigParameters(); -on({id: [NSPanel_Path + 'Config.ScripgtDebugStatus'], change: "ne"}, async function (obj) { +// Trigger for hidden Cards - if hiddenByTrigger is true/false +on({ id: [NSPanel_Path + 'Config.hiddenCards'], change: 'ne' }, async function (obj) { try { - obj.state.val ? log('Debug mode activated', 'info') : log('Debug mode disabled', 'info'); - Debug = obj.state.val - } catch (err: any) { - log('error at Trigger ScripgtDebugStatus: ' + err.message, 'warn'); + obj.state.val ? log('hidden Cards activated', 'info') : log('hidden Cards disabled', 'info'); + valueHiddenCards = obj.state.val; + if (obj.state.val) { + activePage = config.pages[0]; + pageId = 0; + GeneratePage(activePage); + } + } catch (err: any) { + log('error at Trigger hidden Cards Status: ' + err.message, 'warn'); } }); -on({id: [NSPanel_Path + 'Config.localeNumber', - NSPanel_Path + 'Config.temperatureUnitNumber'], change: "ne"}, async function (obj) { +on({ id: [NSPanel_Path + 'Config.ScripgtDebugStatus'], change: 'ne' }, async function (obj) { + try { + obj.state.val ? log('Debug mode activated', 'info') : log('Debug mode disabled', 'info'); + Debug = obj.state.val; + } catch (err: any) { + log('error at Trigger ScripgtDebugStatus: ' + err.message, 'warn'); + } +}); + +on({ id: [NSPanel_Path + 'Config.localeNumber', NSPanel_Path + 'Config.temperatureUnitNumber'], change: 'ne' }, async function (obj) { try { if (obj.id == NSPanel_Path + 'Config.localeNumber') { - let localesList = [ 'en-US', 'de-DE', 'nl-NL', 'da-DK', 'es-ES', 'fr-FR', 'it-IT', 'ru-RU', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'af-ZA', 'ar-SY', - 'bg-BG', 'ca-ES', 'cs-CZ', 'el-GR', 'et-EE', 'fa-IR', 'fi-FI', 'he-IL', 'hr-xx', 'hu-HU', 'hy-AM', 'id-ID', 'is-IS', 'lb-xx', - 'lt-LT', 'ro-RO', 'sk-SK', 'sl-SI', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-TW']; + let localesList = [ + 'en-US', + 'de-DE', + 'nl-NL', + 'da-DK', + 'es-ES', + 'fr-FR', + 'it-IT', + 'ru-RU', + 'nb-NO', + 'nn-NO', + 'pl-PL', + 'pt-PT', + 'af-ZA', + 'ar-SY', + 'bg-BG', + 'ca-ES', + 'cs-CZ', + 'el-GR', + 'et-EE', + 'fa-IR', + 'fi-FI', + 'he-IL', + 'hr-xx', + 'hu-HU', + 'hy-AM', + 'id-ID', + 'is-IS', + 'lb-xx', + 'lt-LT', + 'ro-RO', + 'sk-SK', + 'sl-SI', + 'sv-SE', + 'th-TH', + 'tr-TR', + 'uk-UA', + 'vi-VN', + 'zh-CN', + 'zh-TW', + ]; setStateAsync(NSPanel_Path + 'Config.locale', localesList[obj.state.val]); SendDate(); } @@ -1383,43 +1552,43 @@ on({id: [NSPanel_Path + 'Config.localeNumber', let tempunitList = ['°C', '°F', 'K']; setStateAsync(NSPanel_Path + 'Config.temperatureUnit', tempunitList[obj.state.val]); } - } catch (err: any) { - log('error at Trigger temperatureUnitNumber + localeNumber: ' + err.message, 'warn'); + } catch (err: any) { + log('error at Trigger temperatureUnitNumber + localeNumber: ' + err.message, 'warn'); } }); //switch for Screensaver 1 and Screensaver 2 async function Init_ScreensaverAdvanced() { try { - if (existsState(NSPanel_Path + 'Config.Screensaver.ScreensaverAdvanced') == false ) { + if (existsState(NSPanel_Path + 'Config.Screensaver.ScreensaverAdvanced') == false) { await createStateAsync(NSPanel_Path + 'Config.Screensaver.ScreensaverAdvanced', false, true, { type: 'boolean', write: true }); } - } catch (err: any) { - log('error at function Init_ScreensaverAdvanced: ' + err.message, 'warn'); + } catch (err: any) { + log('error at function Init_ScreensaverAdvanced: ' + err.message, 'warn'); } } Init_ScreensaverAdvanced(); // checks whether setObjects() is available for the instance (true/false) -function CheckEnableSetObject() { - var enableSetObject = getObject("system.adapter.javascript." + instance).native.enableSetObject; +function CheckEnableSetObject() { + var enableSetObject = getObject('system.adapter.javascript.' + instance).native.enableSetObject; return enableSetObject; } //switch BackgroundColors for Screensaver Indicators async function Init_ActivePageData() { try { - if (existsState(NSPanel_Path + 'ActivePage.heading') == false ) { + if (existsState(NSPanel_Path + 'ActivePage.heading') == false) { await createStateAsync(NSPanel_Path + 'ActivePage.heading', '', true, { type: 'string', write: false }); } - if (existsState(NSPanel_Path + 'ActivePage.type') == false ) { + if (existsState(NSPanel_Path + 'ActivePage.type') == false) { await createStateAsync(NSPanel_Path + 'ActivePage.type', '', true, { type: 'string', write: false }); } - if (existsState(NSPanel_Path + 'ActivePage.id0') == false ) { + if (existsState(NSPanel_Path + 'ActivePage.id0') == false) { await createStateAsync(NSPanel_Path + 'ActivePage.id0', '', true, { type: 'string', write: false }); } - } catch (err: any) { - log('error at function Init_ActivePageData: ' + err.message, 'warn'); + } catch (err: any) { + log('error at function Init_ActivePageData: ' + err.message, 'warn'); } } Init_ActivePageData(); @@ -1429,59 +1598,59 @@ async function Init_Screensaver_Backckground_Color_Switch() { try { const objDef: iobJS.StateObject = { _id: '', - type: "state", + type: 'state', common: { - type: "number", - name: "Color Indicator", - role: "level", - states: {0:'black', 1:'red', 2:'green', 3:'attention', 4: 'pink', 5: 'dark red'}, + type: 'number', + name: 'Color Indicator', + role: 'level', + states: { 0: 'black', 1: 'red', 2: 'green', 3: 'attention', 4: 'pink', 5: 'dark red' }, read: true, - write: true + write: true, }, - "native": {}, + native: {}, }; - await extendObjectAsync(NSPanel_Path + 'ScreensaverInfo.bgColorIndicator', objDef) + await extendObjectAsync(NSPanel_Path + 'ScreensaverInfo.bgColorIndicator', objDef); if (await existsStateAsync(NSPanel_Path + 'ScreensaverInfo.bgColorIndicator')) { const obj = await getStateAsync(NSPanel_Path + 'ScreensaverInfo.bgColorIndicator'); if (obj && obj.val !== null && obj.val !== undefined) { bgColorScrSaver = obj.val; } else { - setStateAsync(NSPanel_Path + 'ScreensaverInfo.bgColorIndicator', bgColorScrSaver) + setStateAsync(NSPanel_Path + 'ScreensaverInfo.bgColorIndicator', bgColorScrSaver); } } - } catch (err: any) { - log('error at function Init_Screensaver_Backckground_Color_Switch: ' + err.message, 'warn'); + } catch (err: any) { + log('error at function Init_Screensaver_Backckground_Color_Switch: ' + err.message, 'warn'); } } Init_Screensaver_Backckground_Color_Switch(); -on({id: NSPanel_Path + 'ScreensaverInfo.bgColorIndicator', change: "ne"}, async function (obj) { +on({ id: NSPanel_Path + 'ScreensaverInfo.bgColorIndicator', change: 'ne' }, async function (obj) { try { bgColorScrSaver = obj.state.val; if (bgColorScrSaver < 6) { HandleScreensaverUpdate(); } - } catch (err: any) { - log('error at trigger bgColorIndicator: ' + err.message, 'warn'); + } catch (err: any) { + log('error at trigger bgColorIndicator: ' + err.message, 'warn'); } }); // switch selection of screensaver layout -on({id: NSPanel_Path + 'Config.Screensaver.ScreensaverAdvanced', change: "ne"}, async function (obj) { +on({ id: NSPanel_Path + 'Config.Screensaver.ScreensaverAdvanced', change: 'ne' }, async function (obj) { try { - if (obj.state.val) setState( NSPanel_Path + 'Config.Screensaver.alternativeScreensaverLayout', false ); + if (obj.state.val) setState(NSPanel_Path + 'Config.Screensaver.alternativeScreensaverLayout', false); //setState(config.panelSendTopic, 'pageType~pageStartup'); - } catch (err: any) { - log('error at trigger Screensaver Advanced: ' + err.message, 'warn'); + } catch (err: any) { + log('error at trigger Screensaver Advanced: ' + err.message, 'warn'); } }); -on({id: NSPanel_Path + 'Config.Screensaver.alternativeScreensaverLayout', change: "ne"}, async function (obj) { +on({ id: NSPanel_Path + 'Config.Screensaver.alternativeScreensaverLayout', change: 'ne' }, async function (obj) { try { - if (obj.state.val) setState( NSPanel_Path + 'Config.Screensaver.ScreensaverAdvanced', false ); + if (obj.state.val) setState(NSPanel_Path + 'Config.Screensaver.ScreensaverAdvanced', false); //setState(config.panelSendTopic, 'pageType~pageStartup'); - } catch (err: any) { - log('error at trigger Screensaver Alternativ: ' + err.message, 'warn'); + } catch (err: any) { + log('error at trigger Screensaver Alternativ: ' + err.message, 'warn'); } }); @@ -1490,11 +1659,11 @@ async function Init_bExit_Page_Change() { try { alwaysOn = false; pageCounter = 0; - if (existsState(NSPanel_Path + 'ScreensaverInfo.bExitPage') == false ) { + if (existsState(NSPanel_Path + 'ScreensaverInfo.bExitPage') == false) { await createStateAsync(NSPanel_Path + 'ScreensaverInfo.bExitPage', -1, true, { type: 'number', write: true }); } - } catch (err: any) { - log('error at function Init_bExit_Page_Change: ' + err.message, 'warn'); + } catch (err: any) { + log('error at function Init_bExit_Page_Change: ' + err.message, 'warn'); } } Init_bExit_Page_Change(); @@ -1502,11 +1671,11 @@ Init_bExit_Page_Change(); //Dim mode via trigger via motion detector async function Init_Dimmode_Trigger() { try { - if (existsState(NSPanel_Path + 'ScreensaverInfo.Trigger_Dimmode') == false ) { + if (existsState(NSPanel_Path + 'ScreensaverInfo.Trigger_Dimmode') == false) { await createStateAsync(NSPanel_Path + 'ScreensaverInfo.Trigger_Dimmode', false, true, { type: 'boolean', write: true }); } - } catch (err: any) { - log('error at function Init_Dimmode_Trigger: ' + err.message, 'warn'); + } catch (err: any) { + log('error at function Init_Dimmode_Trigger: ' + err.message, 'warn'); } } Init_Dimmode_Trigger(); @@ -1514,15 +1683,22 @@ Init_Dimmode_Trigger(); async function InitActiveBrightness() { try { if (isSetOptionActive) { - if (existsState(NSPanel_Path + 'ScreensaverInfo.activeBrightness') == false || - existsState(NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness') == false) { - await createStateAsync(NSPanel_Path + 'ScreensaverInfo.activeBrightness', 100, { type: 'number', write: true }); + if (existsState(NSPanel_Path + 'ScreensaverInfo.activeBrightness') == false || existsState(NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness') == false) { + await createStateAsync(NSPanel_Path + 'ScreensaverInfo.activeBrightness', 100, { type: 'number', write: true }); await createStateAsync(NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness', -1, { type: 'number', write: true }); } //Create Alias activeBrightness - setObject(AliasPath + 'ScreensaverInfo.activeBrightness', {type: 'channel', common: {role: 'slider', name:'activeBrightness'}, native: {}}); - await createAliasAsync(AliasPath + 'ScreensaverInfo.activeBrightness.ACTUAL', NSPanel_Path + 'ScreensaverInfo.activeBrightness', true, { type: 'number', role: 'value', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'ScreensaverInfo.activeBrightness.SET', NSPanel_Path + 'ScreensaverInfo.activeBrightness', true, { type: 'number', role: 'level', name: 'SET' }); + setObject(AliasPath + 'ScreensaverInfo.activeBrightness', { type: 'channel', common: { role: 'slider', name: 'activeBrightness' }, native: {} }); + await createAliasAsync(AliasPath + 'ScreensaverInfo.activeBrightness.ACTUAL', NSPanel_Path + 'ScreensaverInfo.activeBrightness', true, { + type: 'number', + role: 'value', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'ScreensaverInfo.activeBrightness.SET', NSPanel_Path + 'ScreensaverInfo.activeBrightness', true, { + type: 'number', + role: 'level', + name: 'SET', + }); } } catch (err: any) { log('error at function InitActiveBrightness: ' + err.message, 'warn'); @@ -1530,7 +1706,7 @@ async function InitActiveBrightness() { } InitActiveBrightness(); -on({id: [NSPanel_Path + 'ScreensaverInfo.activeBrightness'], change: 'ne'}, async function (obj) { +on({ id: [NSPanel_Path + 'ScreensaverInfo.activeBrightness'], change: 'ne' }, async function (obj) { try { let active = getState(NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness').val ?? -1; if (obj.state.val >= 0 || obj.state.val <= 100) { @@ -1538,12 +1714,12 @@ on({id: [NSPanel_Path + 'ScreensaverInfo.activeBrightness'], change: 'ne'}, asyn SendToPanel({ payload: 'dimmode~' + active + '~' + obj.state.val + '~' + rgb_dec565(config.defaultBackgroundColor) + '~' + rgb_dec565(globalTextColor) + '~' + Sliders2 }); InitDimmode(); } - } catch (err:any) { - log('error at trigger activeBrightness: ' + err.message, 'warn'); + } catch (err: any) { + log('error at trigger activeBrightness: ' + err.message, 'warn'); } }); -on({id: [NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness'], change: "ne"}, async function (obj) { +on({ id: [NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness'], change: 'ne' }, async function (obj) { try { let active = getState(NSPanel_Path + 'ScreensaverInfo.activeBrightness').val ?? 80; if (obj.state.val != null && obj.state.val != -1) { @@ -1555,7 +1731,7 @@ on({id: [NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness'], change: "ne" useMediaEvents = false; screensaverEnabled = true; InitDimmode(); - HandleMessage('event', 'startup',undefined, undefined); + HandleMessage('event', 'startup', undefined, undefined); } else { log('action at trigger activeDimmodeBrightness: ' + obj.state.val + ' - activeBrightness: ' + active, 'info'); SendToPanel({ payload: 'dimmode~' + obj.state.val + '~' + active + '~' + rgb_dec565(config.defaultBackgroundColor) + '~' + rgb_dec565(globalTextColor) + '~' + Sliders2 }); @@ -1566,14 +1742,14 @@ on({id: [NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness'], change: "ne" useMediaEvents = false; screensaverEnabled = true; InitDimmode(); - HandleMessage('event', 'startup',undefined, undefined); + HandleMessage('event', 'startup', undefined, undefined); } } catch (err: any) { log('error at trigger activeDimmodeBrightness: ' + err.message, 'warn'); } }); -on({id: String(NSPanel_Path) + 'ScreensaverInfo.Trigger_Dimmode', change: "ne"}, async function (obj) { +on({ id: String(NSPanel_Path) + 'ScreensaverInfo.Trigger_Dimmode', change: 'ne' }, async function (obj) { try { let active = getState(NSPanel_Path + 'ScreensaverInfo.activeBrightness').val ?? 80; if (obj.state.val) { @@ -1581,8 +1757,8 @@ on({id: String(NSPanel_Path) + 'ScreensaverInfo.Trigger_Dimmode', change: "ne"}, } else { InitDimmode(); } - } catch (err: any) { - log('error at trigger Trigger_Dimmode: ' + err.message, 'warn'); + } catch (err: any) { + log('error at trigger Trigger_Dimmode: ' + err.message, 'warn'); } }); @@ -1590,7 +1766,7 @@ async function InitRebootPanel() { try { if (existsState(NSPanel_Path + 'Config.rebootNSPanel') == false) { await createStateAsync(NSPanel_Path + 'Config.rebootNSPanel', false, { type: 'boolean', write: true }); - setObject(AliasPath + 'Config.rebootNSPanel', {type: 'channel', common: {role: 'button', name:'Reboot NSPanel'}, native: {}}); + setObject(AliasPath + 'Config.rebootNSPanel', { type: 'channel', common: { role: 'button', name: 'Reboot NSPanel' }, native: {} }); await createAliasAsync(AliasPath + 'Config.rebootNSPanel.SET', NSPanel_Path + 'Config.rebootNSPanel', true, { type: 'boolean', role: 'state', name: 'SET' }); } } catch (err: any) { @@ -1599,28 +1775,29 @@ async function InitRebootPanel() { } InitRebootPanel(); -on({id: AliasPath + 'Config.rebootNSPanel.SET', change: "any"}, async function (obj) { +on({ id: AliasPath + 'Config.rebootNSPanel.SET', change: 'any' }, async function (obj) { if (obj.state.val) { try { let urlString = `http://${get_current_tasmota_ip_address()}/cm?cmnd=Backlog Restart 1`; if (tasmota_web_admin_password != '') { urlString = `http://${get_current_tasmota_ip_address()}/cm?user=${tasmota_web_admin_user}&password=${tasmota_web_admin_password}&cmnd=Backlog Restart 1;`; } - axios.get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) .then(async function (response) { if (response.status === 200) { - SendToPanel({ payload: 'pageType~pageStartup' }); + SendToPanel({ payload: 'pageType~pageStartup' }); log('Tasmota Reboot', 'info'); setStateAsync(AliasPath + 'Config.rebootNSPanel.SET', false); - log("Name: " + name, 'info'); - log("Instanz: " + instance, 'info'); + log('Name: ' + name, 'info'); + log('Instanz: ' + instance, 'info'); } else { log('Axios Status - Requesting locales: ' + response.state, 'warn'); } }) .catch(function (error) { if (error.code === 'EHOSTUNREACH') { - log(`Can't connect to display!`, 'warn') + log(`Can't connect to display!`, 'warn'); } else log(error, 'warn'); }) .finally(function () { @@ -1641,12 +1818,24 @@ async function InitUpdateDatapoints() { await createStateAsync(NSPanel_Path + 'Config.Update.UpdateTasmota', false, { type: 'boolean', write: true }); await createStateAsync(NSPanel_Path + 'Config.Update.UpdateBerry', false, { type: 'boolean', write: true }); await createStateAsync(NSPanel_Path + 'Config.Update.UpdateNextion', false, { type: 'boolean', write: true }); - setObject(AliasPath + 'Config.Update.UpdateTasmota', {type: 'channel', common: {role: 'button', name:'Tassmota update'}, native: {}}); - setObject(AliasPath + 'Config.Update.UpdateBerry', {type: 'channel', common: {role: 'button', name:'Berry-Driver update'}, native: {}}); - setObject(AliasPath + 'Config.Update.UpdateNextion', {type: 'channel', common: {role: 'button', name:'Nextion TFT update'}, native: {}}); - await createAliasAsync(AliasPath + 'Config.Update.UpdateTasmota.SET', NSPanel_Path + 'Config.Update.UpdateTasmota', true, { type: 'boolean', role: 'state', name: 'SET' }); - await createAliasAsync(AliasPath + 'Config.Update.UpdateBerry.SET', NSPanel_Path + 'Config.Update.UpdateBerry', true, { type: 'boolean', role: 'state', name: 'SET' }); - await createAliasAsync(AliasPath + 'Config.Update.UpdateNextion.SET', NSPanel_Path + 'Config.Update.UpdateNextion', true, { type: 'boolean', role: 'state', name: 'SET' }); + setObject(AliasPath + 'Config.Update.UpdateTasmota', { type: 'channel', common: { role: 'button', name: 'Tassmota update' }, native: {} }); + setObject(AliasPath + 'Config.Update.UpdateBerry', { type: 'channel', common: { role: 'button', name: 'Berry-Driver update' }, native: {} }); + setObject(AliasPath + 'Config.Update.UpdateNextion', { type: 'channel', common: { role: 'button', name: 'Nextion TFT update' }, native: {} }); + await createAliasAsync(AliasPath + 'Config.Update.UpdateTasmota.SET', NSPanel_Path + 'Config.Update.UpdateTasmota', true, { + type: 'boolean', + role: 'state', + name: 'SET', + }); + await createAliasAsync(AliasPath + 'Config.Update.UpdateBerry.SET', NSPanel_Path + 'Config.Update.UpdateBerry', true, { + type: 'boolean', + role: 'state', + name: 'SET', + }); + await createAliasAsync(AliasPath + 'Config.Update.UpdateNextion.SET', NSPanel_Path + 'Config.Update.UpdateNextion', true, { + type: 'boolean', + role: 'state', + name: 'SET', + }); } } } catch (err: any) { @@ -1655,9 +1844,7 @@ async function InitUpdateDatapoints() { } InitUpdateDatapoints(); -on({id: [NSPanel_Path + 'Config.Update.UpdateTasmota', - NSPanel_Path + 'Config.Update.UpdateBerry', - NSPanel_Path + 'Config.Update.UpdateNextion'], change: "any"}, async function (obj) { +on({ id: [NSPanel_Path + 'Config.Update.UpdateTasmota', NSPanel_Path + 'Config.Update.UpdateBerry', NSPanel_Path + 'Config.Update.UpdateNextion'], change: 'any' }, async function (obj) { try { switch (obj.id) { case NSPanel_Path + 'Config.Update.UpdateTasmota': @@ -1665,16 +1852,16 @@ on({id: [NSPanel_Path + 'Config.Update.UpdateTasmota', update_tasmota_firmware(); break; case NSPanel_Path + 'Config.Update.UpdateBerry': - if (Debug) log('Berry Driver Update durchführen', 'info') + if (Debug) log('Berry Driver Update durchführen', 'info'); update_berry_driver_version(); break; case NSPanel_Path + 'Config.Update.UpdateNextion': - if (Debug) log('FlashNextion durchführen', 'info') + if (Debug) log('FlashNextion durchführen', 'info'); update_tft_firmware(); break; - } - } catch (err: any) { - log('error at Trigger Update Firmware: ' + err.message, 'warn'); + } + } catch (err: any) { + log('error at Trigger Update Firmware: ' + err.message, 'warn'); } }); @@ -1682,21 +1869,20 @@ on({id: [NSPanel_Path + 'Config.Update.UpdateTasmota', async function Init_Relays() { try { if (isSetOptionActive) { - if (existsState(NSPanel_Path + 'Relay.1') == false || - existsState(NSPanel_Path + 'Relay.2') == false) { + if (existsState(NSPanel_Path + 'Relay.1') == false || existsState(NSPanel_Path + 'Relay.2') == false) { await createStateAsync(NSPanel_Path + 'Relay.1', true, { type: 'boolean', write: true }); await createStateAsync(NSPanel_Path + 'Relay.2', true, { type: 'boolean', write: true }); } - setObject(AliasPath + 'Relay.1', {type: 'channel', common: {role: 'socket', name:'Relay.1'}, native: {}}); + setObject(AliasPath + 'Relay.1', { type: 'channel', common: { role: 'socket', name: 'Relay.1' }, native: {} }); await createAliasAsync(AliasPath + 'Relay.1.ACTUAL', NSPanel_Path + 'Relay.1', true, { type: 'boolean', role: 'switch', name: 'ACTUAL' }); await createAliasAsync(AliasPath + 'Relay.1.SET', NSPanel_Path + 'Relay.1', true, { type: 'boolean', role: 'switch', name: 'SET' }); //Create Alias alternateMRIconSize 2 - setObject(AliasPath + 'Relay.2', {type: 'channel', common: {role: 'socket', name:'Relay.2'}, native: {}}); + setObject(AliasPath + 'Relay.2', { type: 'channel', common: { role: 'socket', name: 'Relay.2' }, native: {} }); await createAliasAsync(AliasPath + 'Relay.2.ACTUAL', NSPanel_Path + 'Relay.2', true, { type: 'boolean', role: 'switch', name: 'ACTUAL' }); await createAliasAsync(AliasPath + 'Relay.2.SET', NSPanel_Path + 'Relay.2', true, { type: 'boolean', role: 'switch', name: 'SET' }); } - } catch (err: any) { - log('error at function Init_Relays: ' + err.message, 'warn'); + } catch (err: any) { + log('error at function Init_Relays: ' + err.message, 'warn'); } } Init_Relays(); @@ -1705,22 +1891,37 @@ Init_Relays(); async function InitAlternateMRIconsSize() { try { if (isSetOptionActive) { - if (existsState(NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.1') == false || - existsState(NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.2') == false) { + if (existsState(NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.1') == false || existsState(NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.2') == false) { await createStateAsync(NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.1', false, { type: 'boolean', write: true }); await createStateAsync(NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.2', false, { type: 'boolean', write: true }); } //Create Alias alternateMRIconSize 1 - setObject(AliasPath + 'Config.MRIcons.alternateMRIconSize.1', {type: 'channel', common: {role: 'socket', name:'alternateMRIconSize.1'}, native: {}}); - await createAliasAsync(AliasPath + 'Config.MRIcons.alternateMRIconSize.1.ACTUAL', NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.1', true, { type: 'boolean', role: 'switch', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Config.MRIcons.alternateMRIconSize.1.SET', NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.1', true, { type: 'boolean', role: 'switch', name: 'SET' }); + setObject(AliasPath + 'Config.MRIcons.alternateMRIconSize.1', { type: 'channel', common: { role: 'socket', name: 'alternateMRIconSize.1' }, native: {} }); + await createAliasAsync(AliasPath + 'Config.MRIcons.alternateMRIconSize.1.ACTUAL', NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.1', true, { + type: 'boolean', + role: 'switch', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'Config.MRIcons.alternateMRIconSize.1.SET', NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.1', true, { + type: 'boolean', + role: 'switch', + name: 'SET', + }); //Create Alias alternateMRIconSize 2 - setObject(AliasPath + 'Config.MRIcons.alternateMRIconSize.2', {type: 'channel', common: {role: 'socket', name:'alternateMRIconSize.2'}, native: {}}); - await createAliasAsync(AliasPath + 'Config.MRIcons.alternateMRIconSize.2.ACTUAL', NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.2', true, { type: 'boolean', role: 'switch', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Config.MRIcons.alternateMRIconSize.2.SET', NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.2', true, { type: 'boolean', role: 'switch', name: 'SET' }); + setObject(AliasPath + 'Config.MRIcons.alternateMRIconSize.2', { type: 'channel', common: { role: 'socket', name: 'alternateMRIconSize.2' }, native: {} }); + await createAliasAsync(AliasPath + 'Config.MRIcons.alternateMRIconSize.2.ACTUAL', NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.2', true, { + type: 'boolean', + role: 'switch', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'Config.MRIcons.alternateMRIconSize.2.SET', NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.2', true, { + type: 'boolean', + role: 'switch', + name: 'SET', + }); } - } catch (err: any) { - log('error at function InitAlternateMRIconsSize: ' + err.message, 'warn'); + } catch (err: any) { + log('error at function InitAlternateMRIconsSize: ' + err.message, 'warn'); } } InitAlternateMRIconsSize(); @@ -1729,33 +1930,49 @@ InitAlternateMRIconsSize(); async function InitDateformat() { try { if (isSetOptionActive) { - if (existsState(NSPanel_Path + 'Config.Dateformat.weekday') == false || + if ( + existsState(NSPanel_Path + 'Config.Dateformat.weekday') == false || existsState(NSPanel_Path + 'Config.Dateformat.month') == false || - existsState(NSPanel_Path + 'Config.Dateformat.customFormat') == false) { + existsState(NSPanel_Path + 'Config.Dateformat.customFormat') == false + ) { await createStateAsync(NSPanel_Path + 'Config.Dateformat.weekday', 'long', { type: 'string', write: true }); await createStateAsync(NSPanel_Path + 'Config.Dateformat.month', 'long', { type: 'string', write: true }); await createStateAsync(NSPanel_Path + 'Config.Dateformat.customFormat', '', { type: 'string', write: true }); } - if (existsState(NSPanel_Path + 'Config.Dateformat.Switch.weekday') == false || - existsState(NSPanel_Path + 'Config.Dateformat.Switch.month') == false) { + if (existsState(NSPanel_Path + 'Config.Dateformat.Switch.weekday') == false || existsState(NSPanel_Path + 'Config.Dateformat.Switch.month') == false) { await createStateAsync(NSPanel_Path + 'Config.Dateformat.Switch.weekday', true, { type: 'boolean', write: true }); await createStateAsync(NSPanel_Path + 'Config.Dateformat.Switch.month', true, { type: 'boolean', write: true }); - setObject(AliasPath + 'Config.Dateformat.Switch.weekday', {type: 'channel', common: {role: 'socket', name:'Dateformat Switch weekday'}, native: {}}); - await createAliasAsync(AliasPath + 'Config.Dateformat.Switch.weekday.ACTUAL', NSPanel_Path + 'Config.Dateformat.Switch.weekday', true, { type: 'boolean', role: 'switch', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Config.Dateformat.Switch.weekday.SET', NSPanel_Path + 'Config.Dateformat.Switch.weekday', true, { type: 'boolean', role: 'switch', name: 'SET' }); - setObject(AliasPath + 'Config.Dateformat.Switch.month', {type: 'channel', common: {role: 'socket', name:'Dateformat Switch month'}, native: {}}); - await createAliasAsync(AliasPath + 'Config.Dateformat.Switch.month.ACTUAL', NSPanel_Path + 'Config.Dateformat.Switch.month', true, { type: 'boolean', role: 'switch', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Config.Dateformat.Switch.month.SET', NSPanel_Path + 'Config.Dateformat.Switch.month', true, { type: 'boolean', role: 'switch', name: 'SET' }); + setObject(AliasPath + 'Config.Dateformat.Switch.weekday', { type: 'channel', common: { role: 'socket', name: 'Dateformat Switch weekday' }, native: {} }); + await createAliasAsync(AliasPath + 'Config.Dateformat.Switch.weekday.ACTUAL', NSPanel_Path + 'Config.Dateformat.Switch.weekday', true, { + type: 'boolean', + role: 'switch', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'Config.Dateformat.Switch.weekday.SET', NSPanel_Path + 'Config.Dateformat.Switch.weekday', true, { + type: 'boolean', + role: 'switch', + name: 'SET', + }); + setObject(AliasPath + 'Config.Dateformat.Switch.month', { type: 'channel', common: { role: 'socket', name: 'Dateformat Switch month' }, native: {} }); + await createAliasAsync(AliasPath + 'Config.Dateformat.Switch.month.ACTUAL', NSPanel_Path + 'Config.Dateformat.Switch.month', true, { + type: 'boolean', + role: 'switch', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'Config.Dateformat.Switch.month.SET', NSPanel_Path + 'Config.Dateformat.Switch.month', true, { + type: 'boolean', + role: 'switch', + name: 'SET', + }); } - } - } catch (err: any) { - log('error at function InitDateformat: ' + err.message, 'warn'); + } + } catch (err: any) { + log('error at function InitDateformat: ' + err.message, 'warn'); } } InitDateformat(); //Control Dateformat short/long from DP's -on({id: [String(NSPanel_Path) + 'Config.Dateformat.Switch.weekday', - String(NSPanel_Path) + 'Config.Dateformat.Switch.month'], change: "ne"}, async function (obj) { +on({ id: [String(NSPanel_Path) + 'Config.Dateformat.Switch.weekday', String(NSPanel_Path) + 'Config.Dateformat.Switch.month'], change: 'ne' }, async function (obj) { try { if (obj.id == NSPanel_Path + 'Config.Dateformat.Switch.weekday') { if (getState(NSPanel_Path + 'Config.Dateformat.Switch.weekday').val) { @@ -1771,29 +1988,30 @@ on({id: [String(NSPanel_Path) + 'Config.Dateformat.Switch.weekday', } } SendDate(); - } catch (err: any) { - log('error at Trigger Config.Dateformat: ' + err.message, 'warn'); + } catch (err: any) { + log('error at Trigger Config.Dateformat: ' + err.message, 'warn'); } }); //Set Relays from Tasmota -const NSPanelStatTopic = NSPanelSendTopic.replace('.cmnd.','.stat.').replace(/\.CustomSend$/g,'.'); -on({id: [String(NSPanelStatTopic) + 'POWER1',String(NSPanelStatTopic) + 'POWER2'], change: "ne"}, (obj) => { - if (!obj || !obj.id) return - const n = obj.id.substring(obj.id.length-1); - if ( n === '1' || n === '2') { +const NSPanelStatTopic = NSPanelSendTopic.replace('.cmnd.', '.stat.').replace(/\.CustomSend$/g, '.'); +on({ id: [String(NSPanelStatTopic) + 'POWER1', String(NSPanelStatTopic) + 'POWER2'], change: 'ne' }, (obj) => { + if (!obj || !obj.id) return; + const n = obj.id.substring(obj.id.length - 1); + if (n === '1' || n === '2') { if (getState(NSPanel_Path + 'Relay.' + n).val != obj.state.val) { setState(NSPanel_Path + 'Relay.' + n, obj.state.val == 'ON' ? true : false, true); } } -}) +}); //Control Relays from DP's -on({id: [String(NSPanel_Path) + 'Relay.1',String(NSPanel_Path) + 'Relay.2'], change: "ne", ack: false}, async function (obj) { +on({ id: [String(NSPanel_Path) + 'Relay.1', String(NSPanel_Path) + 'Relay.2'], change: 'ne', ack: false }, async function (obj) { try { - let Button = obj.id!.split('.'); - let urlString: string = ['http://',get_current_tasmota_ip_address(),'/cm?cmnd=Power',Button[Button.length - 1],' ',(obj.state ? obj.state.val : "")].join(''); + let Button = obj.id!.split('.'); + let urlString: string = ['http://', get_current_tasmota_ip_address(), '/cm?cmnd=Power', Button[Button.length - 1], ' ', obj.state ? obj.state.val : ''].join(''); - axios.get(urlString) + axios + .get(urlString) .then(async function (response) { if (response.status === 200) { if (Debug) { @@ -1803,25 +2021,24 @@ on({id: [String(NSPanel_Path) + 'Relay.1',String(NSPanel_Path) + 'Relay.2'], cha }) .catch(function (error) { if (error.code === 'EHOSTUNREACH') { - log(`Can't connect to display!`, 'warn') + log(`Can't connect to display!`, 'warn'); } else log(error, 'warn'); - }) - - } catch (err: any) { - log('error at Trigger Relay1/2: ' + err.message, 'warn'); + }); + } catch (err: any) { + log('error at Trigger Relay1/2: ' + err.message, 'warn'); } }); -async function SubscribeMRIcons () { +async function SubscribeMRIcons() { try { let arr = config.mrIcon1ScreensaverEntity.ScreensaverEntity != null ? [config.mrIcon1ScreensaverEntity.ScreensaverEntity] : []; arr = config.mrIcon1ScreensaverEntity.ScreensaverEntityValue != null ? [...arr, config.mrIcon1ScreensaverEntity.ScreensaverEntityValue] : arr; if (arr.length > 0) { - on({id: arr, change: "ne"}, async function (obj) { - if (obj.id!.substring(0,4) == 'mqtt') { - let Button = obj.id!.split('.'); - if (getState(NSPanel_Path + 'Relay.' + Button[Button.length - 1].substring(5,6)).val != obj.state.val) { - await setStateAsync(NSPanel_Path + 'Relay.' + Button[Button.length - 1].substring(5,6), obj.state.val == 'ON' ? true : false); + on({ id: arr, change: 'ne' }, async function (obj) { + if (obj.id!.substring(0, 4) == 'mqtt') { + let Button = obj.id!.split('.'); + if (getState(NSPanel_Path + 'Relay.' + Button[Button.length - 1].substring(5, 6)).val != obj.state.val) { + await setStateAsync(NSPanel_Path + 'Relay.' + Button[Button.length - 1].substring(5, 6), obj.state.val == 'ON' ? true : false); } } else { HandleScreensaverStatusIcons(); @@ -1831,41 +2048,49 @@ async function SubscribeMRIcons () { arr = config.mrIcon2ScreensaverEntity.ScreensaverEntity != null ? [config.mrIcon2ScreensaverEntity.ScreensaverEntity] : []; arr = config.mrIcon2ScreensaverEntity.ScreensaverEntityValue != null ? [...arr, config.mrIcon2ScreensaverEntity.ScreensaverEntityValue] : arr; if (arr.length > 0) { - on({id: arr, change: "ne"}, async function (obj) { - if (obj.id!.substring(0,4) == 'mqtt') { - let Button = obj.id!.split('.'); - if (getState(NSPanel_Path + 'Relay.' + Button[Button.length - 1].substring(5,6)).val != obj.state.val) { - await setStateAsync(NSPanel_Path + 'Relay.' + Button[Button.length - 1].substring(5,6), obj.state.val == 'ON' ? true : false); + on({ id: arr, change: 'ne' }, async function (obj) { + if (obj.id!.substring(0, 4) == 'mqtt') { + let Button = obj.id!.split('.'); + if (getState(NSPanel_Path + 'Relay.' + Button[Button.length - 1].substring(5, 6)).val != obj.state.val) { + await setStateAsync(NSPanel_Path + 'Relay.' + Button[Button.length - 1].substring(5, 6), obj.state.val == 'ON' ? true : false); } } else { HandleScreensaverStatusIcons(); } }); } - } catch (err: any) { - log('error at function SubscribeMRIcons: ' + err.message, 'warn'); + } catch (err: any) { + log('error at function SubscribeMRIcons: ' + err.message, 'warn'); } } SubscribeMRIcons(); // Create atomatically Wheather-Alias, if exists accuweather.0. and is not exists Config-Wheather-Alias -async function CreateWeatherAlias () { +async function CreateWeatherAlias() { try { if (autoCreateAlias) { if (weatherAdapterInstance == 'daswetter.' + weatherAdapterInstanceNumber + '.') { try { if (isSetOptionActive) { if (!existsState(config.weatherEntity + '.ICON') && existsState('daswetter.' + weatherAdapterInstanceNumber + '.NextHours.Location_1.Day_1.current.symbol_value')) { - log('Weather alias for daswetter.' + weatherAdapterInstanceNumber + '. does not exist yet, will be created now', 'info'); - setObject(config.weatherEntity, {_id: config.weatherEntity, type: 'channel', common: {role: 'weatherCurrent', name:'media'}, native: {}}); - await createAliasAsync(config.weatherEntity + '.ICON', 'daswetter.' + weatherAdapterInstanceNumber + '.NextHours.Location_1.Day_1.current.symbol_value', true, { type: 'number', role: 'value', name: 'ICON' }); - await createAliasAsync(config.weatherEntity + '.TEMP', 'daswetter.' + weatherAdapterInstanceNumber + '.NextHours.Location_1.Day_1.current.temp_value', true, { type: 'number', role: 'value.temperature', name: 'TEMP' }); - await createAliasAsync(config.weatherEntity + '.TEMP_MIN', 'daswetter.' + weatherAdapterInstanceNumber + '.NextDays.Location_1.Day_1.Minimale_Temperatur_value', true, { type: 'number', role: 'value.temperature.forecast.0', name: 'TEMP_MIN' }); - await createAliasAsync(config.weatherEntity + '.TEMP_MAX', 'daswetter.' + weatherAdapterInstanceNumber + '.NextDays.Location_1.Day_1.Maximale_Temperatur_value', true, { type: 'number', role: 'value.temperature.max.forecast.0', name: 'TEMP_MAX' }); + log('Weather alias for daswetter.' + weatherAdapterInstanceNumber + '. does not exist yet, will be created now', 'info'); + setObject(config.weatherEntity, { _id: config.weatherEntity, type: 'channel', common: { role: 'weatherCurrent', name: 'media' }, native: {} }); + await createAliasAsync(config.weatherEntity + '.ICON', 'daswetter.' + weatherAdapterInstanceNumber + '.NextHours.Location_1.Day_1.current.symbol_value', true, < + iobJS.StateCommon + >{ type: 'number', role: 'value', name: 'ICON' }); + await createAliasAsync(config.weatherEntity + '.TEMP', 'daswetter.' + weatherAdapterInstanceNumber + '.NextHours.Location_1.Day_1.current.temp_value', true, < + iobJS.StateCommon + >{ type: 'number', role: 'value.temperature', name: 'TEMP' }); + await createAliasAsync(config.weatherEntity + '.TEMP_MIN', 'daswetter.' + weatherAdapterInstanceNumber + '.NextDays.Location_1.Day_1.Minimale_Temperatur_value', true, < + iobJS.StateCommon + >{ type: 'number', role: 'value.temperature.forecast.0', name: 'TEMP_MIN' }); + await createAliasAsync(config.weatherEntity + '.TEMP_MAX', 'daswetter.' + weatherAdapterInstanceNumber + '.NextDays.Location_1.Day_1.Maximale_Temperatur_value', true, < + iobJS.StateCommon + >{ type: 'number', role: 'value.temperature.max.forecast.0', name: 'TEMP_MAX' }); } else { log('weather alias for daswetter.' + weatherAdapterInstanceNumber + '. already exists', 'info'); } - } + } } catch (err: any) { log('error at function CreateWeatherAlias daswetter.' + weatherAdapterInstanceNumber + '. : ' + err.message, 'warn'); } @@ -1873,12 +2098,28 @@ async function CreateWeatherAlias () { try { if (isSetOptionActive) { if (!existsState(config.weatherEntity + '.ICON') && existsState('accuweather.' + weatherAdapterInstanceNumber + '.Current.WeatherIcon')) { - log('Weather alias for accuweather.' + weatherAdapterInstanceNumber + '. does not exist yet, will be created now', 'info'); - setObject(config.weatherEntity, {_id: config.weatherEntity, type: 'channel', common: {role: 'weatherCurrent', name:'media'}, native: {}}); - await createAliasAsync(config.weatherEntity + '.ICON', 'accuweather.' + weatherAdapterInstanceNumber + '.Current.WeatherIcon', true, { type: 'number', role: 'value', name: 'ICON' }); - await createAliasAsync(config.weatherEntity + '.TEMP', 'accuweather.' + weatherAdapterInstanceNumber + '.Current.Temperature', true, { type: 'number', role: 'value.temperature', name: 'TEMP' }); - await createAliasAsync(config.weatherEntity + '.TEMP_MIN', 'accuweather.' + weatherAdapterInstanceNumber + '.Daily.Day1.Temperature.Minimum', true, { type: 'number', role: 'value.temperature.forecast.0', name: 'TEMP_MIN' }); - await createAliasAsync(config.weatherEntity + '.TEMP_MAX', 'accuweather.' + weatherAdapterInstanceNumber + '.Daily.Day1.Temperature.Maximum', true, { type: 'number', role: 'value.temperature.max.forecast.0', name: 'TEMP_MAX' }); + log('Weather alias for accuweather.' + weatherAdapterInstanceNumber + '. does not exist yet, will be created now', 'info'); + setObject(config.weatherEntity, { _id: config.weatherEntity, type: 'channel', common: { role: 'weatherCurrent', name: 'media' }, native: {} }); + await createAliasAsync(config.weatherEntity + '.ICON', 'accuweather.' + weatherAdapterInstanceNumber + '.Current.WeatherIcon', true, { + type: 'number', + role: 'value', + name: 'ICON', + }); + await createAliasAsync(config.weatherEntity + '.TEMP', 'accuweather.' + weatherAdapterInstanceNumber + '.Current.Temperature', true, { + type: 'number', + role: 'value.temperature', + name: 'TEMP', + }); + await createAliasAsync(config.weatherEntity + '.TEMP_MIN', 'accuweather.' + weatherAdapterInstanceNumber + '.Daily.Day1.Temperature.Minimum', true, { + type: 'number', + role: 'value.temperature.forecast.0', + name: 'TEMP_MIN', + }); + await createAliasAsync(config.weatherEntity + '.TEMP_MAX', 'accuweather.' + weatherAdapterInstanceNumber + '.Daily.Day1.Temperature.Maximum', true, { + type: 'number', + role: 'value.temperature.max.forecast.0', + name: 'TEMP_MAX', + }); } else { log('weather alias for accuweather.' + weatherAdapterInstanceNumber + '. already exists', 'info'); } @@ -1887,10 +2128,10 @@ async function CreateWeatherAlias () { log('error at function CreateWeatherAlias accuweather.' + weatherAdapterInstanceNumber + '.: ' + err.message, 'warn'); } } - } - } catch (err: any) { - log('error at function CreateWeatherAlias: ' + err.message, 'warn'); - } + } + } catch (err: any) { + log('error at function CreateWeatherAlias: ' + err.message, 'warn'); + } } CreateWeatherAlias(); @@ -1899,7 +2140,7 @@ async function InitPageNavi() { try { if (!existsState(NSPanel_Path + 'PageNavi')) { await createStateAsync(NSPanel_Path + 'PageNavi', { type: 'string', write: true }); - await setStateAsync(NSPanel_Path + 'PageNavi', { val: {"pagetype": "page","pageId": 0}, ack: true }); + await setStateAsync(NSPanel_Path + 'PageNavi', { val: { pagetype: 'page', pageId: 0 }, ack: true }); } } catch (err: any) { log('error at function InitPageNavi: ' + err.message, 'warn'); @@ -1908,7 +2149,7 @@ async function InitPageNavi() { InitPageNavi(); //PageNavi -on({id: [NSPanel_Path + 'PageNavi'], change: "any"}, async function (obj) { +on({ id: [NSPanel_Path + 'PageNavi'], change: 'any' }, async function (obj) { try { if (existsState(NSPanel_Path + 'PageNavi')) { let vObj = JSON.parse(obj.state.val); @@ -1918,16 +2159,16 @@ on({id: [NSPanel_Path + 'PageNavi'], change: "any"}, async function (obj) { GeneratePage(config.subPages[vObj.pageId]); } } - } catch (err: any) { - log('error at Trigger PageNavi: ' + err.message, 'warn'); + } catch (err: any) { + log('error at Trigger PageNavi: ' + err.message, 'warn'); } }); //----------------------Begin Dimmode -function ScreensaverDimmode(timeDimMode:NSPanel.DimMode) { +function ScreensaverDimmode(timeDimMode: NSPanel.DimMode) { try { - let active = getState(NSPanel_Path + 'ScreensaverInfo.activeBrightness').val ?? 80 - let dimmode = getState(NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness').val ?? -1 + let active = getState(NSPanel_Path + 'ScreensaverInfo.activeBrightness').val ?? 80; + let dimmode = getState(NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness').val ?? -1; if (Debug) { log('function ScreensaverDimmode RGB-Wert HMIDark' + rgb_dec565(HMIDark), 'info'); } @@ -1941,7 +2182,9 @@ function ScreensaverDimmode(timeDimMode:NSPanel.DimMode) { log('function ScreensaverDimmode -> Day NSPanel.Payload: ' + 'dimmode~' + timeDimMode.brightnessDay + '~' + active, 'info'); } } else { - SendToPanel({ payload: 'dimmode~' + timeDimMode.brightnessNight + '~' + active + '~' + rgb_dec565(config.defaultBackgroundColor) + '~' + rgb_dec565(globalTextColor) + '~' + Sliders2 }); + SendToPanel({ + payload: 'dimmode~' + timeDimMode.brightnessNight + '~' + active + '~' + rgb_dec565(config.defaultBackgroundColor) + '~' + rgb_dec565(globalTextColor) + '~' + Sliders2, + }); if (Debug) { log('function ScreensaverDimmode -> Night NSPanel.Payload: ' + 'dimmode~' + timeDimMode.brightnessNight + '~' + active, 'info'); } @@ -1958,25 +2201,51 @@ async function InitWeatherForecast() { try { if (isSetOptionActive) { //----Ability to choose between Accu-Weather Forecast or self-defined values in the screensaver--------------------------------- - if (existsState(NSPanel_Path + "ScreensaverInfo.weatherForecast") == false || - existsState(NSPanel_Path + "ScreensaverInfo.weatherForecastTimer") == false || - existsState(NSPanel_Path + "ScreensaverInfo.entityChangeTime") == false) { - await createStateAsync(NSPanel_Path + "ScreensaverInfo.weatherForecast", true, { type: 'boolean', write: true }); - await createStateAsync(NSPanel_Path + "ScreensaverInfo.weatherForecastTimer", true, { type: 'boolean', write: true }); - await createStateAsync(NSPanel_Path + "ScreensaverInfo.entityChangeTime", 60, { type: 'number', write: true }); + if ( + existsState(NSPanel_Path + 'ScreensaverInfo.weatherForecast') == false || + existsState(NSPanel_Path + 'ScreensaverInfo.weatherForecastTimer') == false || + existsState(NSPanel_Path + 'ScreensaverInfo.entityChangeTime') == false + ) { + await createStateAsync(NSPanel_Path + 'ScreensaverInfo.weatherForecast', true, { type: 'boolean', write: true }); + await createStateAsync(NSPanel_Path + 'ScreensaverInfo.weatherForecastTimer', true, { type: 'boolean', write: true }); + await createStateAsync(NSPanel_Path + 'ScreensaverInfo.entityChangeTime', 60, { type: 'number', write: true }); } //Create Alias weatherForecast - setObject(AliasPath + 'ScreensaverInfo.weatherForecast', {type: 'channel', common: {role: 'socket', name:'weatherForecast'}, native: {}}); - await createAliasAsync(AliasPath + 'ScreensaverInfo.weatherForecast.ACTUAL', NSPanel_Path + 'ScreensaverInfo.weatherForecast', true, { type: 'boolean', role: 'switch', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'ScreensaverInfo.weatherForecast.SET', NSPanel_Path + 'ScreensaverInfo.weatherForecast', true, { type: 'boolean', role: 'switch', name: 'SET' }); + setObject(AliasPath + 'ScreensaverInfo.weatherForecast', { type: 'channel', common: { role: 'socket', name: 'weatherForecast' }, native: {} }); + await createAliasAsync(AliasPath + 'ScreensaverInfo.weatherForecast.ACTUAL', NSPanel_Path + 'ScreensaverInfo.weatherForecast', true, { + type: 'boolean', + role: 'switch', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'ScreensaverInfo.weatherForecast.SET', NSPanel_Path + 'ScreensaverInfo.weatherForecast', true, { + type: 'boolean', + role: 'switch', + name: 'SET', + }); //Create Alias weatherForecastTimer - setObject(AliasPath + 'ScreensaverInfo.weatherForecastTimer', {type: 'channel', common: {role: 'socket', name:'weatherForecastTimer'}, native: {}}); - await createAliasAsync(AliasPath + 'ScreensaverInfo.weatherForecastTimer.ACTUAL', NSPanel_Path + 'ScreensaverInfo.weatherForecastTimer', true, { type: 'boolean', role: 'switch', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'ScreensaverInfo.weatherForecastTimer.SET', NSPanel_Path + 'ScreensaverInfo.weatherForecastTimer', true, { type: 'boolean', role: 'switch', name: 'SET' }); + setObject(AliasPath + 'ScreensaverInfo.weatherForecastTimer', { type: 'channel', common: { role: 'socket', name: 'weatherForecastTimer' }, native: {} }); + await createAliasAsync(AliasPath + 'ScreensaverInfo.weatherForecastTimer.ACTUAL', NSPanel_Path + 'ScreensaverInfo.weatherForecastTimer', true, { + type: 'boolean', + role: 'switch', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'ScreensaverInfo.weatherForecastTimer.SET', NSPanel_Path + 'ScreensaverInfo.weatherForecastTimer', true, { + type: 'boolean', + role: 'switch', + name: 'SET', + }); //Create Alias entityChangeTime - setObject(AliasPath + 'ScreensaverInfo.entityChangeTime', {type: 'channel', common: {role: 'slider', name:'entityChangeTime'}, native: {}}); - await createAliasAsync(AliasPath + 'ScreensaverInfo.entityChangeTime.ACTUAL', NSPanel_Path + 'ScreensaverInfo.entityChangeTime', true, { type: 'number', role: 'value', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'ScreensaverInfo.entityChangeTime.SET', NSPanel_Path + 'ScreensaverInfo.entityChangeTime', true, { type: 'number', role: 'level', name: 'SET' }); + setObject(AliasPath + 'ScreensaverInfo.entityChangeTime', { type: 'channel', common: { role: 'slider', name: 'entityChangeTime' }, native: {} }); + await createAliasAsync(AliasPath + 'ScreensaverInfo.entityChangeTime.ACTUAL', NSPanel_Path + 'ScreensaverInfo.entityChangeTime', true, { + type: 'number', + role: 'value', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'ScreensaverInfo.entityChangeTime.SET', NSPanel_Path + 'ScreensaverInfo.entityChangeTime', true, { + type: 'number', + role: 'level', + name: 'SET', + }); } } catch (err: any) { log('error at function InitWeatherForecast: ' + err.message, 'warn'); @@ -1991,28 +2260,44 @@ async function InitDimmode() { if (!existsState(NSPanel_Path + 'NSPanel_Dimmode_brightnessDay')) { await createStateAsync(NSPanel_Path + 'NSPanel_Dimmode_brightnessDay', { type: 'number', write: true }); await setStateAsync(NSPanel_Path + 'NSPanel_Dimmode_brightnessDay', { val: 8, ack: true }); - setObject(AliasPath + 'Dimmode.brightnessDay', {type: 'channel', common: {role: 'slider', name:'brightnessDay'}, native: {}}); - await createAliasAsync(AliasPath + 'Dimmode.brightnessDay.ACTUAL', NSPanel_Path + 'NSPanel_Dimmode_brightnessDay', true, { type: 'number', role: 'value', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Dimmode.brightnessDay.SET', NSPanel_Path + 'NSPanel_Dimmode_brightnessDay', true, { type: 'number', role: 'level', name: 'SET' }); + setObject(AliasPath + 'Dimmode.brightnessDay', { type: 'channel', common: { role: 'slider', name: 'brightnessDay' }, native: {} }); + await createAliasAsync(AliasPath + 'Dimmode.brightnessDay.ACTUAL', NSPanel_Path + 'NSPanel_Dimmode_brightnessDay', true, { + type: 'number', + role: 'value', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'Dimmode.brightnessDay.SET', NSPanel_Path + 'NSPanel_Dimmode_brightnessDay', true, { + type: 'number', + role: 'level', + name: 'SET', + }); } if (!existsState(NSPanel_Path + 'NSPanel_Dimmode_hourDay')) { await createStateAsync(NSPanel_Path + 'NSPanel_Dimmode_hourDay', { type: 'number', write: true }); await setStateAsync(NSPanel_Path + 'NSPanel_Dimmode_hourDay', { val: 7, ack: true }); - setObject(AliasPath + 'Dimmode.hourDay', {type: 'channel', common: {role: 'slider', name:'hourDay'}, native: {}}); + setObject(AliasPath + 'Dimmode.hourDay', { type: 'channel', common: { role: 'slider', name: 'hourDay' }, native: {} }); await createAliasAsync(AliasPath + 'Dimmode.hourDay.ACTUAL', NSPanel_Path + 'NSPanel_Dimmode_hourDay', true, { type: 'number', role: 'value', name: 'ACTUAL' }); await createAliasAsync(AliasPath + 'Dimmode.hourDay.SET', NSPanel_Path + 'NSPanel_Dimmode_hourDay', true, { type: 'number', role: 'level', name: 'SET' }); } if (!existsState(NSPanel_Path + 'NSPanel_Dimmode_brightnessNight')) { await createStateAsync(NSPanel_Path + 'NSPanel_Dimmode_brightnessNight', { type: 'number', write: true }); await setStateAsync(NSPanel_Path + 'NSPanel_Dimmode_brightnessNight', { val: 1, ack: true }); - setObject(AliasPath + 'Dimmode.brightnessNight', {type: 'channel', common: {role: 'slider', name:'brightnessNight'}, native: {}}); - await createAliasAsync(AliasPath + 'Dimmode.brightnessNight.ACTUAL', NSPanel_Path + 'NSPanel_Dimmode_brightnessNight', true, { type: 'number', role: 'value', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Dimmode.brightnessNight.SET', NSPanel_Path + 'NSPanel_Dimmode_brightnessNight', true, { type: 'number', role: 'level', name: 'SET' }); + setObject(AliasPath + 'Dimmode.brightnessNight', { type: 'channel', common: { role: 'slider', name: 'brightnessNight' }, native: {} }); + await createAliasAsync(AliasPath + 'Dimmode.brightnessNight.ACTUAL', NSPanel_Path + 'NSPanel_Dimmode_brightnessNight', true, { + type: 'number', + role: 'value', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'Dimmode.brightnessNight.SET', NSPanel_Path + 'NSPanel_Dimmode_brightnessNight', true, { + type: 'number', + role: 'level', + name: 'SET', + }); } if (!existsState(NSPanel_Path + 'NSPanel_Dimmode_hourNight')) { await createStateAsync(NSPanel_Path + 'NSPanel_Dimmode_hourNight', { type: 'number', write: true }); await setStateAsync(NSPanel_Path + 'NSPanel_Dimmode_hourNight', { val: 22, ack: true }); - setObject(AliasPath + 'Dimmode.hourNight', {type: 'channel', common: {role: 'slider', name:'hourNight'}, native: {}}); + setObject(AliasPath + 'Dimmode.hourNight', { type: 'channel', common: { role: 'slider', name: 'hourNight' }, native: {} }); await createAliasAsync(AliasPath + 'Dimmode.hourNight.ACTUAL', NSPanel_Path + 'NSPanel_Dimmode_hourNight', true, { type: 'number', role: 'value', name: 'ACTUAL' }); await createAliasAsync(AliasPath + 'Dimmode.hourNight.SET', NSPanel_Path + 'NSPanel_Dimmode_hourNight', true, { type: 'number', role: 'level', name: 'SET' }); } @@ -2022,11 +2307,11 @@ async function InitDimmode() { dimmodeOn: true, brightnessDay: getState(NSPanel_Path + 'NSPanel_Dimmode_brightnessDay').val, brightnessNight: getState(NSPanel_Path + 'NSPanel_Dimmode_brightnessNight').val, - timeDay: (vTimeDay < 10) ? `0${vTimeDay}:00` : `${vTimeDay}:00`, - timeNight: (vTimeNight < 10) ? `0${vTimeNight}:00` : `${vTimeNight}:00` + timeDay: vTimeDay < 10 ? `0${vTimeDay}:00` : `${vTimeDay}:00`, + timeNight: vTimeNight < 10 ? `0${vTimeNight}:00` : `${vTimeNight}:00`, }; // timeDimMode Day - scheduleInitDimModeDay = adapterSchedule({ hour: getState(NSPanel_Path + 'NSPanel_Dimmode_hourDay').val, minute: 0}, 24 * 60 * 60, () => { + scheduleInitDimModeDay = adapterSchedule({ hour: getState(NSPanel_Path + 'NSPanel_Dimmode_hourDay').val, minute: 0 }, 24 * 60 * 60, () => { ScreensaverDimmode(timeDimMode); }); // timeDimMode Night @@ -2034,12 +2319,24 @@ async function InitDimmode() { ScreensaverDimmode(timeDimMode); }); if (getState(NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness').val != null && getState(NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness').val != -1) { - SendToPanel({ payload: 'dimmode~' + getState(NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness').val + '~' + getState(NSPanel_Path + 'ScreensaverInfo.activeBrightness').val ?? 80 + '~' + rgb_dec565(config.defaultBackgroundColor) + '~' + rgb_dec565(globalTextColor) + '~' + Sliders2 }); + SendToPanel({ + payload: + 'dimmode~' + getState(NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness').val + '~' + getState(NSPanel_Path + 'ScreensaverInfo.activeBrightness').val ?? + 80 + '~' + rgb_dec565(config.defaultBackgroundColor) + '~' + rgb_dec565(globalTextColor) + '~' + Sliders2, + }); } else { - if (isDimTimeInRange(timeDimMode.timeDay,timeDimMode.timeNight)) { - SendToPanel({ payload: 'dimmode~' + timeDimMode.brightnessDay + '~' + getState(NSPanel_Path + 'ScreensaverInfo.activeBrightness').val?? 80 + '~' + rgb_dec565(config.defaultBackgroundColor) + '~' + rgb_dec565(globalTextColor) + '~' + Sliders2 }); + if (isDimTimeInRange(timeDimMode.timeDay, timeDimMode.timeNight)) { + SendToPanel({ + payload: + 'dimmode~' + timeDimMode.brightnessDay + '~' + getState(NSPanel_Path + 'ScreensaverInfo.activeBrightness').val ?? + 80 + '~' + rgb_dec565(config.defaultBackgroundColor) + '~' + rgb_dec565(globalTextColor) + '~' + Sliders2, + }); } else { - SendToPanel({ payload: 'dimmode~' + timeDimMode.brightnessNight + '~' + getState(NSPanel_Path + 'ScreensaverInfo.activeBrightness').val ?? 80 + '~' + rgb_dec565(config.defaultBackgroundColor) + '~' + rgb_dec565(globalTextColor) + '~' + Sliders2 }); + SendToPanel({ + payload: + 'dimmode~' + timeDimMode.brightnessNight + '~' + getState(NSPanel_Path + 'ScreensaverInfo.activeBrightness').val ?? + 80 + '~' + rgb_dec565(config.defaultBackgroundColor) + '~' + rgb_dec565(globalTextColor) + '~' + Sliders2, + }); } ScreensaverDimmode(timeDimMode); } @@ -2071,16 +2368,119 @@ function isDimTimeInRange(strLower, strUpper) { let inRange = false; if (upper > lower) { // opens and closes in same day - inRange = (now >= lower && now <= upper) ? true : false; + inRange = now >= lower && now <= upper ? true : false; } else { // closes in the following day - inRange = (now >= upper && now <= lower) ? false : true; + inRange = now >= upper && now <= lower ? false : true; } return inRange; } //--------------------End Dimmode +//--------------------Begin Consumtion (with Dimmode and Relays On Off) +// Funktion to calculate mean linear consumtion +async function Calc_Consumtion(Brightness: number, Relays: number) { + try { + return parseFloat((Relays * 0.25 + (0.0086 * Brightness + 0.7429)).toFixed(2)); + } catch (err: any) { + log('error at function Calc_Consumtion: ' + err.message, 'warn'); + } +} + +// +async function CountRelaysOn(Path: string) { + try { + let r1: boolean = getState(Path + 'Relay.1').val; + let r2: boolean = getState(Path + 'Relay.2').val; + + if (r1 && r2) { + return 2; + } else if (!r1 && !r2) { + return 0; + } else { + return 1; + } + } catch (err: any) { + log('error at function CountRelaysOn: ' + err.message, 'warn'); + } +} + +async function DetermineDimBrightness(Path: string) { + try { + const vTimeDay = getState(Path + 'NSPanel_Dimmode_hourDay').val; + const vTimeNight = getState(Path + 'NSPanel_Dimmode_hourNight').val; + const timeDimMode: NSPanel.DimMode = { + dimmodeOn: true, + brightnessDay: getState(NSPanel_Path + 'NSPanel_Dimmode_brightnessDay').val, + brightnessNight: getState(NSPanel_Path + 'NSPanel_Dimmode_brightnessNight').val, + timeDay: vTimeDay < 10 ? `0${vTimeDay}:00` : `${vTimeDay}:00`, + timeNight: vTimeNight < 10 ? `0${vTimeNight}:00` : `${vTimeNight}:00`, + }; + + if (getState(Path + 'ScreensaverInfo.activeDimmodeBrightness').val == -1) { + if (getState(Path + 'ActivePage.id0').val == 'screensaver') { + return await DetermineScreensaverDimmode(timeDimMode); + } else { + return getState(Path + 'ScreensaverInfo.activeBrightness').val; + } + } else { + return getState(Path + 'ScreensaverInfo.activeDimmodeBrightness').val; + } + } catch (err: any) { + log('error at function DetermineDimBrightness: ' + err.message, 'warn'); + } +} + +async function DetermineScreensaverDimmode(timeDimMode: NSPanel.DimMode) { + try { + if (timeDimMode.dimmodeOn != undefined ? timeDimMode.dimmodeOn : false) { + if (compareTime(timeDimMode.timeNight != undefined ? timeDimMode.timeNight : '22:00', timeDimMode.timeDay != undefined ? timeDimMode.timeDay : '07:00', 'not between', undefined)) { + return timeDimMode.brightnessDay; + } else { + return timeDimMode.brightnessNight; + } + } + } catch (err: any) { + log('error at function DetermineScreensaverDimmode: ' + err.message, 'warn'); + } +} + +async function InitMeanPowerConsumtion() { + try { + const MeanPower = NSPanel_Path + 'Consumtion.MeanPower'; + let meanConsumtion: number = await Calc_Consumtion(await DetermineDimBrightness(NSPanel_Path), await CountRelaysOn(NSPanel_Path)); + if (!existsState(MeanPower)) { + await createStateAsync(MeanPower, { type: 'number', write: true, unit: 'W' }); + } + await setStateAsync(MeanPower, { val: meanConsumtion, ack: true }); + if (Debug) log(meanConsumtion + ' W', 'info'); + } catch (err: any) { + log('error at function InitMeanPowerConsumtion: ' + err.message, 'warn'); + } +} +InitMeanPowerConsumtion(); + +// Trigger fires on currentPage, dim Standby and dimActive +on( + { + id: [] + .concat(NSPanel_Path + 'NSPanel_Dimmode_brightnessDay') + .concat(NSPanel_Path + 'NSPanel_Dimmode_brightnessNight') + .concat(NSPanel_Path + 'ScreensaverInfo.activeBrightness') + .concat(NSPanel_Path + 'ScreensaverInfo.activeDimmodeBrightness') + .concat(NSPanel_Path + 'Relay.1') + .concat(NSPanel_Path + 'Relay.2') + .concat(NSPanel_Path + 'ActivePage.id0'), + change: 'any', + }, + async (obj) => { + await InitMeanPowerConsumtion(); + } +); + +//--------------------End Consumtion + // Data points for message to screensaver const screensaverNotifyHeading = NSPanel_Path + 'ScreensaverInfo.popupNotifyHeading'; const screensaverNotifyText = NSPanel_Path + 'ScreensaverInfo.popupNotifyText'; @@ -2098,14 +2498,13 @@ const popupNotifyButton2Text = NSPanel_Path + 'popupNotify.popupNotifyButton2Tex const popupNotifySleepTimeout = NSPanel_Path + 'popupNotify.popupNotifySleepTimeout'; // in sec. / if 0, then the message remains const popupNotifyAction = NSPanel_Path + 'popupNotify.popupNotifyAction'; // Response from the panel true/false const popupNotifyLayout = NSPanel_Path + 'popupNotify.popupNotifyLayout'; -const popupNotifyFontIdText = NSPanel_Path + 'popupNotify.popupNotifyFontIdText'; // 1 - 5 -const popupNotifyIcon = NSPanel_Path + 'popupNotify.popupNotifyIcon'; // 1 - 5 -const popupNotifyIconColor = NSPanel_Path + 'popupNotify.popupNotifyIconColor'; // 1 - 5 -const popupNotifyBuzzer = NSPanel_Path + 'popupNotify.popupNotifyBuzzer'; // 1,1,1 -> off 0 +const popupNotifyFontIdText = NSPanel_Path + 'popupNotify.popupNotifyFontIdText'; // 1 - 5 +const popupNotifyIcon = NSPanel_Path + 'popupNotify.popupNotifyIcon'; // 1 - 5 +const popupNotifyIconColor = NSPanel_Path + 'popupNotify.popupNotifyIconColor'; // 1 - 5 +const popupNotifyBuzzer = NSPanel_Path + 'popupNotify.popupNotifyBuzzer'; // 1,1,1 -> off 0 async function InitPopupNotify() { try { - if (!existsState(screensaverNotifyHeading)) { await createStateAsync(screensaverNotifyHeading, { type: 'string', write: true }); await setStateAsync(screensaverNotifyHeading, { val: '', ack: true }); @@ -2131,13 +2530,13 @@ async function InitPopupNotify() { await createStateAsync(popupNotifyFontIdText, { type: 'number', write: true }); await createStateAsync(popupNotifyIcon, { type: 'string', write: true }); await createStateAsync(popupNotifyIconColor, { type: 'string', write: true }); - await createStateAsync(popupNotifyBuzzer,{type: 'string', def: '0', write: true}); + await createStateAsync(popupNotifyBuzzer, { type: 'string', def: '0', write: true }); // Notification to screensaver on({ id: [screensaverNotifyHeading, screensaverNotifyText], change: 'ne', ack: false }, async (obj) => { const heading = getState(screensaverNotifyHeading).val; const text = getState(screensaverNotifyText).val; - + if (screensaverEnabled && heading != '' && text != '') { setIfExists(config.panelSendTopic, `notify~${heading}~${text}`); } @@ -2148,39 +2547,46 @@ async function InitPopupNotify() { }); // popupNotify - Notification to a separate page - on({ id: [popupNotifyText], change: 'any' }, async() => { - + on({ id: [popupNotifyText], change: 'any' }, async () => { let notification: string; - let v_popupNotifyHeadingColor = (getState(popupNotifyHeadingColor).val != null) ? getState(popupNotifyHeadingColor).val : '65504'// Farbe Headline - gelb 65504 - let v_popupNotifyButton1TextColor = (getState(popupNotifyButton1TextColor).val != null) ? getState(popupNotifyButton1TextColor).val : '63488'// Farbe Button 1 - rot 63488 - let v_popupNotifyButton2TextColor = (getState(popupNotifyButton2TextColor).val != null) ? getState(popupNotifyButton2TextColor).val : '2016'// Farbe Button 2 - grün 2016 - let v_popupNotifyTextColor = (getState(popupNotifyTextColor).val != null) ? getState(popupNotifyTextColor).val : '65535'// Farbe Text - weiss 65535 - let v_popupNotifyIconColor = (getState(popupNotifyIconColor).val != null) ? getState(popupNotifyIconColor).val : '65535'// Farbe Icon - weiss 65535 - let v_popupNotifyFontIdText = (getState(popupNotifyFontIdText).val != null) ? getState(popupNotifyFontIdText).val : '1' - let v_popupNotifyIcon = (getState(popupNotifyIcon).val != null) ? getState(popupNotifyIcon).val : 'alert' - let v_popupNotifyBuzzer = (getState(popupNotifyBuzzer).val != null) ? getState(popupNotifyBuzzer).val : '0'; + let v_popupNotifyHeadingColor = getState(popupNotifyHeadingColor).val != null ? getState(popupNotifyHeadingColor).val : '65504'; // Farbe Headline - gelb 65504 + let v_popupNotifyButton1TextColor = getState(popupNotifyButton1TextColor).val != null ? getState(popupNotifyButton1TextColor).val : '63488'; // Farbe Button 1 - rot 63488 + let v_popupNotifyButton2TextColor = getState(popupNotifyButton2TextColor).val != null ? getState(popupNotifyButton2TextColor).val : '2016'; // Farbe Button 2 - grün 2016 + let v_popupNotifyTextColor = getState(popupNotifyTextColor).val != null ? getState(popupNotifyTextColor).val : '65535'; // Farbe Text - weiss 65535 + let v_popupNotifyIconColor = getState(popupNotifyIconColor).val != null ? getState(popupNotifyIconColor).val : '65535'; // Farbe Icon - weiss 65535 + let v_popupNotifyFontIdText = getState(popupNotifyFontIdText).val != null ? getState(popupNotifyFontIdText).val : '1'; + let v_popupNotifyIcon = getState(popupNotifyIcon).val != null ? getState(popupNotifyIcon).val : 'alert'; + let v_popupNotifyBuzzer = getState(popupNotifyBuzzer).val != null ? getState(popupNotifyBuzzer).val : '0'; const heading = getState(popupNotifyHeading).val; const text = getState(popupNotifyText).val; - notification = 'entityUpdateDetail' + '~' - + getState(popupNotifyInternalName).val + '~' - + heading + '~' - + v_popupNotifyHeadingColor + '~' - + getState(popupNotifyButton1Text).val + '~' - + v_popupNotifyButton1TextColor + '~' - + getState(popupNotifyButton2Text).val + '~' - + v_popupNotifyButton2TextColor + '~' - + text + '~' - + v_popupNotifyTextColor + '~' - + getState(popupNotifySleepTimeout).val; + notification = + 'entityUpdateDetail' + + '~' + + getState(popupNotifyInternalName).val + + '~' + + heading + + '~' + + v_popupNotifyHeadingColor + + '~' + + getState(popupNotifyButton1Text).val + + '~' + + v_popupNotifyButton1TextColor + + '~' + + getState(popupNotifyButton2Text).val + + '~' + + v_popupNotifyButton2TextColor + + '~' + + text + + '~' + + v_popupNotifyTextColor + + '~' + + getState(popupNotifySleepTimeout).val; if (getState(popupNotifyLayout).val == 2) { - notification = notification + '~' - + v_popupNotifyFontIdText + '~' - + Icons.GetIcon(v_popupNotifyIcon) + '~' - + v_popupNotifyIconColor; + notification = notification + '~' + v_popupNotifyFontIdText + '~' + Icons.GetIcon(v_popupNotifyIcon) + '~' + v_popupNotifyIconColor; } if (heading != '' && text != '') { @@ -2189,9 +2595,9 @@ async function InitPopupNotify() { } //------ Tasmota Buzzer ------ - + if (v_popupNotifyBuzzer != '0') { - if (Debug){ + if (Debug) { log('Tasmota Buzzer enabled. Value: ' + v_popupNotifyBuzzer, 'info'); } let urlString = `http://${get_current_tasmota_ip_address()}/cm?cmnd=Buzzer ${v_popupNotifyBuzzer}`; @@ -2199,7 +2605,8 @@ async function InitPopupNotify() { urlString = `http://${get_current_tasmota_ip_address()}/cm?user=${tasmota_web_admin_user}&password=${tasmota_web_admin_password}&cmnd=Buzzer ${v_popupNotifyBuzzer}`; } - axios.get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) .then(async function (response) { if (response.status === 200) { log('Axios Data: ' + JSON.stringify(response.data), 'info'); @@ -2209,16 +2616,15 @@ async function InitPopupNotify() { }) .catch(function (error) { if (error.code === 'EHOSTUNREACH') { - log(`Can't connect to display!`, 'warn') + log(`Can't connect to display!`, 'warn'); } else log(error, 'warn'); }); } else { - if (Debug){ + if (Debug) { log('Tasmota Buzzer disabled', 'info'); } } //---- Tasmota Buzzer ----- - }); } catch (err: any) { log('error at function InitPopupNotify: ' + err.message, 'warn'); @@ -2232,7 +2638,7 @@ let pageId = 0; let activePage: PageType | undefined = undefined; //Send time to NSPanel -let scheduleSendTime = adapterSchedule(new Date().setSeconds(0,0), 60, () => { +let scheduleSendTime = adapterSchedule(new Date().setSeconds(0, 0), 60, () => { try { SendTime(); HandleScreensaverUpdate(); @@ -2245,10 +2651,20 @@ let scheduleSendTime = adapterSchedule(new Date().setSeconds(0,0), 60, () => { let scheduleSwichScreensaver = adapterSchedule(undefined, parseInt(getState(NSPanel_Path + 'ScreensaverInfo.entityChangeTime').val), () => { try { //WeatherForecast true/false Switchover delayed - if (getState(NSPanel_Path + "ScreensaverInfo.popupNotifyHeading").val == '' && getState(NSPanel_Path + "ScreensaverInfo.popupNotifyText").val == '' && getState(NSPanel_Path + "ScreensaverInfo.weatherForecast").val == true && getState(NSPanel_Path + "ScreensaverInfo.weatherForecastTimer").val == true) { - setStateDelayed(NSPanel_Path + "ScreensaverInfo.weatherForecast", false, (getState(NSPanel_Path + 'ScreensaverInfo.entityChangeTime').val / 2 * 1000), false); - } else if (getState(NSPanel_Path + "ScreensaverInfo.popupNotifyHeading").val == '' && getState(NSPanel_Path + "ScreensaverInfo.popupNotifyText").val == '' && getState(NSPanel_Path + "ScreensaverInfo.weatherForecast").val == false && getState(NSPanel_Path + "ScreensaverInfo.weatherForecastTimer").val == true) { - setStateDelayed(NSPanel_Path + "ScreensaverInfo.weatherForecast", true, (getState(NSPanel_Path + 'ScreensaverInfo.entityChangeTime').val / 2 * 1000), false); + if ( + getState(NSPanel_Path + 'ScreensaverInfo.popupNotifyHeading').val == '' && + getState(NSPanel_Path + 'ScreensaverInfo.popupNotifyText').val == '' && + getState(NSPanel_Path + 'ScreensaverInfo.weatherForecast').val == true && + getState(NSPanel_Path + 'ScreensaverInfo.weatherForecastTimer').val == true + ) { + setStateDelayed(NSPanel_Path + 'ScreensaverInfo.weatherForecast', false, (getState(NSPanel_Path + 'ScreensaverInfo.entityChangeTime').val / 2) * 1000, false); + } else if ( + getState(NSPanel_Path + 'ScreensaverInfo.popupNotifyHeading').val == '' && + getState(NSPanel_Path + 'ScreensaverInfo.popupNotifyText').val == '' && + getState(NSPanel_Path + 'ScreensaverInfo.weatherForecast').val == false && + getState(NSPanel_Path + 'ScreensaverInfo.weatherForecastTimer').val == true + ) { + setStateDelayed(NSPanel_Path + 'ScreensaverInfo.weatherForecast', true, (getState(NSPanel_Path + 'ScreensaverInfo.entityChangeTime').val / 2) * 1000, false); } } catch (err: any) { log('error at schedule entityChangeTime: ' + err.message, 'warn'); @@ -2258,7 +2674,7 @@ let scheduleSwichScreensaver = adapterSchedule(undefined, parseInt(getState(NSPa function InitHWButton1Color() { try { if (config.mrIcon1ScreensaverEntity.ScreensaverEntity != null || config.mrIcon1ScreensaverEntity.ScreensaverEntity != undefined) { - on({id: config.mrIcon1ScreensaverEntity.ScreensaverEntity, change: "ne"}, async function () { + on({ id: config.mrIcon1ScreensaverEntity.ScreensaverEntity, change: 'ne' }, async function () { HandleScreensaverUpdate(); }); } @@ -2271,7 +2687,7 @@ InitHWButton1Color(); function InitHWButton2Color() { try { if (config.mrIcon2ScreensaverEntity.ScreensaverEntity != null || config.mrIcon2ScreensaverEntity.ScreensaverEntity != undefined) { - on({id: config.mrIcon2ScreensaverEntity.ScreensaverEntity, change: "ne"}, async function () { + on({ id: config.mrIcon2ScreensaverEntity.ScreensaverEntity, change: 'ne' }, async function () { HandleScreensaverUpdate(); }); } @@ -2282,8 +2698,8 @@ function InitHWButton2Color() { InitHWButton2Color(); //Switch between data points and weather forecast in the screensaver -on({id: [NSPanel_Path + "ScreensaverInfo.weatherForecast"], change: "ne"}, async function (obj) { - try { +on({ id: [NSPanel_Path + 'ScreensaverInfo.weatherForecast'], change: 'ne' }, async function (obj) { + try { weatherForecast = obj.state.val; HandleScreensaverUpdate(); } catch (err: any) { @@ -2292,26 +2708,25 @@ on({id: [NSPanel_Path + "ScreensaverInfo.weatherForecast"], change: "ne"}, async }); //Update if Changing Values on Wheather Alias -on({id: [config.weatherEntity + '.TEMP', - config.weatherEntity + '.ICON'], change: "ne"}, async function (obj) { - try { +on({ id: [config.weatherEntity + '.TEMP', config.weatherEntity + '.ICON'], change: 'ne' }, async function (obj) { + try { HandleScreensaverUpdate(); } catch (err: any) { log('error at trigger weatherForecast .TEMP + .ICON: ' + err.message, 'warn'); } }); -let scheduleSendDate = adapterSchedule((new Date().setMinutes(0,0)),60*60, () => { +let scheduleSendDate = adapterSchedule(new Date().setMinutes(0, 0), 60 * 60, () => { SendDate(); }); // 3:30 a.m. Perform startup and receive current TFT version -let scheduleStartup = adapterSchedule({ hour: 3, minute: 30 }, 24*60*60, async () => { +let scheduleStartup = adapterSchedule({ hour: 3, minute: 30 }, 24 * 60 * 60, async () => { setIfExists(config.panelSendTopic, 'pageType~pageStartup'); }); // Updates currently compare every 12 hours -let scheduleCheckUpdates = adapterSchedule(undefined,60*60*12, () => { +let scheduleCheckUpdates = adapterSchedule(undefined, 60 * 60 * 12, () => { get_tasmota_status0(); get_panel_update_data(); check_updates(); @@ -2335,7 +2750,7 @@ setTimeout(async function () { function getDayjsLocale(): String { try { let locale = getState(NSPanel_Path + 'Config.locale').val; - if (locale == "hy-AM" || locale == "zh-CN" || locale == "zh-TW") { + if (locale == 'hy-AM' || locale == 'zh-CN' || locale == 'zh-TW') { return locale.toLowerCase(); } else { return locale.substring(0, 2); @@ -2354,7 +2769,8 @@ async function get_locales() { } let urlString: string = 'https://raw.githubusercontent.com/joBr99/nspanel-lovelace-ui/main/ioBroker/ioBroker_NSPanel_locales.json'; - axios.get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) .then(async function (response) { if (response.status === 200) { if (Debug) { @@ -2369,7 +2785,6 @@ async function get_locales() { .catch(function (error) { log(error, 'warn'); }); - } catch (err: any) { log('error requesting locales in function get_locales: ' + err.message, 'warn'); } @@ -2382,7 +2797,8 @@ async function get_locales_servicemenu() { } let urlString: string = 'https://raw.githubusercontent.com/joBr99/nspanel-lovelace-ui/main/ioBroker/ioBroker_NSPanel_locales_service.json'; - axios.get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) .then(async function (response) { if (response.status === 200) { if (Debug) { @@ -2397,7 +2813,6 @@ async function get_locales_servicemenu() { .catch(function (error) { log(error, 'warn'); }); - } catch (err: any) { log('error requesting locales in function get_locales_servicemenu: ' + err.message, 'warn'); } @@ -2415,20 +2830,19 @@ async function check_updates() { const HeadlineColor: string = '63488'; // Farbe Rot const Button1: string = 'Nein'; - const Button1Color: string = '63488'; // Farbe Rot + const Button1Color: string = '63488'; // Farbe Rot const Button2: string = 'Ja'; - const Button2Color: string = '2016'; // Farbe Grün + const Button2Color: string = '2016'; // Farbe Grün const Timeout: number = 0; const Layout: number = 1; - + // Tasmota-Firmware-Vergleich if (existsObject(NSPanel_Path + 'Tasmota_Firmware.currentVersion') && existsObject(NSPanel_Path + 'Tasmota_Firmware.onlineVersion')) { - let splitTasmotaVersion = (getState(NSPanel_Path + 'Tasmota_Firmware.currentVersion').val).split('.'); - let shortTasmoataVersion = splitTasmotaVersion[0] + '.' + splitTasmotaVersion[1] + '.' + splitTasmotaVersion[2] + let splitTasmotaVersion = getState(NSPanel_Path + 'Tasmota_Firmware.currentVersion').val.split('.'); + let shortTasmoataVersion = splitTasmotaVersion[0] + '.' + splitTasmotaVersion[1] + '.' + splitTasmotaVersion[2]; if (shortTasmoataVersion !== getState(NSPanel_Path + 'Tasmota_Firmware.onlineVersion').val) { if (existsState(NSPanel_Path + 'NSPanel_autoUpdate')) { if (getState(NSPanel_Path + 'NSPanel_autoUpdate').val) { - log('Auto-Updates eingeschaltet - Update Tasmota wird durchgeführt', 'info'); // Perform Tasmota upgrade @@ -2442,7 +2856,19 @@ async function check_updates() { InternalName = 'TasmotaFirmwareUpdate'; Headline = 'Tasmota-Firmware Update'; - Text = ['Es ist eine neue Version der Tasmota-Firmware', '\r\n', 'verfügbar', '\r\n', '\r\n', 'Installierte Version: ' + String(getState((String(NSPanel_Path) + 'Tasmota_Firmware.currentVersion')).val), '\r\n', 'Verfügbare Version: ' + String(getState((String(NSPanel_Path) + 'Tasmota_Firmware.onlineVersion')).val), '\r\n', '\r\n', 'Upgrade durchführen?'].join(''); + Text = [ + 'Es ist eine neue Version der Tasmota-Firmware', + '\r\n', + 'verfügbar', + '\r\n', + '\r\n', + 'Installierte Version: ' + String(getState(String(NSPanel_Path) + 'Tasmota_Firmware.currentVersion').val), + '\r\n', + 'Verfügbare Version: ' + String(getState(String(NSPanel_Path) + 'Tasmota_Firmware.onlineVersion').val), + '\r\n', + '\r\n', + 'Upgrade durchführen?', + ].join(''); Update = true; } } @@ -2456,7 +2882,6 @@ async function check_updates() { if (parseFloat(getState(NSPanel_Path + 'Berry_Driver.currentVersion').val) < berry_driver_version) { if (existsState(NSPanel_Path + 'NSPanel_autoUpdate')) { if (getState(NSPanel_Path + 'NSPanel_autoUpdate').val) { - log('Auto-updates switched on - Berry driver update is carried out', 'info'); // Tasmota Berry-Driver Update durchführen @@ -2465,14 +2890,25 @@ async function check_updates() { await setStateAsync(NSPanel_Path + 'Berry_Driver.currentVersion', { val: getState(NSPanel_Path + 'Berry_Driver.onlineVersion').val, ack: true }); if (Debug) log('Berry driver updated automatically', 'info'); - } else { //Auf BerryDriver-Update hinweisen if (Debug) log('Berry Driver => Automatic updates off, manual update required', 'info'); InternalName = 'BerryDriverUpdate'; Headline = 'Berry-Driver Update'; - Text = ['Es ist eine neue Version des Berry-Drivers', '\r\n', '(Tasmota) verfügbar', '\r\n', '\r\n', 'Installierte Version: ' + String(getState((String(NSPanel_Path) + 'Berry_Driver.currentVersion')).val), '\r\n', 'Verfügbare Version: ' + String(berry_driver_version), '\r\n', '\r\n', 'Upgrade durchführen?'].join(''); + Text = [ + 'Es ist eine neue Version des Berry-Drivers', + '\r\n', + '(Tasmota) verfügbar', + '\r\n', + '\r\n', + 'Installierte Version: ' + String(getState(String(NSPanel_Path) + 'Berry_Driver.currentVersion').val), + '\r\n', + 'Verfügbare Version: ' + String(berry_driver_version), + '\r\n', + '\r\n', + 'Upgrade durchführen?', + ].join(''); Update = true; } } @@ -2486,7 +2922,6 @@ async function check_updates() { if (parseInt(getState(NSPanel_Path + 'Display_Firmware.currentVersion').val) < desired_display_firmware_version) { if (existsState(NSPanel_Path + 'NSPanel_autoUpdate')) { if (getState(NSPanel_Path + 'NSPanel_autoUpdate').val) { - log('Auto-updates switched on - update TFT firmware is carried out', 'info'); // TFT-Firmware Update durchführen @@ -2495,14 +2930,25 @@ async function check_updates() { await setStateAsync(NSPanel_Path + 'Display_Firmware.currentVersion', { val: getState(NSPanel_Path + 'Display_Firmware.onlineVersion').val, ack: true }); if (Debug) log('Display firmware updated automatically', 'info'); - } else { // Auf TFT-Firmware hinweisen if (Debug) log('Display firmware => Automatic updates off, manual update required', 'info'); InternalName = 'TFTFirmwareUpdate'; Headline = 'TFT-Firmware Update'; - Text = ['Es ist eine neue Version der TFT-Firmware', '\r\n', 'verfügbar', '\r\n', '\r\n', 'Installierte Version: ' + String(getState((String(NSPanel_Path) + 'Display_Firmware.currentVersion')).val), '\r\n', 'Verfügbare Version: ' + String(desired_display_firmware_version), '\r\n', '\r\n', 'Upgrade durchführen?'].join(''); + Text = [ + 'Es ist eine neue Version der TFT-Firmware', + '\r\n', + 'verfügbar', + '\r\n', + '\r\n', + 'Installierte Version: ' + String(getState(String(NSPanel_Path) + 'Display_Firmware.currentVersion').val), + '\r\n', + 'Verfügbare Version: ' + String(desired_display_firmware_version), + '\r\n', + '\r\n', + 'Upgrade durchführen?', + ].join(''); Update = true; } } @@ -2521,13 +2967,12 @@ async function check_updates() { await setStateAsync(popupNotifySleepTimeout, { val: Timeout, ack: false }); await setStateAsync(popupNotifyInternalName, { val: InternalName, ack: false }); await setStateAsync(popupNotifyLayout, { val: Layout, ack: false }); - await setStateAsync(popupNotifyText, { val: [formatDate(getDateObject((new Date().getTime())), 'TT.MM.JJJJ SS:mm:ss'), '\r\n', '\r\n', Text].join(''), ack: false }); + await setStateAsync(popupNotifyText, { val: [formatDate(getDateObject(new Date().getTime()), 'TT.MM.JJJJ SS:mm:ss'), '\r\n', '\r\n', Text].join(''), ack: false }); } else if (Update && !update_message) { log('Updates for NSPanel available', 'info'); } else { log('No Updates for NSPanel available', 'info'); } - } catch (err: any) { log('error at function check_updates: ' + err.message, 'warn'); } @@ -2541,7 +2986,6 @@ on({ id: NSPanel_Path + 'popupNotify.popupNotifyAction', change: 'any' }, async log('Button1 was pressed', 'info'); } } else if (val) { - const internalName: string = getState(NSPanel_Path + 'popupNotify.popupNotifyInternalName').val; if (internalName.includes('Update')) { if (internalName == 'TasmotaFirmwareUpdate') { @@ -2566,20 +3010,28 @@ async function get_panel_update_data() { if (isSetOptionActive) { await createStateAsync(NSPanel_Path + 'Config.Update.UpdateMessage', true, { read: true, write: true, name: 'Update-Message', type: 'boolean', def: true }); if (autoCreateAlias) { - setObject(AliasPath + 'Config.Update.UpdateMessage', {type: 'channel', common: {role: 'socket', name:'UpdateMesssage'}, native: {}}); - await createAliasAsync(AliasPath + 'Config.Update.UpdateMessage.ACTUAL', NSPanel_Path + 'Config.Update.UpdateMessage', true, { type: 'boolean', role: 'switch', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Config.Update.UpdateMessage.SET', NSPanel_Path + 'Config.Update.UpdateMessage', true, { type: 'boolean', role: 'switch', name: 'SET' }); + setObject(AliasPath + 'Config.Update.UpdateMessage', { type: 'channel', common: { role: 'socket', name: 'UpdateMesssage' }, native: {} }); + await createAliasAsync(AliasPath + 'Config.Update.UpdateMessage.ACTUAL', NSPanel_Path + 'Config.Update.UpdateMessage', true, { + type: 'boolean', + role: 'switch', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'Config.Update.UpdateMessage.SET', NSPanel_Path + 'Config.Update.UpdateMessage', true, { + type: 'boolean', + role: 'switch', + name: 'SET', + }); } await createStateAsync(NSPanel_Path + 'NSPanel_autoUpdate', false, { read: true, write: true, name: 'Auto-Update', type: 'boolean', def: false }); if (autoCreateAlias) { - setObject(AliasPath + 'autoUpdate', {type: 'channel', common: {role: 'socket', name:'AutoUpdate'}, native: {}}); + setObject(AliasPath + 'autoUpdate', { type: 'channel', common: { role: 'socket', name: 'AutoUpdate' }, native: {} }); await createAliasAsync(AliasPath + 'autoUpdate.ACTUAL', NSPanel_Path + 'NSPanel_autoUpdate', true, { type: 'boolean', role: 'switch', name: 'ACTUAL' }); await createAliasAsync(AliasPath + 'autoUpdate.SET', NSPanel_Path + 'NSPanel_autoUpdate', true, { type: 'boolean', role: 'switch', name: 'SET' }); } await createStateAsync(NSPanel_Path + 'NSPanel_ipAddress', { type: 'string', write: false }); await setStateAsync(NSPanel_Path + 'NSPanel_ipAddress', { val: get_current_tasmota_ip_address(), ack: true }); if (autoCreateAlias) { - setObject(AliasPath + 'ipAddress', {type: 'channel', common: {role: 'info', name:'ipAddress'}, native: {}}); + setObject(AliasPath + 'ipAddress', { type: 'channel', common: { role: 'info', name: 'ipAddress' }, native: {} }); await createAliasAsync(AliasPath + 'ipAddress.ACTUAL', NSPanel_Path + 'NSPanel_ipAddress', true, { type: 'string', role: 'state', name: 'ACTUAL' }); } get_online_tasmota_firmware_version(); @@ -2616,22 +3068,27 @@ function get_online_tasmota_firmware_version() { let urlString: string = 'https://api.github.com/repositories/80286288/releases/latest'; - axios.get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) .then(async function (response) { if (response.status === 200) { if (Debug) { log(JSON.stringify(response.data), 'info'); } if (isSetOptionActive) { - const Tasmota_JSON = JSON.parse(JSON.stringify(response.data));// Write JSON result to variable - const TasmotaTagName = Tasmota_JSON.tag_name; // Filter JSON by "tag_name" and write to variable + const Tasmota_JSON = JSON.parse(JSON.stringify(response.data)); // Write JSON result to variable + const TasmotaTagName = Tasmota_JSON.tag_name; // Filter JSON by "tag_name" and write to variable const TasmotaVersionOnline = TasmotaTagName.replace(/v/i, ''); // Filter unnecessary "v" from variable and write to release variable await createStateAsync(NSPanel_Path + 'Tasmota_Firmware.onlineVersion', { type: 'string', write: false }); - setObject(AliasPath + 'Tasmota_Firmware.onlineVersion', {type: 'channel', common: {role: 'info', name:'onlineVersion'}, native: {}}); - await createAliasAsync(AliasPath + 'Tasmota_Firmware.onlineVersion.ACTUAL', NSPanel_Path + 'Tasmota_Firmware.onlineVersion', true, { type: 'string', role: 'state', name: 'ACTUAL' }); + setObject(AliasPath + 'Tasmota_Firmware.onlineVersion', { type: 'channel', common: { role: 'info', name: 'onlineVersion' }, native: {} }); + await createAliasAsync(AliasPath + 'Tasmota_Firmware.onlineVersion.ACTUAL', NSPanel_Path + 'Tasmota_Firmware.onlineVersion', true, { + type: 'string', + role: 'state', + name: 'ACTUAL', + }); await setStateAsync(NSPanel_Path + 'Tasmota_Firmware.onlineVersion', { val: TasmotaVersionOnline, ack: true }); if (Debug) log('online tasmota firmware version => ' + TasmotaVersionOnline, 'info'); - } + } } else { log('Axios Status - online tasmota firmware version: ' + response.state, 'warn'); } @@ -2639,7 +3096,6 @@ function get_online_tasmota_firmware_version() { .catch(function (error) { log(error, 'warn'); }); - } catch (err: any) { log('error requesting firmware in function get_online_tasmota_firmware_version: ' + err.message, 'warn'); } @@ -2656,7 +3112,8 @@ function get_current_berry_driver_version() { urlString = `http://${get_current_tasmota_ip_address()}/cm?user=${tasmota_web_admin_user}&password=${tasmota_web_admin_password}&cmnd=GetDriverVersion`; } - axios.get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) .then(async function (response) { if (response.status === 200) { if (Debug) { @@ -2667,8 +3124,12 @@ function get_current_berry_driver_version() { await createStateAsync(NSPanel_Path + 'Berry_Driver.currentVersion', { type: 'string', write: false }); await setStateAsync(NSPanel_Path + 'Berry_Driver.currentVersion', { val: JSON.parse(JSON.stringify(response.data)).nlui_driver_version, ack: true }); if (autoCreateAlias) { - setObject(AliasPath + 'Display.BerryDriver', {type: 'channel', common: {role: 'info', name: 'Berry Driver'}, native: {}}); - await createAliasAsync(AliasPath + 'Display.BerryDriver.ACTUAL', NSPanel_Path + 'Berry_Driver.currentVersion', true, { type: 'string', role: 'state', name: 'ACTUAL' }); + setObject(AliasPath + 'Display.BerryDriver', { type: 'channel', common: { role: 'info', name: 'Berry Driver' }, native: {} }); + await createAliasAsync(AliasPath + 'Display.BerryDriver.ACTUAL', NSPanel_Path + 'Berry_Driver.currentVersion', true, { + type: 'string', + role: 'state', + name: 'ACTUAL', + }); } if (Debug) log('current berry driver version => ' + BerryDriverVersionCurrent, 'info'); } @@ -2678,10 +3139,9 @@ function get_current_berry_driver_version() { }) .catch(function (error) { if (error.code === 'EHOSTUNREACH') { - log(`Can't connect to display!`, 'warn') + log(`Can't connect to display!`, 'warn'); } else log(error, 'warn'); }); - } catch (err: any) { log('error requesting firmware in function get_current_berry_driver_version: ' + err.message, 'warn'); } @@ -2690,15 +3150,16 @@ function get_current_berry_driver_version() { function get_tasmota_status0() { try { if (Debug) { - log('Requesting tasmota status0', 'info'); + log('Requesting tasmota status0', 'info'); } - + let urlString = `http://${get_current_tasmota_ip_address()}/cm?cmnd=Status0`; if (tasmota_web_admin_password != '') { urlString = `http://${get_current_tasmota_ip_address()}/cm?user=${tasmota_web_admin_user}&password=${tasmota_web_admin_password}&cmnd=Status0`; } - axios.get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) .then(async function (response) { if (response.status === 200) { if (Debug) { @@ -2740,27 +3201,55 @@ function get_tasmota_status0() { log('error setState in function get_tasmota_status0' + err.message, 'warn'); } if (autoCreateAlias) { - setObject(AliasPath + 'Tasmota.Uptime', {type: 'channel', common: {role: 'info', name: 'Uptime'}, native: {}}); - setObject(AliasPath + 'Tasmota.Version', {type: 'channel', common: {role: 'info', name:'Version'}, native: {}}); - setObject(AliasPath + 'Tasmota.Hardware', {type: 'channel', common: {role: 'info', name: 'Hardware'}, native: {}}); - setObject(AliasPath + 'Tasmota.Wifi.AP', {type: 'channel', common: {role: 'info', name:'AP'}, native: {}}); - setObject(AliasPath + 'Tasmota.Wifi.SSId', {type: 'channel', common: {role: 'info', name:'SSId'}, native: {}}); - setObject(AliasPath + 'Tasmota.Wifi.BSSId', {type: 'channel', common: {role: 'info', name: 'BSSId'}, native: {}}); - setObject(AliasPath + 'Tasmota.Wifi.Channel', {type: 'channel', common: {role: 'info', name:'Channel'}, native: {}}); - setObject(AliasPath + 'Tasmota.Wifi.Mode', {type: 'channel', common: {role: 'info', name: 'Mode'}, native: {}}); - setObject(AliasPath + 'Tasmota.Wifi.RSSI', {type: 'channel', common: {role: 'info', name:'RSSI'}, native: {}}); - setObject(AliasPath + 'Tasmota.Wifi.Signal', {type: 'channel', common: {role: 'info', name:'Signal'}, native: {}}); - setObject(AliasPath + 'Tasmota.Product', {type: 'channel', common: {role: 'info', name:'Product'}, native: {}}); + setObject(AliasPath + 'Tasmota.Uptime', { type: 'channel', common: { role: 'info', name: 'Uptime' }, native: {} }); + setObject(AliasPath + 'Tasmota.Version', { type: 'channel', common: { role: 'info', name: 'Version' }, native: {} }); + setObject(AliasPath + 'Tasmota.Hardware', { type: 'channel', common: { role: 'info', name: 'Hardware' }, native: {} }); + setObject(AliasPath + 'Tasmota.Wifi.AP', { type: 'channel', common: { role: 'info', name: 'AP' }, native: {} }); + setObject(AliasPath + 'Tasmota.Wifi.SSId', { type: 'channel', common: { role: 'info', name: 'SSId' }, native: {} }); + setObject(AliasPath + 'Tasmota.Wifi.BSSId', { type: 'channel', common: { role: 'info', name: 'BSSId' }, native: {} }); + setObject(AliasPath + 'Tasmota.Wifi.Channel', { type: 'channel', common: { role: 'info', name: 'Channel' }, native: {} }); + setObject(AliasPath + 'Tasmota.Wifi.Mode', { type: 'channel', common: { role: 'info', name: 'Mode' }, native: {} }); + setObject(AliasPath + 'Tasmota.Wifi.RSSI', { type: 'channel', common: { role: 'info', name: 'RSSI' }, native: {} }); + setObject(AliasPath + 'Tasmota.Wifi.Signal', { type: 'channel', common: { role: 'info', name: 'Signal' }, native: {} }); + setObject(AliasPath + 'Tasmota.Product', { type: 'channel', common: { role: 'info', name: 'Product' }, native: {} }); await createAliasAsync(AliasPath + 'Tasmota.Uptime.ACTUAL', NSPanel_Path + 'Tasmota.Uptime', true, { type: 'string', role: 'state', name: 'ACTUAL' }); await createAliasAsync(AliasPath + 'Tasmota.Version.ACTUAL', NSPanel_Path + 'Tasmota.Version', true, { type: 'string', role: 'state', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Tasmota.Hardware.ACTUAL', NSPanel_Path + 'Tasmota.Hardware', true, { type: 'string', role: 'state', name: 'ACTUAL' }); + await createAliasAsync(AliasPath + 'Tasmota.Hardware.ACTUAL', NSPanel_Path + 'Tasmota.Hardware', true, { + type: 'string', + role: 'state', + name: 'ACTUAL', + }); await createAliasAsync(AliasPath + 'Tasmota.Wifi.AP.ACTUAL', NSPanel_Path + 'Tasmota.Wifi.AP', true, { type: 'number', role: 'state', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Tasmota.Wifi.SSId.ACTUAL', NSPanel_Path + 'Tasmota.Wifi.SSId', true, { type: 'string', role: 'state', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Tasmota.Wifi.BSSId.ACTUAL', NSPanel_Path + 'Tasmota.Wifi.BSSId', true, { type: 'string', role: 'state', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Tasmota.Wifi.Channel.ACTUAL', NSPanel_Path + 'Tasmota.Wifi.Channel', true, { type: 'number', role: 'state', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Tasmota.Wifi.Mode.ACTUAL', NSPanel_Path + 'Tasmota.Wifi.Mode', true, { type: 'string', role: 'state', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Tasmota.Wifi.RSSI.ACTUAL', NSPanel_Path + 'Tasmota.Wifi.RSSI', true, { type: 'number', role: 'state', name: 'ACTUAL' }); - await createAliasAsync(AliasPath + 'Tasmota.Wifi.Signal.ACTUAL', NSPanel_Path + 'Tasmota.Wifi.Signal', true, { type: 'number', role: 'state', name: 'ACTUAL' }); + await createAliasAsync(AliasPath + 'Tasmota.Wifi.SSId.ACTUAL', NSPanel_Path + 'Tasmota.Wifi.SSId', true, { + type: 'string', + role: 'state', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'Tasmota.Wifi.BSSId.ACTUAL', NSPanel_Path + 'Tasmota.Wifi.BSSId', true, { + type: 'string', + role: 'state', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'Tasmota.Wifi.Channel.ACTUAL', NSPanel_Path + 'Tasmota.Wifi.Channel', true, { + type: 'number', + role: 'state', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'Tasmota.Wifi.Mode.ACTUAL', NSPanel_Path + 'Tasmota.Wifi.Mode', true, { + type: 'string', + role: 'state', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'Tasmota.Wifi.RSSI.ACTUAL', NSPanel_Path + 'Tasmota.Wifi.RSSI', true, { + type: 'number', + role: 'state', + name: 'ACTUAL', + }); + await createAliasAsync(AliasPath + 'Tasmota.Wifi.Signal.ACTUAL', NSPanel_Path + 'Tasmota.Wifi.Signal', true, { + type: 'number', + role: 'state', + name: 'ACTUAL', + }); await createAliasAsync(AliasPath + 'Tasmota.Product.ACTUAL', NSPanel_Path + 'Tasmota.Product', true, { type: 'string', role: 'state', name: 'ACTUAL' }); } } @@ -2770,10 +3259,9 @@ function get_tasmota_status0() { }) .catch(function (error) { if (error.code === 'EHOSTUNREACH') { - log(`Can't connect to display!`, 'warn') + log(`Can't connect to display!`, 'warn'); } else log(error, 'error'); }); - } catch (err: any) { log('error requesting firmware in function get_tasmota_status0: ' + err.message, 'warn'); } @@ -2788,17 +3276,24 @@ function get_online_berry_driver_version() { let urlString = 'https://raw.githubusercontent.com/joBr99/nspanel-lovelace-ui/main/tasmota/autoexec.be'; - axios.get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) .then(async function (response) { if (response.status === 200) { if (Debug) { log(response.data, 'info'); } if (isSetOptionActive) { - const BerryDriverVersionOnline = response.data.substring((response.data.indexOf('version_of_this_script = ') + 24), response.data.indexOf('version_of_this_script = ') + 27).replace(/\s+/g, ''); + const BerryDriverVersionOnline = response.data + .substring(response.data.indexOf('version_of_this_script = ') + 24, response.data.indexOf('version_of_this_script = ') + 27) + .replace(/\s+/g, ''); await createStateAsync(NSPanel_Path + 'Berry_Driver.onlineVersion', { type: 'string', write: false }); - setObject(AliasPath + 'Berry_Driver.onlineVersion', {type: 'channel', common: {role: 'info', name:'onlineVersion'}, native: {}}); - await createAliasAsync(AliasPath + 'Berry_Driver.onlineVersion.ACTUAL', NSPanel_Path + 'Berry_Driver.onlineVersion', true, { type: 'string', role: 'state', name: 'ACTUAL' }); + setObject(AliasPath + 'Berry_Driver.onlineVersion', { type: 'channel', common: { role: 'info', name: 'onlineVersion' }, native: {} }); + await createAliasAsync(AliasPath + 'Berry_Driver.onlineVersion.ACTUAL', NSPanel_Path + 'Berry_Driver.onlineVersion', true, { + type: 'string', + role: 'state', + name: 'ACTUAL', + }); await setStateAsync(NSPanel_Path + 'Berry_Driver.onlineVersion', { val: BerryDriverVersionOnline, ack: true }); if (Debug) log('online berry driver version => ' + BerryDriverVersionOnline, 'info'); } @@ -2809,7 +3304,6 @@ function get_online_berry_driver_version() { .catch(function (error) { log(error, 'warn'); }); - } } catch (err: any) { log('error requesting firmware in function get_online_berry_driver_version: ' + err.message, 'warn'); @@ -2824,15 +3318,16 @@ function check_version_tft_firmware() { let urlString = 'https://api.github.com/repos/joBr99/nspanel-lovelace-ui/releases/latest'; - axios.get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) .then(async function (response) { if (response.status === 200) { if (Debug) { log(JSON.stringify(response.data), 'info'); } let NSPanel_JSON = JSON.parse(JSON.stringify(response.data)); // Write JSON result to variable - let NSPanelTagName = NSPanel_JSON.tag_name; // created_at; published_at; name ; draft ; prerelease - let NSPanelVersion = NSPanelTagName.replace(/v/i, ''); // Filter unnecessary "v" from variable and write to release variable + let NSPanelTagName = NSPanel_JSON.tag_name; // created_at; published_at; name ; draft ; prerelease + let NSPanelVersion = NSPanelTagName.replace(/v/i, ''); // Filter unnecessary "v" from variable and write to release variable await createStateAsync(NSPanel_Path + 'TFT_Firmware.onlineVersion', { type: 'string', write: false }); await setStateAsync(NSPanel_Path + 'TFT_Firmware.onlineVersion', { val: NSPanelVersion, ack: true }); @@ -2844,7 +3339,6 @@ function check_version_tft_firmware() { .catch(function (error) { log(error, 'warn'); }); - } catch (err: any) { log('error requesting firmware in function check_version_tft_firmware: ' + err.message, 'warn'); } @@ -2858,13 +3352,16 @@ function check_online_display_firmware() { let urlString = 'https://raw.githubusercontent.com/joBr99/nspanel-lovelace-ui/main/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py'; - axios.get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) .then(async function (response) { if (response.status === 200) { if (Debug) { log(response.data, 'info'); } - let desired_display_firmware_version = response.data.substring((response.data.indexOf('desired_display_firmware_version =') + 34), response.data.indexOf('desired_display_firmware_version =') + 38).replace(/\s+/g, ''); + let desired_display_firmware_version = response.data + .substring(response.data.indexOf('desired_display_firmware_version =') + 34, response.data.indexOf('desired_display_firmware_version =') + 38) + .replace(/\s+/g, ''); await createStateAsync(NSPanel_Path + 'Display_Firmware.onlineVersion', { type: 'string', write: false }); await setStateAsync(NSPanel_Path + 'Display_Firmware.onlineVersion', { val: desired_display_firmware_version, ack: true }); @@ -2876,7 +3373,6 @@ function check_online_display_firmware() { .catch(function (error) { log(error, 'warn'); }); - } catch (err: any) { log('error requesting firmware in function check_online_display_firmware: ' + err.message, 'warn'); } @@ -2884,45 +3380,47 @@ function check_online_display_firmware() { //mqttCallback (topic: string, message: string): Promise { on({ id: config.panelRecvTopic }, async (obj) => { - if (obj.state.val.startsWith('\{"CustomRecv":')) { + if (obj.state.val.startsWith('{"CustomRecv":')) { try { const json = JSON.parse(obj.state.val); const split = json.CustomRecv.split(','); if (isSetOptionActive) { - if (split[0] == 'event' && split[1] == 'startup') { await createStateAsync(NSPanel_Path + 'Display_Firmware.currentVersion', { type: 'string', write: false }); await createStateAsync(NSPanel_Path + 'NSPanel_Version', { type: 'string', write: false }); await setStateAsync(NSPanel_Path + 'Display_Firmware.currentVersion', { val: split[2], ack: true }); await setStateAsync(NSPanel_Path + 'NSPanel_Version', { val: split[3], ack: true }); - + if (autoCreateAlias) { - setObject(AliasPath + 'Display.TFTVersion', {type: 'channel', common: {role: 'info', name:'Display.TFTVersion'}, native: {}}); - setObject(AliasPath + 'Display.Model', {type: 'channel', common: {role: 'info', name:'Display.Model'}, native: {}}); - await createAliasAsync(AliasPath + 'Display.TFTVersion.ACTUAL', NSPanel_Path + 'Display_Firmware.currentVersion', true, { type: 'string', role: 'state', name: 'ACTUAL' }); + setObject(AliasPath + 'Display.TFTVersion', { type: 'channel', common: { role: 'info', name: 'Display.TFTVersion' }, native: {} }); + setObject(AliasPath + 'Display.Model', { type: 'channel', common: { role: 'info', name: 'Display.Model' }, native: {} }); + await createAliasAsync(AliasPath + 'Display.TFTVersion.ACTUAL', NSPanel_Path + 'Display_Firmware.currentVersion', true, { + type: 'string', + role: 'state', + name: 'ACTUAL', + }); await createAliasAsync(AliasPath + 'Display.Model.ACTUAL', NSPanel_Path + 'NSPanel_Version', true, { type: 'string', role: 'state', name: 'ACTUAL' }); } } } - + if (isEventMethod(split[1])) HandleMessage(split[0], split[1], parseInt(split[2]), split); } catch (err: any) { log('error at trigger rceiving CustomRecv: ' + err.message, 'warn'); } - } }); function update_berry_driver_version() { try { - let urlString = `http://${get_current_tasmota_ip_address()}/cm?cmnd=Backlog UpdateDriverVersion https://raw.githubusercontent.com/joBr99/nspanel-lovelace-ui/main/tasmota/autoexec.be; Restart 1`; if (tasmota_web_admin_password != '') { urlString = `http://${get_current_tasmota_ip_address()}/cm?user=${tasmota_web_admin_user}&password=${tasmota_web_admin_password}&cmnd=Backlog UpdateDriverVersion https://raw.githubusercontent.com/joBr99/nspanel-lovelace-ui/main/tasmota/autoexec.be; Restart 1`; - } - - axios.get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + } + + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) .then(async function (response) { if (response.status === 200) { if (Debug) { @@ -2935,22 +3433,20 @@ function update_berry_driver_version() { .catch(function (error) { log(error, 'warn'); }); - } catch (err: any) { - log('error at function update_berry_driver_version: ' + err.message, 'warn'); + log('error at function update_berry_driver_version: ' + err.message, 'warn'); } } function update_tft_firmware() { if (getState(NSPanel_Path + 'Config.Update.activ').val == 0) { - - let desired_display_firmware_url ="" - - if(getState(NSPanel_Path + 'NSPanel_Version').val =="us-l"){ + let desired_display_firmware_url = ''; + + if (getState(NSPanel_Path + 'NSPanel_Version').val == 'us-l') { desired_display_firmware_url = `http://nspanel.pky.eu/lovelace-ui/github/nspanel-us-l-${tft_version}.tft`; - }else if (getState(NSPanel_Path + 'NSPanel_Version').val =="us-p"){ + } else if (getState(NSPanel_Path + 'NSPanel_Version').val == 'us-p') { desired_display_firmware_url = `http://nspanel.pky.eu/lovelace-ui/github/nspanel-us-p-${tft_version}.tft`; - }else{ + } else { desired_display_firmware_url = `http://nspanel.pky.eu/lovelace-ui/github/nspanel-${tft_version}.tft`; } @@ -2958,13 +3454,13 @@ function update_tft_firmware() { log('Install NextionTFT: ' + desired_display_firmware_url, 'info'); try { - let urlString = `http://${get_current_tasmota_ip_address()}/cm?cmnd=FlashNextion ${desired_display_firmware_url}`; if (tasmota_web_admin_password != '') { urlString = `http://${get_current_tasmota_ip_address()}/cm?user=${tasmota_web_admin_user}&password=${tasmota_web_admin_password}&cmnd=FlashNextion ${desired_display_firmware_url}`; } - axios.get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) .then(async function (response) { if (response.status === 200) { if (Debug) { @@ -2980,7 +3476,6 @@ function update_tft_firmware() { .catch(function (error) { log(error, 'warn'); }); - } catch (err: any) { log('error request in function update_tft_firmware: ' + err.message, 'warn'); } @@ -2995,7 +3490,8 @@ function update_tasmota_firmware() { urlString = `http://${get_current_tasmota_ip_address()}/cm?user=${tasmota_web_admin_user}&password=${tasmota_web_admin_password}&cmnd=OtaUrl ${tasmotaOtaUrl}${tasmotaOtaVersion}`; } - axios.get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) .then(async function (response) { if (response.status === 200) { if (Debug) { @@ -3014,7 +3510,8 @@ function update_tasmota_firmware() { urlString = `http://${get_current_tasmota_ip_address()}/cm?user=${tasmota_web_admin_user}&password=${tasmota_web_admin_password}&cmnd=Upgrade 1`; } - axios.get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) .then(async function (response) { if (response.status === 200) { if (Debug) { @@ -3027,14 +3524,13 @@ function update_tasmota_firmware() { .catch(function (error) { log(error, 'warn'); }); - - } + } } catch (err: any) { log('error request in function update_tasmota_firmware: ' + err.message, 'warn'); } } //mqttCallback (topic: string, message: string): Promise { -on({ id: config.panelRecvTopic.substring(0, config.panelRecvTopic.length - 'RESULT'.length) + 'INFO1', change: 'ne'}, async (obj) => { +on({ id: config.panelRecvTopic.substring(0, config.panelRecvTopic.length - 'RESULT'.length) + 'INFO1', change: 'ne' }, async (obj) => { try { if (getState(NSPanel_Path + 'Config.Update.activ').val == 0) { let Tasmota_JSON: any = JSON.parse(obj.state.val); @@ -3048,7 +3544,7 @@ on({ id: config.panelRecvTopic.substring(0, config.panelRecvTopic.length - 'RESU } } } catch (err: any) { - log('error at trigger with reading senor-data: '+ err.message, 'warn'); + log('error at trigger with reading senor-data: ' + err.message, 'warn'); } }); @@ -3066,7 +3562,6 @@ async function SendToPanel(val: NSPanel.Payload | NSPanel.Payload[]) { } else { setIfExists(config.panelSendTopic, val.payload); } - } catch (err: any) { log('error at function SendToPanel: ' + err.message, 'warn'); } @@ -3103,8 +3598,7 @@ function HandleMessage(typ: string, method: NSPanel.EventMethod, page: number | case 'sleepReached': useMediaEvents = false; screensaverEnabled = true; - if (pageId < 0) - pageId = 0; + if (pageId < 0) pageId = 0; HandleScreensaver(); if (Debug) log('HandleMessage -> sleepReached', 'info'); break; @@ -3118,18 +3612,18 @@ function HandleMessage(typ: string, method: NSPanel.EventMethod, page: number | let tempId: PageItem['id']; let tempPageItem = words[3].split('?'); let placeId: number | undefined = undefined; - if (!isNaN(parseInt(tempPageItem[0]))){ + if (!isNaN(parseInt(tempPageItem[0]))) { tempId = activePage!.items[tempPageItem[0]].id; - placeId = parseInt(tempPageItem[0]) + placeId = parseInt(tempPageItem[0]); if (tempId == undefined) { - throw new Error(`Missing id in HandleMessage!`) + throw new Error(`Missing id in HandleMessage!`); } } else { tempId = tempPageItem[0]; } let pageItem: PageItem = findPageItem(tempId); if (pageItem !== undefined && isPopupType(words[2])) { - let temp: string | NSPanel.mediaOptional | undefined = tempPageItem[1] + let temp: string | NSPanel.mediaOptional | undefined = tempPageItem[1]; if (isMediaOptional(temp)) SendToPanel(GenerateDetailPage(words[2], temp, pageItem, placeId)); else SendToPanel(GenerateDetailPage(words[2], undefined, pageItem, placeId)); } @@ -3150,7 +3644,7 @@ function HandleMessage(typ: string, method: NSPanel.EventMethod, page: number | case 'button2': screensaverEnabled = false; HandleHardwareButton(method); - if (Debug) log('HandleMessage -> button1 / button2', 'info') + if (Debug) log('HandleMessage -> button1 / button2', 'info'); break; default: break; @@ -3163,16 +3657,15 @@ function HandleMessage(typ: string, method: NSPanel.EventMethod, page: number | //@ts-ignore ticaki bitte lösen, rückgabe kann undefined sein und ist es wenn ins catch gesprungen wird. function findPageItem(searching: String): PageItem { try { - - let pageItem = activePage!.items.find(e => e.id === searching); + let pageItem = activePage!.items.find((e) => e.id === searching); if (pageItem !== undefined) { if (Debug) log('findPageItem -> pageItem ' + JSON.stringify(pageItem), 'info'); return pageItem; } - config.subPages.every(sp => { - pageItem = sp.items.find(e => e.id === searching); + config.subPages.every((sp) => { + pageItem = sp.items.find((e) => e.id === searching); return pageItem === undefined; }); @@ -3239,14 +3732,14 @@ function GeneratePage(page: PageType): void { function HandleHardwareButton(method: NSPanel.EventMethod): void { try { let buttonConfig: NSPanel.ConfigButtonFunction = config[method]; - if(buttonConfig.mode === null) { + if (buttonConfig.mode === null) { return; } - switch(buttonConfig.mode) { + switch (buttonConfig.mode) { case 'page': if (Debug) log('HandleHardwareButton -> Mode Page', 'info'); if (buttonConfig.page) { - if(method == 'button1') { + if (method == 'button1') { pageId = -1; } else if (method == 'button2') { pageId = -2; @@ -3292,7 +3785,7 @@ function SendDate(): void { if (existsObject(NSPanel_Path + 'Config.locale')) { let dpWeekday = existsObject(NSPanel_Path + 'Config.Dateformat.weekday') ? getState(NSPanel_Path + 'Config.Dateformat.weekday').val : 'short'; let dpMonth = existsObject(NSPanel_Path + 'Config.Dateformat.month') ? getState(NSPanel_Path + 'Config.Dateformat.month').val : 'short'; - let dpCustomFormat = existsObject(NSPanel_Path + 'Config.Dateformat.customFormat') ? getState(NSPanel_Path + 'Config.Dateformat.customFormat').val : ''; + let dpCustomFormat = existsObject(NSPanel_Path + 'Config.Dateformat.customFormat') ? getState(NSPanel_Path + 'Config.Dateformat.customFormat').val : ''; const date = new Date(); const options: any = { weekday: dpWeekday, year: 'numeric', month: dpMonth, day: 'numeric' }; @@ -3301,7 +3794,7 @@ function SendDate(): void { SendToPanel({ payload: 'date~' + _SendDate }); } } catch (err: any) { - if (err.message = 'Cannot convert undefined or null to object') { + if ((err.message = 'Cannot convert undefined or null to object')) { log('Datumsformat noch nicht initialisiert', 'info'); } else { log('error at function SendDate: ' + err.message, 'warn'); @@ -3316,7 +3809,7 @@ function SendTime(): void { const min = (d.getMinutes() < 10 ? '0' : '') + d.getMinutes(); SendToPanel({ payload: 'time~' + hr + ':' + min });*/ - SendToPanel({ payload: `time~${new Date().toLocaleTimeString('de-DE', { hour: "2-digit", minute: "2-digit" })}`, }); + SendToPanel({ payload: `time~${new Date().toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit' })}` }); } catch (err: any) { log('error at function SendTime: ' + err.message, 'warn'); } @@ -3325,9 +3818,9 @@ function SendTime(): void { function GenerateEntitiesPage(page: NSPanel.PageEntities): NSPanel.Payload[] { try { let out_msgs: NSPanel.Payload[]; - out_msgs = [{ payload: 'pageType~cardEntities' }] + out_msgs = [{ payload: 'pageType~cardEntities' }]; out_msgs.push({ payload: GeneratePageElements(page) }); - return out_msgs + return out_msgs; } catch (err: any) { log('error at function GenerateEntitiesPage: ' + err.message, 'warn'); return []; @@ -3397,7 +3890,7 @@ function GeneratePageElements(page: PageType): string { maxItems = 9; } else { maxItems = 8; - }; + } break; } @@ -3405,7 +3898,7 @@ function GeneratePageElements(page: PageType): string { for (let index = 0; index < maxItems; index++) { if (page.items[index] !== undefined) { - pageData += CreateEntity(page.items[index], index, 'useColor' in page ? page.useColor : false ); + pageData += CreateEntity(page.items[index], index, 'useColor' in page ? page.useColor : false); } } if (Debug) log('GeneratePageElements pageData ' + pageData, 'info'); @@ -3423,45 +3916,43 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = if (pageItem.id == 'delete') { return '~delete~~~~~'; } - + let name: string; let buttonText: string = 'PRESS'; let type: NSPanel.SerialType; // ioBroker - if (pageItem.id && existsObject(pageItem.id) || pageItem.navigate === true) { - - let iconColor:number = rgb_dec565(config.defaultColor); - let optVal:string = '0'; + if ((pageItem.id && existsObject(pageItem.id)) || pageItem.navigate === true) { + let iconColor: number = rgb_dec565(config.defaultColor); + let optVal: string = '0'; let val: any = null; - - let o:any = undefined; + + let o: any = undefined; if (pageItem.id != null && existsObject(pageItem.id)) { o = getObject(pageItem.id); - } - + } + // Fallback if no name is given name = pageItem.name !== undefined ? pageItem.name : o.common.name.de == undefined ? o.common.name : o.common.name.de; const prefix = pageItem.prefixName !== undefined ? pageItem.prefixName : ''; const suffix = pageItem.suffixName !== undefined ? pageItem.suffixName : ''; - + // If name is used with changing values if ((name || '').indexOf('getState(') != -1) { - let dpName: string = name.slice(10, name.length -6); + let dpName: string = name.slice(10, name.length - 6); name = getState(dpName).val; RegisterEntityWatcher(dpName); - } - else if ((name || '').split('.').length > 3 && existsState(name)) { + } else if ((name || '').split('.').length > 3 && existsState(name)) { name = getState(name).val; RegisterEntityWatcher(name); } name = prefix + name + suffix; - + if (existsState(pageItem.id + '.GET')) { val = getState(pageItem.id + '.GET').val; RegisterEntityWatcher(pageItem.id + '.GET'); } - if(pageItem.monobutton != undefined && pageItem.monobutton == true){ + if (pageItem.monobutton != undefined && pageItem.monobutton == true) { if (existsState(pageItem.id + '.ACTUAL')) { val = getState(pageItem.id + '.ACTUAL').val; RegisterEntityWatcher(pageItem.id + '.ACTUAL'); @@ -3479,7 +3970,7 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = if (existsState(pageItem.id + '.ON_ACTUAL')) { val = getState(pageItem.id + '.ON_ACTUAL').val; RegisterEntityWatcher(pageItem.id + '.ON_ACTUAL'); - } + } if (existsState(pageItem.id + '.ON_SET')) { val = getState(pageItem.id + '.ON_SET').val; RegisterEntityWatcher(pageItem.id + '.ON_SET'); @@ -3488,20 +3979,18 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = val = getState(pageItem.id + '.ON').val; RegisterEntityWatcher(pageItem.id + '.ON'); } - + if (pageItem.navigate) { - if (pageItem.id == null && pageItem.targetPage != undefined) { buttonText = pageItem.buttonText !== undefined ? pageItem.buttonText : 'PRESS'; type = 'button'; iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('gesture-tap-button'); iconColor = GetIconColor(pageItem, true, useColors); - - if (Debug) log('CreateEntity statisch Icon Navi ~' + type + '~' + 'navigate.' + pageItem.targetPage + '~' + iconId + '~' + iconColor + '~' + pageItem.name + '~' + buttonText, 'info') + + if (Debug) + log('CreateEntity statisch Icon Navi ~' + type + '~' + 'navigate.' + pageItem.targetPage + '~' + iconId + '~' + iconColor + '~' + pageItem.name + '~' + buttonText, 'info'); return '~' + type + '~' + 'navigate.' + pageItem.targetPage + '~' + iconId + '~' + iconColor + '~' + name + '~' + buttonText; - } else if (pageItem.id != null && pageItem.targetPage != undefined) { - type = 'button'; const role = o.common.role as NSPanel.roles; switch (role) { @@ -3509,7 +3998,7 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = case 'light': iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : role == 'socket' ? Icons.GetIcon('power-socket-de') : Icons.GetIcon('lightbulb'); iconId2 = pageItem.icon2 !== undefined ? Icons.GetIcon(pageItem.icon2) : iconId; - + buttonText = pageItem.buttonText !== undefined ? pageItem.buttonText : existsState(pageItem.id + '.BUTTONTEXT') ? getState(pageItem.id + '.BUTTONTEXT').val : 'PRESS'; if (existsState(pageItem.id + '.COLORDEC')) { iconColor = getState(pageItem.id + '.COLORDEC').val; @@ -3520,20 +4009,24 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = iconColor = GetIconColor(pageItem, false, useColors); } } - if (val === true || val === 'true') { iconId = iconId2 }; + if (val === true || val === 'true') { + iconId = iconId2; + } break; - + case 'blind': iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('window-open'); - iconColor = existsState(pageItem.id + '.COLORDEC') ? getState(pageItem.id + '.COLORDEC').val : GetIconColor(pageItem, existsState(pageItem.id + '.ACTUAL') ? getState(pageItem.id + '.ACTUAL').val : true, useColors); + iconColor = existsState(pageItem.id + '.COLORDEC') + ? getState(pageItem.id + '.COLORDEC').val + : GetIconColor(pageItem, existsState(pageItem.id + '.ACTUAL') ? getState(pageItem.id + '.ACTUAL').val : true, useColors); buttonText = pageItem.buttonText !== undefined ? pageItem.buttonText : existsState(pageItem.id + '.BUTTONTEXT') ? getState(pageItem.id + '.BUTTONTEXT').val : 'PRESS'; break; - + case 'door': case 'window': iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : role == 'door' ? Icons.GetIcon('door-closed') : Icons.GetIcon('window-closed-variant'); iconId2 = pageItem.icon2 !== undefined ? Icons.GetIcon(pageItem.icon2) : role == 'door' ? Icons.GetIcon('door-open') : Icons.GetIcon('window-open-variant'); - + buttonText = pageItem.buttonText !== undefined ? pageItem.buttonText : existsState(pageItem.id + '.BUTTONTEXT') ? getState(pageItem.id + '.BUTTONTEXT').val : 'PRESS'; if (existsState(pageItem.id + '.COLORDEC')) { iconColor = getState(pageItem.id + '.COLORDEC').val; @@ -3544,13 +4037,15 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = iconColor = GetIconColor(pageItem, false, useColors); } } - if (val === true || val === 'true') { iconId = iconId2 }; + if (val === true || val === 'true') { + iconId = iconId2; + } break; - + case 'info': iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('gesture-tap-button'); iconId2 = pageItem.icon2 !== undefined ? Icons.GetIcon(pageItem.icon2) : iconId; - + buttonText = pageItem.buttonText !== undefined ? pageItem.buttonText : existsState(pageItem.id + '.BUTTONTEXT') ? getState(pageItem.id + '.BUTTONTEXT').val : 'PRESS'; if (existsState(pageItem.id + '.COLORDEC')) { iconColor = getState(pageItem.id + '.COLORDEC').val; @@ -3563,132 +4058,138 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = } if (pageItem.colorScale != undefined) { - let iconvalmin = (pageItem.colorScale.val_min != undefined) ? pageItem.colorScale.val_min : 0 ; - let iconvalmax = (pageItem.colorScale.val_max != undefined) ? pageItem.colorScale.val_max : 100 ; - let iconvalbest = (pageItem.colorScale.val_best != undefined) ? pageItem.colorScale.val_best : iconvalmin ; + let iconvalmin = pageItem.colorScale.val_min != undefined ? pageItem.colorScale.val_min : 0; + let iconvalmax = pageItem.colorScale.val_max != undefined ? pageItem.colorScale.val_max : 100; + let iconvalbest = pageItem.colorScale.val_best != undefined ? pageItem.colorScale.val_best : iconvalmin; let valueScale = val; - + if (iconvalmin == 0 && iconvalmax == 1) { - iconColor = (getState(pageItem.id).val == 1) ? rgb_dec565(colorScale0) : rgb_dec565(colorScale10); + iconColor = getState(pageItem.id).val == 1 ? rgb_dec565(colorScale0) : rgb_dec565(colorScale10); } else { if (iconvalbest == iconvalmin) { - valueScale = scale(valueScale,iconvalmin, iconvalmax, 10, 0); + valueScale = scale(valueScale, iconvalmin, iconvalmax, 10, 0); } else { if (valueScale < iconvalbest) { - valueScale = scale(valueScale,iconvalmin, iconvalbest, 0, 10); + valueScale = scale(valueScale, iconvalmin, iconvalbest, 0, 10); } else if (valueScale > iconvalbest || iconvalbest != iconvalmin) { - valueScale = scale(valueScale,iconvalbest, iconvalmax, 10, 0); + valueScale = scale(valueScale, iconvalbest, iconvalmax, 10, 0); } else { - valueScale = scale(valueScale,iconvalmin, iconvalmax, 10, 0); + valueScale = scale(valueScale, iconvalmin, iconvalmax, 10, 0); } } - let valueScaletemp = (Math.round(valueScale)).toFixed(); + let valueScaletemp = Math.round(valueScale).toFixed(); iconColor = HandleColorScale(valueScaletemp); } } - - if (val === true || val === 'true') { iconId = iconId2 }; + + if (val === true || val === 'true') { + iconId = iconId2; + } break; - + case 'humidity': - + case 'temperature': - + case 'value.temperature': - + case 'value.humidity': - + case 'sensor.door': - + case 'sensor.window': - + case 'thermostat': - - iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : role == 'temperature' || role == 'value.temperature' || role == 'thermostat' ? Icons.GetIcon('thermometer') : Icons.GetIcon('information-outline'); - + iconId = + pageItem.icon !== undefined + ? Icons.GetIcon(pageItem.icon) + : role == 'temperature' || role == 'value.temperature' || role == 'thermostat' + ? Icons.GetIcon('thermometer') + : Icons.GetIcon('information-outline'); + let unit = ''; optVal = '0'; - + if (existsState(pageItem.id + '.ON_ACTUAL')) { optVal = getState(pageItem.id + '.ON_ACTUAL').val; unit = pageItem.unit !== undefined ? pageItem.unit : GetUnitOfMeasurement(pageItem.id + '.ON_ACTUAL'); } else if (existsState(pageItem.id + '.ACTUAL')) { optVal = getState(pageItem.id + '.ACTUAL').val; unit = pageItem.unit !== undefined ? pageItem.unit : GetUnitOfMeasurement(pageItem.id + '.ACTUAL'); - } - + } + iconColor = GetIconColor(pageItem, parseInt(optVal), useColors); - + if (pageItem.colorScale != undefined) { - let iconvalmin = (pageItem.colorScale.val_min != undefined) ? pageItem.colorScale.val_min : 0 ; - let iconvalmax = (pageItem.colorScale.val_max != undefined) ? pageItem.colorScale.val_max : 100 ; - let iconvalbest = (pageItem.colorScale.val_best != undefined) ? pageItem.colorScale.val_best : iconvalmin ; + let iconvalmin = pageItem.colorScale.val_min != undefined ? pageItem.colorScale.val_min : 0; + let iconvalmax = pageItem.colorScale.val_max != undefined ? pageItem.colorScale.val_max : 100; + let iconvalbest = pageItem.colorScale.val_best != undefined ? pageItem.colorScale.val_best : iconvalmin; let valueScale = val; - + if (iconvalmin == 0 && iconvalmax == 1) { - iconColor = (getState(pageItem.id).val == 1) ? rgb_dec565(colorScale0) : rgb_dec565(colorScale10); + iconColor = getState(pageItem.id).val == 1 ? rgb_dec565(colorScale0) : rgb_dec565(colorScale10); } else { if (iconvalbest == iconvalmin) { - valueScale = scale(valueScale,iconvalmin, iconvalmax, 10, 0); + valueScale = scale(valueScale, iconvalmin, iconvalmax, 10, 0); } else { if (valueScale < iconvalbest) { - valueScale = scale(valueScale,iconvalmin, iconvalbest, 0, 10); + valueScale = scale(valueScale, iconvalmin, iconvalbest, 0, 10); } else if (valueScale > iconvalbest || iconvalbest != iconvalmin) { - valueScale = scale(valueScale,iconvalbest, iconvalmax, 10, 0); + valueScale = scale(valueScale, iconvalbest, iconvalmax, 10, 0); } else { - valueScale = scale(valueScale,iconvalmin, iconvalmax, 10, 0); + valueScale = scale(valueScale, iconvalmin, iconvalmax, 10, 0); } } - let valueScaletemp = (Math.round(valueScale)).toFixed(); + let valueScaletemp = Math.round(valueScale).toFixed(); iconColor = HandleColorScale(valueScaletemp); } } - + if (existsState(pageItem.id + '.USERICON')) { iconId = Icons.GetIcon(getState(pageItem.id + '.USERICON').val); if (Debug) log('iconid von ' + pageItem.id + '.USERICON: ' + getState(pageItem.id + '.USERICON').val, 'info'); RegisterEntityWatcher(pageItem.id + '.USERICON'); } - + if (pageItem.useValue) { if (pageItem.fontSize != undefined) { - iconId = optVal + '¬' + pageItem.fontSize; + iconId = optVal + '¬' + pageItem.fontSize; } else { - iconId = optVal; + iconId = optVal; } } buttonText = pageItem.buttonText !== undefined ? pageItem.buttonText : existsState(pageItem.id + '.BUTTONTEXT') ? getState(pageItem.id + '.BUTTONTEXT').val : 'PRESS'; break; - + case 'warning': iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('gesture-tap-button'); iconColor = pageItem.onColor !== undefined ? GetIconColor(pageItem, true, useColors) : getState(pageItem.id + '.LEVEL').val; name = pageItem.name !== undefined ? pageItem.name : getState(pageItem.id + '.INFO').val; break; - + default: buttonText = pageItem.buttonText !== undefined ? pageItem.buttonText : existsState(pageItem.id + '.BUTTONTEXT') ? getState(pageItem.id + '.BUTTONTEXT').val : 'PRESS'; - iconColor = pageItem.onColor !== undefined ? GetIconColor(pageItem, true, useColors) : existsState(pageItem.id + '.COLORDEC') ? getState(pageItem.id + '.COLORDEC').val : 65535; + iconColor = + pageItem.onColor !== undefined ? GetIconColor(pageItem, true, useColors) : existsState(pageItem.id + '.COLORDEC') ? getState(pageItem.id + '.COLORDEC').val : 65535; iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('gesture-tap-button'); break; // return '~delete~~~~~'; } - - if (Debug) log('CreateEntity Dynamische Icon Navi ~' + type + '~' + 'navigate.' + pageItem.targetPage + '~' + iconId + '~' + iconColor + '~' + name + '~' + buttonText, 'info') + + if (Debug) log('CreateEntity Dynamische Icon Navi ~' + type + '~' + 'navigate.' + pageItem.targetPage + '~' + iconId + '~' + iconColor + '~' + name + '~' + buttonText, 'info'); return '~' + type + '~' + 'navigate.' + pageItem.targetPage + '~' + iconId + '~' + iconColor + '~' + name + '~' + buttonText; - } else { type = 'button'; iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('gesture-tap-button'); iconColor = GetIconColor(pageItem, true, useColors); buttonText = pageItem.buttonText !== undefined ? pageItem.buttonText : 'PRESS'; - - if (Debug) log('CreateEntity Standard ~' + type + '~' + 'navigate.' + pageItem.id + '~' + iconId + '~' + iconColor + '~' + name + '~' + buttonText, 'info') + + if (Debug) log('CreateEntity Standard ~' + type + '~' + 'navigate.' + pageItem.id + '~' + iconId + '~' + iconColor + '~' + name + '~' + buttonText, 'info'); return '~' + type + '~' + 'navigate.' + pageItem.id + '~' + iconId + '~' + iconColor + '~' + name + '~' + buttonText; } } - const role = o.common.role as NSPanel.roles + const role = o.common.role as NSPanel.roles; switch (role) { case 'socket': case 'light': @@ -3696,7 +4197,7 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : role == 'socket' ? Icons.GetIcon('power-socket-de') : Icons.GetIcon('lightbulb'); iconId2 = pageItem.icon2 !== undefined ? Icons.GetIcon(pageItem.icon2) : role == 'socket' ? Icons.GetIcon('power-socket-de') : Icons.GetIcon('lightbulb'); optVal = '0'; - + if (val === true || val === 'true') { optVal = '1'; iconColor = GetIconColor(pageItem, true, useColors); @@ -3708,15 +4209,15 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = } } } - + if (Debug) log('CreateEntity Icon role socket/light ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal, 'info'); return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal; - + case 'hue': type = 'light'; iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('lightbulb'); optVal = '0'; - + if (val === true || val === 'true') { optVal = '1'; iconColor = GetIconColor(pageItem, existsState(pageItem.id + '.DIMMER') ? getState(pageItem.id + '.DIMMER').val : true, useColors); @@ -3728,7 +4229,7 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = } } } - + if (pageItem.interpolateColor != undefined && pageItem.interpolateColor == true && val) { if (existsState(pageItem.id + '.HUE')) { if (getState(pageItem.id + '.HUE').val != null) { @@ -3738,15 +4239,15 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = } } } - + if (Debug) log('CreateEntity Icon role hue ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal, 'info'); return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal; - + case 'ct': type = 'light'; iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('lightbulb'); optVal = '0'; - + if (val === true || val === 'true') { optVal = '1'; iconColor = GetIconColor(pageItem, existsState(pageItem.id + '.DIMMER') ? getState(pageItem.id + '.DIMMER').val : true, useColors); @@ -3758,15 +4259,15 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = } } } - + if (Debug) log('CreateEntity Icon role ct ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal, 'info'); return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal; - + case 'rgb': type = 'light'; iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('lightbulb'); optVal = '0'; - + if (val === true || val === 'true') { optVal = '1'; iconColor = GetIconColor(pageItem, existsState(pageItem.id + '.DIMMER') ? getState(pageItem.id + '.DIMMER').val : true, useColors); @@ -3778,7 +4279,7 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = } } } - + if (existsState(pageItem.id + '.RED') && existsState(pageItem.id + '.GREEN') && existsState(pageItem.id + '.BLUE') && val) { if (getState(pageItem.id + '.RED').val != null && getState(pageItem.id + '.GREEN').val != null && getState(pageItem.id + '.BLUE').val != null) { let rgbRed = getState(pageItem.id + '.RED').val; @@ -3787,19 +4288,19 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = let rgb: RGB = { red: Math.round(rgbRed), green: Math.round(rgbGreen), blue: Math.round(rgbBlue) }; iconColor = rgb_dec565(pageItem.interpolateColor !== undefined ? rgb : config.defaultOnColor); } - } - + } + if (Debug) log('CreateEntity Icon role rgb ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal, 'info'); return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal; - + case 'cie': case 'rgbSingle': type = 'light'; iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('lightbulb'); optVal = '0'; - + if (val === true || val === 'true') { - optVal = '1' + optVal = '1'; iconColor = GetIconColor(pageItem, existsState(pageItem.id + '.DIMMER') ? getState(pageItem.id + '.DIMMER').val : true, useColors); } else { iconColor = GetIconColor(pageItem, false, useColors); @@ -3809,7 +4310,7 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = } } } - + if (existsState(pageItem.id + '.RGB') && val) { if (getState(pageItem.id + '.RGB').val != null) { let hex = getState(pageItem.id + '.RGB').val; @@ -3819,16 +4320,16 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = let rgb: RGB = { red: Math.round(hexRed), green: Math.round(hexGreen), blue: Math.round(hexBlue) }; iconColor = rgb_dec565(pageItem.interpolateColor !== undefined ? rgb : config.defaultOnColor); } - } - + } + if (Debug) log('CreateEntity Icon role cie/rgbSingle ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal, 'info'); return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal; - + case 'dimmer': type = 'light'; iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('lightbulb'); optVal = '0'; - + if (val === true || val === 'true') { optVal = '1'; iconColor = GetIconColor(pageItem, existsState(pageItem.id + '.ACTUAL') ? getState(pageItem.id + '.ACTUAL').val : true, useColors); @@ -3840,10 +4341,10 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = } } } - + if (Debug) log('CreateEntity Icon role dimmer ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal, 'info'); return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal; - + case 'blind': type = 'shutter'; iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('window-open'); @@ -3868,7 +4369,7 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = let icon_up_status = 'enable'; let icon_down_status = 'enable'; - let tempVal: number = getState(pageItem.id + '.ACTUAL').val + let tempVal: number = getState(pageItem.id + '.ACTUAL').val; //Disabled Status while bug in updating origin adapter data points of lift values //let icon_up_status = tempVal === min_Level ? 'disable' : 'enable'; @@ -3877,17 +4378,16 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = //icon_stop_status = 'disable'; } //let icon_down_status = tempVal === max_Level ? 'disable' : 'enable'; - let value = icon_up + '|' + icon_stop + '|' + icon_down + '|' + icon_up_status + '|' + icon_stop_status + '|' + icon_down_status - + let value = icon_up + '|' + icon_stop + '|' + icon_down + '|' + icon_up_status + '|' + icon_stop_status + '|' + icon_down_status; + if (Debug) log('CreateEntity Icon role blind ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + value, 'info'); return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + value; - + case 'gate': type = 'text'; let gateState: string | undefined = undefined; if (existsState(pageItem.id + '.ACTUAL')) { - if (getState(pageItem.id + '.ACTUAL').val == 0 || getState(pageItem.id + '.ACTUAL').val === false) { iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('garage'); iconColor = GetIconColor(pageItem, false, useColors); @@ -3898,20 +4398,19 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = iconColor = GetIconColor(pageItem, true, useColors); gateState = findLocale('window', 'opened'); } - } if (gateState == undefined) { - throw new Error(`Missing ${pageItem.id}.ACTUAL for type ${type}`) + throw new Error(`Missing ${pageItem.id}.ACTUAL for type ${type}`); } - + if (Debug) log('CreateEntity Icon role gate ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + gateState, 'info'); return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + gateState; - + case 'door': case 'window': type = 'text'; let windowState; - + if (existsState(pageItem.id + '.ACTUAL')) { if (getState(pageItem.id + '.ACTUAL').val) { iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : role == 'door' ? Icons.GetIcon('door-open') : Icons.GetIcon('window-open-variant'); @@ -3924,11 +4423,11 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = windowState = findLocale('window', 'closed'); } } - + if (Debug) log('CreateEntity Icon role door/window ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + windowState, 'info'); return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + windowState; - - case 'motion': + + case 'motion': type = 'text'; if (val === true) { optVal = 'On'; @@ -3939,32 +4438,37 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = iconColor = GetIconColor(pageItem, false, useColors); iconId = pageItem.icon2 !== undefined ? Icons.GetIcon(pageItem.icon2) : Icons.GetIcon('motion-sensor'); } - + if (Debug) log('CreateEntity Icon role motion ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal, 'info'); return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal; - + case 'info': - + case 'humidity': - + case 'temperature': - + case 'value.temperature': - + case 'value.humidity': - + case 'sensor.door': - + case 'sensor.window': - + case 'thermostat': type = 'text'; - - iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : role == 'temperature' || role == 'value.temperature' || role == 'thermostat' ? Icons.GetIcon('thermometer') : Icons.GetIcon('information-outline'); - + + iconId = + pageItem.icon !== undefined + ? Icons.GetIcon(pageItem.icon) + : role == 'temperature' || role == 'value.temperature' || role == 'thermostat' + ? Icons.GetIcon('thermometer') + : Icons.GetIcon('information-outline'); + let unit = ''; optVal = '0'; - + if (existsState(pageItem.id + '.ON_ACTUAL')) { optVal = getState(pageItem.id + '.ON_ACTUAL').val; unit = pageItem.unit !== undefined ? pageItem.unit : GetUnitOfMeasurement(pageItem.id + '.ON_ACTUAL'); @@ -3972,62 +4476,61 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = optVal = getState(pageItem.id + '.ACTUAL').val; unit = pageItem.unit !== undefined ? pageItem.unit : GetUnitOfMeasurement(pageItem.id + '.ACTUAL'); } - + iconColor = GetIconColor(pageItem, parseInt(optVal), useColors); - + if (pageItem.colorScale != undefined) { - let iconvalmin = (pageItem.colorScale.val_min != undefined) ? pageItem.colorScale.val_min : 0 ; - let iconvalmax = (pageItem.colorScale.val_max != undefined) ? pageItem.colorScale.val_max : 100 ; - let iconvalbest = (pageItem.colorScale.val_best != undefined) ? pageItem.colorScale.val_best : iconvalmin ; + let iconvalmin = pageItem.colorScale.val_min != undefined ? pageItem.colorScale.val_min : 0; + let iconvalmax = pageItem.colorScale.val_max != undefined ? pageItem.colorScale.val_max : 100; + let iconvalbest = pageItem.colorScale.val_best != undefined ? pageItem.colorScale.val_best : iconvalmin; let valueScale = val; - + if (iconvalmin == 0 && iconvalmax == 1) { - iconColor = (!pageItem.id || getState(pageItem.id).val == 1) ? rgb_dec565(colorScale0) : rgb_dec565(colorScale10); + iconColor = !pageItem.id || getState(pageItem.id).val == 1 ? rgb_dec565(colorScale0) : rgb_dec565(colorScale10); } else { if (iconvalbest == iconvalmin) { - valueScale = scale(valueScale,iconvalmin, iconvalmax, 10, 0); + valueScale = scale(valueScale, iconvalmin, iconvalmax, 10, 0); } else { if (valueScale < iconvalbest) { - valueScale = scale(valueScale,iconvalmin, iconvalbest, 0, 10); + valueScale = scale(valueScale, iconvalmin, iconvalbest, 0, 10); } else if (valueScale > iconvalbest || iconvalbest != iconvalmin) { - valueScale = scale(valueScale,iconvalbest, iconvalmax, 10, 0); + valueScale = scale(valueScale, iconvalbest, iconvalmax, 10, 0); } else { - valueScale = scale(valueScale,iconvalmin, iconvalmax, 10, 0); + valueScale = scale(valueScale, iconvalmin, iconvalmax, 10, 0); } } - let valueScaletemp = (Math.round(valueScale)).toFixed(); + let valueScaletemp = Math.round(valueScale).toFixed(); iconColor = HandleColorScale(valueScaletemp); } } - + if (existsState(pageItem.id + '.USERICON')) { iconId = Icons.GetIcon(getState(pageItem.id + '.USERICON').val); if (Debug) log('iconid von ' + pageItem.id + '.USERICON: ' + getState(pageItem.id + '.USERICON').val, 'info'); RegisterEntityWatcher(pageItem.id + '.USERICON'); } - + if (pageItem.useValue) { if (pageItem.fontSize != undefined) { - iconId = optVal + '¬' + pageItem.fontSize; + iconId = optVal + '¬' + pageItem.fontSize; } else { - iconId = optVal; + iconId = optVal; } } - + if (Debug) log('CreateEntity Icon role info, humidity, temperature, value.temperature, value.humidity, sensor.door, sensor.window, thermostat', 'info'); - if (Debug) log('CreateEntity ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal+ ' ' + unit, 'info'); + if (Debug) log('CreateEntity ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal + ' ' + unit, 'info'); return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal + ' ' + unit; - + case 'buttonSensor': - type = 'input_sel'; iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('gesture-tap-button'); iconColor = GetIconColor(pageItem, true, useColors); let inSelText = pageItem.buttonText !== undefined ? pageItem.buttonText : 'PRESS'; - + if (Debug) log('CreateEntity Icon role buttonSensor ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + inSelText, 'info'); return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + inSelText; - + case 'button': type = 'button'; @@ -4038,7 +4541,7 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = } let buttonText = pageItem.buttonText !== undefined ? pageItem.buttonText : 'PRESS'; - + if (Debug) log('CreateEntity Icon role button ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + buttonText, 'info'); return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + buttonText; case 'value.time': @@ -4047,27 +4550,27 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('gesture-tap-button'); iconColor = GetIconColor(pageItem, true, useColors); let timerText = pageItem.buttonText !== undefined ? pageItem.buttonText : 'PRESS'; - + if (existsState(pageItem.id + '.STATE')) { val = getState(pageItem.id + '.STATE').val; RegisterEntityWatcher(pageItem.id + '.STATE'); } - + if (Debug) log('CreateEntity Icon role level.timer ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + timerText, 'info'); return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + timerText; case 'value.alarmtime': - type = 'timer'; + type = 'timer'; iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('timer-outline'); let alarmtimerText = pageItem.buttonText !== undefined ? pageItem.buttonText : 'PRESS'; - + if (existsState(pageItem.id + '.STATE')) { val = getState(pageItem.id + '.STATE').val; - iconColor = (val == 'paused') ? rgb_dec565(colorScale10) : rgb_dec565(colorScale0); + iconColor = val == 'paused' ? rgb_dec565(colorScale10) : rgb_dec565(colorScale0); } if (existsState(pageItem.id + '.ACTUAL')) { - let timer_actual = getState(pageItem.id + '.ACTUAL').val + let timer_actual = getState(pageItem.id + '.ACTUAL').val; name = ('0' + String(Math.floor(timer_actual / 60))).slice(-2) + ':' + ('0' + String(timer_actual % 60)).slice(-2); } @@ -4075,11 +4578,10 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + alarmtimerText; case 'level.mode.fan': - type = 'fan'; iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('fan'); optVal = '0'; - + if (val === true || val === 'true') { optVal = '1'; iconColor = GetIconColor(pageItem, true, useColors); @@ -4091,16 +4593,16 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = } } } - + if (Debug) log('CreateEntity Icon role level.mode.fan ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal, 'info'); - return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal; - + return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + optVal; + case 'lock': type = 'button'; iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('lock'); iconColor = GetIconColor(pageItem, true, useColors); let lockState; - + if (existsState(pageItem.id + '.ACTUAL')) { if (getState(pageItem.id + '.ACTUAL').val) { iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('lock'); @@ -4113,28 +4615,32 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = } lockState = pageItem.buttonText !== undefined ? pageItem.buttonText : lockState; } - + if (Debug) log('CreateEntity Icon role lock ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + lockState, 'info'); return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + lockState; - + case 'slider': type = 'number'; iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('plus-minus-variant'); - + iconColor = GetIconColor(pageItem, false, useColors); - - if (Debug) log('CreateEntity Icon role slider ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + val + '|' + pageItem.minValue + '|' + pageItem.maxValue, 'info'); + + if (Debug) + log( + 'CreateEntity Icon role slider ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + val + '|' + pageItem.minValue + '|' + pageItem.maxValue, + 'info' + ); return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + val + '|' + pageItem.minValue + '|' + pageItem.maxValue; - + case 'volumeGroup': case 'volume': type = 'number'; - iconColor = GetIconColor(pageItem, false, useColors) + iconColor = GetIconColor(pageItem, false, useColors); if (existsState(pageItem.id + '.MUTE')) { - getState(pageItem.id + '.MUTE').val ? iconColor = GetIconColor(pageItem, false, useColors) : iconColor = GetIconColor(pageItem, true, useColors); + getState(pageItem.id + '.MUTE').val ? (iconColor = GetIconColor(pageItem, false, useColors)) : (iconColor = GetIconColor(pageItem, true, useColors)); RegisterEntityWatcher(pageItem.id + '.MUTE'); } - + if (val > 0 && val <= 33 && !getState(pageItem.id + '.MUTE').val) { iconId = Icons.GetIcon('volume-low'); } else if (val > 33 && val <= 66 && !getState(pageItem.id + '.MUTE').val) { @@ -4144,49 +4650,68 @@ function CreateEntity(pageItem: PageItem, placeId: number, useColors: boolean = } else { iconId = Icons.GetIcon('volume-mute'); } - - if (Debug) log('CreateEntity Icon role volumeGroup/volume ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + val + '|' + pageItem.minValue + '|' + pageItem.maxValue, 'info'); + + if (Debug) + log( + 'CreateEntity Icon role volumeGroup/volume ~' + + type + + '~' + + placeId + + '~' + + iconId + + '~' + + iconColor + + '~' + + name + + '~' + + val + + '|' + + pageItem.minValue + + '|' + + pageItem.maxValue, + 'info' + ); return '~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + name + '~' + val + '|' + pageItem.minValue + '|' + pageItem.maxValue; - + case 'warning': type = 'text'; iconId = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('alert-outline'); - iconColor = getState(([pageItem.id, '.LEVEL'].join(''))).val; - let itemName = getState(([pageItem.id, '.TITLE'].join(''))).val; - let itemInfo = getState(([pageItem.id, '.INFO'].join(''))).val; - + iconColor = getState([pageItem.id, '.LEVEL'].join('')).val; + let itemName = getState([pageItem.id, '.TITLE'].join('')).val; + let itemInfo = getState([pageItem.id, '.INFO'].join('')).val; + RegisterEntityWatcher(pageItem.id + '.LEVEL'); RegisterEntityWatcher(pageItem.id + '.INFO'); - + if (pageItem.useValue) { - iconId = itemInfo; + iconId = itemInfo; } - + if (Debug) log('CreateEntity Icon role warning ~' + type + '~' + placeId + '~' + iconId + '~' + iconColor + '~' + itemName + '~' + itemInfo, 'info'); return '~' + type + '~' + itemName + '~' + iconId + '~' + iconColor + '~' + itemName + '~' + itemInfo; - + case 'timeTable': type = 'text'; - let itemFahrzeug:string = getState(pageItem.id + '.VEHICLE').val; - let itemUhrzeit:string = getState(pageItem.id + '.ACTUAL').val; - let itemRichtung:string = getState(pageItem.id + '.DIRECTION').val; - let itemVerspaetung:boolean = getState(pageItem.id + '.DELAY').val; - - if (Icons.GetIcon(itemFahrzeug) != "") { - iconId = Icons.GetIcon(itemFahrzeug) - }else { - iconId='' - }; - - iconColor = (!itemVerspaetung) ? rgb_dec565(colorScale0) : rgb_dec565(colorScale10); - + let itemFahrzeug: string = getState(pageItem.id + '.VEHICLE').val; + let itemUhrzeit: string = getState(pageItem.id + '.ACTUAL').val; + let itemRichtung: string = getState(pageItem.id + '.DIRECTION').val; + let itemVerspaetung: boolean = getState(pageItem.id + '.DELAY').val; + + if (Icons.GetIcon(itemFahrzeug) != '') { + iconId = Icons.GetIcon(itemFahrzeug); + } else { + iconId = ''; + } + + iconColor = !itemVerspaetung ? rgb_dec565(colorScale0) : rgb_dec565(colorScale10); + if (Debug) log('CreateEntity Icon role timeTable ~' + type + '~' + itemRichtung + '~' + iconId + '~' + iconColor + '~' + itemRichtung + '~' + itemUhrzeit, 'info'); return '~' + type + '~' + itemRichtung + '~' + iconId + '~' + iconColor + '~' + itemRichtung + '~' + itemUhrzeit; - + default: if (Debug) log('CreateEntity Icon keine passende Rolle gefunden', 'warn'); return '~delete~~~~~'; - } + } } if (Debug) log('CreateEntity return ~delete~~~~~', 'info'); return '~delete~~~~~'; @@ -4218,7 +4743,6 @@ function findLocale(controlsObject: string, controlsState: string): string { } else { return controlsState; } - } catch (err: any) { if (err.message.substring(0, 35) == 'Cannot read properties of undefined') { if (Debug) { @@ -4252,7 +4776,6 @@ function findLocaleServMenu(controlsState: string): string { return controlsState; } } - } catch (err: any) { if (err.message.substring(0, 35) == 'Cannot read properties of undefined') { if (Debug) { @@ -4265,10 +4788,10 @@ function findLocaleServMenu(controlsState: string): string { } } -function GetIconColor(pageItem: PageItem, value: (boolean | number), useColors: boolean): number { +function GetIconColor(pageItem: PageItem, value: boolean | number, useColors: boolean): number { try { // dimmer - if ((pageItem.useColor || useColors) && pageItem.interpolateColor && typeof (value) === 'number') { + if ((pageItem.useColor || useColors) && pageItem.interpolateColor && typeof value === 'number') { let maxValue = pageItem.maxValueBrightness !== undefined ? pageItem.maxValueBrightness : 100; let minValue = pageItem.minValueBrightness !== undefined ? pageItem.minValueBrightness : 0; if (pageItem.maxValue !== undefined) maxValue = pageItem.maxValue; @@ -4285,7 +4808,10 @@ function GetIconColor(pageItem: PageItem, value: (boolean | number), useColors: ); } - if ((pageItem.useColor || useColors) && (typeof (value) === 'boolean' && value) || ((typeof (value) === 'number') && (value > (pageItem.minValueBrightness !== undefined ? pageItem.minValueBrightness : 0)))) { + if ( + ((pageItem.useColor || useColors) && typeof value === 'boolean' && value) || + (typeof value === 'number' && value > (pageItem.minValueBrightness !== undefined ? pageItem.minValueBrightness : 0)) + ) { return rgb_dec565(pageItem.onColor !== undefined ? pageItem.onColor : config.defaultOnColor); } @@ -4302,7 +4828,7 @@ function RegisterEntityWatcher(id: string): void { return; } - subscriptions[id] = (on({ id: id, change: 'any' }, () => { + subscriptions[id] = on({ id: id, change: 'any' }, () => { if (pageId == -1 && config.button1.page) { SendToPanel({ payload: GeneratePageElements(config.button1.page) }); } @@ -4312,7 +4838,7 @@ function RegisterEntityWatcher(id: string): void { if (activePage !== undefined) { SendToPanel({ payload: GeneratePageElements(activePage!) }); } - })); + }); } catch (err: any) { log('error at function RegisterEntityWatcher: ' + err.message, 'warn'); } @@ -4323,12 +4849,12 @@ function RegisterDetailEntityWatcher(id: string, pageItem: PageItem, type: NSPan if (subscriptions.hasOwnProperty(id)) { return; } - + if (Debug) log('id: ' + id + ' - pageItem: ' + JSON.stringify(pageItem) + ' - type: ' + type + ' - placeId: ' + placeId, 'info'); - subscriptions[id] = (on({ id: id, change: 'any' }, () => { + subscriptions[id] = on({ id: id, change: 'any' }, () => { SendToPanel(GenerateDetailPage(type, undefined, pageItem, placeId)); - })) + }); } catch (err: any) { log('error at function RegisterDetailEntityWatcher: ' + err.message, 'warn'); } @@ -4336,8 +4862,7 @@ function RegisterDetailEntityWatcher(id: string, pageItem: PageItem, type: NSPan function GetUnitOfMeasurement(id: string): string { try { - if (!existsObject(id)) - return ''; + if (!existsObject(id)) return ''; let obj = getObject(id); if (typeof obj.common.unit !== 'undefined') { @@ -4351,28 +4876,28 @@ function GetUnitOfMeasurement(id: string): string { return ''; } catch (err: any) { log('error at function GetUnitOfMeasurement: ' + err.message, 'warn'); - return '' + return ''; } } function GenerateThermoPage(page: NSPanel.PageThermo): NSPanel.Payload[] { try { UnsubscribeWatcher(); - let id = page.items[0].id + let id = page.items[0].id; let out_msgs: NSPanel.Payload[] = []; out_msgs.push({ payload: 'pageType~cardThermo' }); - + // ioBroker if (id && existsObject(id)) { let o = getObject(id); let name = page.heading !== undefined ? page.heading : o.common.name.de; let currentTemp = 0; if (existsState(id + '.ACTUAL')) { - currentTemp = (Math.round(parseFloat(getState(id + '.ACTUAL').val) * 10) / 10); + currentTemp = Math.round(parseFloat(getState(id + '.ACTUAL').val) * 10) / 10; } - let minTemp = page.items[0].minValue !== undefined ? page.items[0].minValue : 50; //Min Temp 5°C - let maxTemp = page.items[0].maxValue !== undefined ? page.items[0].maxValue : 300; //Max Temp 30°C + let minTemp = page.items[0].minValue !== undefined ? page.items[0].minValue : 50; //Min Temp 5°C + let maxTemp = page.items[0].maxValue !== undefined ? page.items[0].maxValue : 300; //Max Temp 30°C let stepTemp = page.items[0].stepValue !== undefined ? page.items[0].stepValue : 5; //Default 0,5° Schritte let destTemp = 0; @@ -4398,296 +4923,296 @@ function GenerateThermoPage(page: NSPanel.PageThermo): NSPanel.Payload[] { //Add attributes if defined in alias let i_list = Array.prototype.slice.apply($('[state.id="' + id + '.*"]')); let bt = ['~~~~', '~~~~', '~~~~', '~~~~', '~~~~', '~~~~', '~~~~', '~~~~', '~~~~']; - - let tempIcon: string = ''; - - if ((i_list.length - 3) != 0) { + let tempIcon: string = ''; + + if (i_list.length - 3 != 0) { let i = 0; switch (o.common.role as NSPanel.roles) { - case 'thermostat': { - - if (existsState(id + '.AUTOMATIC') && getState(id + '.AUTOMATIC').val != null) { - if (getState(id + '.AUTOMATIC').val) { - bt[i++] = Icons.GetIcon('alpha-a-circle') + '~' + rgb_dec565(On) + '~1~' + 'AUTT' + '~'; - statusStr = 'AUTO'; - } else { - bt[i++] = Icons.GetIcon('alpha-a-circle') + '~33840~1~' + 'AUTT' + '~'; - } - } - if (existsState(id + '.MANUAL') && getState(id + '.MANUAL').val != null) { - if (getState(id + '.MANUAL').val) { - bt[i++] = Icons.GetIcon('alpha-m-circle') + '~' + rgb_dec565(On) + '~1~' + 'MANT' + '~'; - statusStr = 'MANU'; - } else { - bt[i++] = Icons.GetIcon('alpha-m-circle') + '~33840~1~' + 'MANT' + '~'; - } - } - if (existsState(id + '.PARTY') && getState(id + '.PARTY').val != null) { - if (getState(id + '.PARTY').val) { - bt[i++] = Icons.GetIcon('party-popper') + '~' + rgb_dec565(On) + '~1~' + 'PART' + '~'; - statusStr = 'PARTY'; - } else { - bt[i++] = Icons.GetIcon('party-popper') + '~33840~1~' + 'PART' + '~'; - } - } - if (existsState(id + '.VACATION') && getState(id + '.VACATION').val != null) { - if (getState(id + '.VACATION').val) { - bt[i++] = Icons.GetIcon('palm-tree') + '~' + rgb_dec565(On) + '~1~' + 'VACT' + '~'; - statusStr = 'VAC'; - } else { - bt[i++] = Icons.GetIcon('palm-tree') + '~33840~1~' + 'VACT' + '~'; - } - } - if (existsState(id + '.BOOST') && getState(id + '.BOOST').val != null) { - if (getState(id + '.BOOST').val) { - bt[i++] = Icons.GetIcon('fast-forward-60') + '~' + rgb_dec565(On) + '~1~' + 'BOOT' + '~'; - statusStr = 'BOOST'; - } else { - bt[i++] = Icons.GetIcon('fast-forward-60') + '~33840~1~' + 'BOOT' + '~'; - } - } - - for (let i_index in i_list) { - let thermostatState = i_list[i_index].split('.'); - if ( - thermostatState[thermostatState.length - 1] != 'SET' && - thermostatState[thermostatState.length - 1] != 'ACTUAL' && - thermostatState[thermostatState.length - 1] != 'MODE' - ) { - i++; - - switch (thermostatState[thermostatState.length - 1]) { - case 'HUMIDITY': - if (existsState(id + '.HUMIDITY') && getState(id + '.HUMIDITY').val != null) { - if (parseInt(getState(id + '.HUMIDITY').val) < 40) { - bt[i - 1] = Icons.GetIcon('water-percent') + '~65504~1~' + 'HUM' + '~'; - } else if (parseInt(getState(id + '.HUMIDITY').val) < 30) { - bt[i - 1] = Icons.GetIcon('water-percent') + '~63488~1~' + 'HUM' + '~'; - } else if (parseInt(getState(id + '.HUMIDITY').val) >= 40) { - bt[i - 1] = Icons.GetIcon('water-percent') + '~2016~1~' + 'HUM' + '~'; - } else if (parseInt(getState(id + '.HUMIDITY').val) > 65) { - bt[i - 1] = Icons.GetIcon('water-percent') + '~65504~1~' + 'HUM' + '~'; - } else if (parseInt(getState(id + '.HUMIDITY').val) > 75) { - bt[i - 1] = Icons.GetIcon('water-percent') + '~63488~1~' + 'HUM' + '~'; - } - } else i--; - break; - case 'LOWBAT': - if (existsState(id + '.LOWBAT') && getState(id + '.LOWBAT').val != null) { - if (getState(id + '.LOWBAT').val) { - bt[i - 1] = Icons.GetIcon('battery-low') + '~63488~1~' + 'LBAT' + '~'; - } else { - bt[i - 1] = Icons.GetIcon('battery-high') + '~2016~1~' + 'LBAT' + '~'; - } - } else i--; - break; - case 'MAINTAIN': - if (existsState(id + '.MAINTAIN') && getState(id + '.MAINTAIN').val != null) { - if (getState(id + '.MAINTAIN').val >> .1) { - bt[i - 1] = Icons.GetIcon('account-wrench') + '~60897~1~' + 'MAIN' + '~'; - } else { - bt[i - 1] = Icons.GetIcon('account-wrench') + '~33840~1~' + 'MAIN' + '~'; - } - } else i--; - break; - case 'UNREACH': - if (existsState(id + '.UNREACH') && getState(id + '.UNREACH').val != null) { - if (getState(id + '.UNREACH').val) { - bt[i - 1] = Icons.GetIcon('wifi-off') + '~63488~1~' + 'WLAN' + '~'; - } else { - bt[i - 1] = Icons.GetIcon('wifi') + '~2016~1~' + 'WLAN' + '~'; - } - } else i--; - break; - case 'POWER': - if (existsState(id + '.POWER') && getState(id + '.POWER').val != null) { - if (getState(id + '.POWER').val) { - bt[i - 1] = Icons.GetIcon('power-standby') + '~2016~1~' + 'POWER' + '~'; - } else { - bt[i - 1] = Icons.GetIcon('power-standby') + '~33840~1~' + 'POWER' + '~'; - } - } else i--; - break; - case 'ERROR': - if (existsState(id + '.ERROR') && getState(id + '.ERROR').val != null) { - if (getState(id + '.ERROR').val) { - bt[i - 1] = Icons.GetIcon('alert-circle') + '~63488~1~' + 'ERR' + '~'; - } else { - bt[i - 1] = Icons.GetIcon('alert-circle') + '~33840~1~' + 'ERR' + '~'; - } - } else i--; - break; - case 'WORKING': - if (existsState(id + '.WORKING') && getState(id + '.WORKING').val != null) { - if (getState(id + '.WORKING').val) { - bt[i - 1] = Icons.GetIcon('briefcase-check') + '~2016~1~' + 'WORK' + '~'; - } else { - bt[i - 1] = Icons.GetIcon('briefcase-check') + '~33840~1~' + 'WORK' + '~'; - } - } else i--; - break; - case 'WINDOWOPEN': - if (existsState(id + '.WINDOWOPEN') && getState(id + '.WINDOWOPEN').val != null) { - if (getState(id + '.WINDOWOPEN').val) { - bt[i - 1] = Icons.GetIcon('window-open-variant') + '~63488~1~' + 'WIN' + '~'; - } else { - bt[i - 1] = Icons.GetIcon('window-closed-variant') + '~2016~1~' + 'WIN' + '~'; - } - } else i--; - break; - default: - i--; - break; - } - } - } - - for (let j = i; j < 9; j++) { - bt[j] = '~~~~'; - } - } - break; - case 'airCondition': { - if (existsState(id + '.MODE') && getState(id + '.MODE').val != null) { - let Mode = getState(id + '.MODE').val - let States = getObject(id + '.MODE').common.states; - - let iconIndex: number = 1; - for (const statekey in States) { - let stateName: string = States[statekey]; - let stateKeyNumber: number = parseInt(statekey); - if (stateName == 'OFF' || stateKeyNumber > 6) { - continue; - } - if (stateKeyNumber == Mode) { - statusStr = stateName.replace('_', ' '); - } - - switch (stateName) { - case 'AUTO': - if (page.items[0].iconArray !== undefined && page.items[0].iconArray[1] !== '') { - tempIcon = page.items[0].iconArray[1]; - } else { - tempIcon = 'air-conditioner'; - } - if (stateKeyNumber == Mode) { - bt[iconIndex] = Icons.GetIcon(tempIcon) + '~1024~1~' + 'AUTO' + '~'; - } else { - bt[iconIndex] = Icons.GetIcon(tempIcon) + '~35921~0~' + 'AUTO' + '~'; - } - break; - case 'COOL': - if (page.items[0].iconArray !== undefined && page.items[0].iconArray[2] !== '') { - tempIcon = page.items[0].iconArray[2]; - } else { - tempIcon = 'snowflake'; - } - if (stateKeyNumber == Mode) { - bt[iconIndex] = Icons.GetIcon(tempIcon) + '~11487~1~' + 'COOL' + '~'; - } else { - bt[iconIndex] = Icons.GetIcon(tempIcon) + '~35921~0~' + 'COOL' + '~'; - } - break; - case 'HEAT': - if (page.items[0].iconArray !== undefined && page.items[0].iconArray[3] !== '') { - tempIcon = page.items[0].iconArray[3]; - } else { - tempIcon = 'fire'; - } - if (stateKeyNumber == Mode) { - bt[iconIndex] = Icons.GetIcon(tempIcon) + '~64512~1~' + 'HEAT' + '~'; - } else { - bt[iconIndex] = Icons.GetIcon(tempIcon) + '~35921~0~' + 'HEAT' + '~'; - } - break; - case 'ECO': - if (page.items[0].iconArray !== undefined && page.items[0].iconArray[4] !== '') { - tempIcon = page.items[0].iconArray[4]; - } else { - tempIcon = 'alpha-e-circle-outline'; - } - if (stateKeyNumber == Mode) { - bt[iconIndex] = Icons.GetIcon(tempIcon) + '~2016~1~' + 'ECO' + '~'; - } else { - bt[iconIndex] = Icons.GetIcon(tempIcon) + '~35921~0~' + 'ECO' + '~'; - } - break; - case 'FAN_ONLY': - if (page.items[0].iconArray !== undefined && page.items[0].iconArray[5] !== '') { - tempIcon = page.items[0].iconArray[5]; - } else { - tempIcon = 'fan'; - } - if (stateKeyNumber == Mode) { - bt[iconIndex] = Icons.GetIcon(tempIcon) + '~11487~1~' + 'FAN_ONLY' + '~'; - } else { - bt[iconIndex] = Icons.GetIcon(tempIcon) + '~35921~0~' + 'FAN_ONLY' + '~'; - } - break; - case 'DRY': - if (page.items[0].iconArray !== undefined && page.items[0].iconArray[6] !== '') { - tempIcon = page.items[0].iconArray[6]; - } else { - tempIcon = 'water-percent'; - } - if (stateKeyNumber == Mode) { - bt[iconIndex] = Icons.GetIcon(tempIcon) + '~60897~1~' + 'DRY' + '~'; - } else { - bt[iconIndex] = Icons.GetIcon(tempIcon) + '~35921~0~' + 'DRY' + '~'; - } - break; - } - iconIndex++; - } - - if (iconIndex <= 7 && existsState(id + '.ECO') && getState(id + '.ECO').val != null) { - if (page.items[0].iconArray !== undefined && page.items[0].iconArray[4] !== '') { - tempIcon = page.items[0].iconArray[4]; + case 'thermostat': + { + if (existsState(id + '.AUTOMATIC') && getState(id + '.AUTOMATIC').val != null) { + if (getState(id + '.AUTOMATIC').val) { + bt[i++] = Icons.GetIcon('alpha-a-circle') + '~' + rgb_dec565(On) + '~1~' + 'AUTT' + '~'; + statusStr = 'AUTO'; } else { - tempIcon = 'alpha-e-circle-outline'; + bt[i++] = Icons.GetIcon('alpha-a-circle') + '~33840~1~' + 'AUTT' + '~'; } - if (getState(id + '.ECO').val && getState(id + '.ECO').val == 1) { - bt[iconIndex] = Icons.GetIcon(tempIcon) + '~2016~1~' + 'ECO' + '~'; - statusStr = 'ECO'; + } + if (existsState(id + '.MANUAL') && getState(id + '.MANUAL').val != null) { + if (getState(id + '.MANUAL').val) { + bt[i++] = Icons.GetIcon('alpha-m-circle') + '~' + rgb_dec565(On) + '~1~' + 'MANT' + '~'; + statusStr = 'MANU'; } else { - bt[iconIndex] = Icons.GetIcon(tempIcon) + '~35921~0~' + 'ECO' + '~'; + bt[i++] = Icons.GetIcon('alpha-m-circle') + '~33840~1~' + 'MANT' + '~'; + } + } + if (existsState(id + '.PARTY') && getState(id + '.PARTY').val != null) { + if (getState(id + '.PARTY').val) { + bt[i++] = Icons.GetIcon('party-popper') + '~' + rgb_dec565(On) + '~1~' + 'PART' + '~'; + statusStr = 'PARTY'; + } else { + bt[i++] = Icons.GetIcon('party-popper') + '~33840~1~' + 'PART' + '~'; + } + } + if (existsState(id + '.VACATION') && getState(id + '.VACATION').val != null) { + if (getState(id + '.VACATION').val) { + bt[i++] = Icons.GetIcon('palm-tree') + '~' + rgb_dec565(On) + '~1~' + 'VACT' + '~'; + statusStr = 'VAC'; + } else { + bt[i++] = Icons.GetIcon('palm-tree') + '~33840~1~' + 'VACT' + '~'; + } + } + if (existsState(id + '.BOOST') && getState(id + '.BOOST').val != null) { + if (getState(id + '.BOOST').val) { + bt[i++] = Icons.GetIcon('fast-forward-60') + '~' + rgb_dec565(On) + '~1~' + 'BOOT' + '~'; + statusStr = 'BOOST'; + } else { + bt[i++] = Icons.GetIcon('fast-forward-60') + '~33840~1~' + 'BOOT' + '~'; } - iconIndex++; } - if (iconIndex <= 7 && existsState(id + '.SWING') && getState(id + '.SWING').val != null) { - if (page.items[0].iconArray !== undefined && page.items[0].iconArray[7] !== '') { - tempIcon = page.items[0].iconArray[7]; - } else { - tempIcon = 'swap-vertical-bold'; + for (let i_index in i_list) { + let thermostatState = i_list[i_index].split('.'); + if ( + thermostatState[thermostatState.length - 1] != 'SET' && + thermostatState[thermostatState.length - 1] != 'ACTUAL' && + thermostatState[thermostatState.length - 1] != 'MODE' + ) { + i++; + + switch (thermostatState[thermostatState.length - 1]) { + case 'HUMIDITY': + if (existsState(id + '.HUMIDITY') && getState(id + '.HUMIDITY').val != null) { + if (parseInt(getState(id + '.HUMIDITY').val) < 40) { + bt[i - 1] = Icons.GetIcon('water-percent') + '~65504~1~' + 'HUM' + '~'; + } else if (parseInt(getState(id + '.HUMIDITY').val) < 30) { + bt[i - 1] = Icons.GetIcon('water-percent') + '~63488~1~' + 'HUM' + '~'; + } else if (parseInt(getState(id + '.HUMIDITY').val) >= 40) { + bt[i - 1] = Icons.GetIcon('water-percent') + '~2016~1~' + 'HUM' + '~'; + } else if (parseInt(getState(id + '.HUMIDITY').val) > 65) { + bt[i - 1] = Icons.GetIcon('water-percent') + '~65504~1~' + 'HUM' + '~'; + } else if (parseInt(getState(id + '.HUMIDITY').val) > 75) { + bt[i - 1] = Icons.GetIcon('water-percent') + '~63488~1~' + 'HUM' + '~'; + } + } else i--; + break; + case 'LOWBAT': + if (existsState(id + '.LOWBAT') && getState(id + '.LOWBAT').val != null) { + if (getState(id + '.LOWBAT').val) { + bt[i - 1] = Icons.GetIcon('battery-low') + '~63488~1~' + 'LBAT' + '~'; + } else { + bt[i - 1] = Icons.GetIcon('battery-high') + '~2016~1~' + 'LBAT' + '~'; + } + } else i--; + break; + case 'MAINTAIN': + if (existsState(id + '.MAINTAIN') && getState(id + '.MAINTAIN').val != null) { + if (getState(id + '.MAINTAIN').val >> 0.1) { + bt[i - 1] = Icons.GetIcon('account-wrench') + '~60897~1~' + 'MAIN' + '~'; + } else { + bt[i - 1] = Icons.GetIcon('account-wrench') + '~33840~1~' + 'MAIN' + '~'; + } + } else i--; + break; + case 'UNREACH': + if (existsState(id + '.UNREACH') && getState(id + '.UNREACH').val != null) { + if (getState(id + '.UNREACH').val) { + bt[i - 1] = Icons.GetIcon('wifi-off') + '~63488~1~' + 'WLAN' + '~'; + } else { + bt[i - 1] = Icons.GetIcon('wifi') + '~2016~1~' + 'WLAN' + '~'; + } + } else i--; + break; + case 'POWER': + if (existsState(id + '.POWER') && getState(id + '.POWER').val != null) { + if (getState(id + '.POWER').val) { + bt[i - 1] = Icons.GetIcon('power-standby') + '~2016~1~' + 'POWER' + '~'; + } else { + bt[i - 1] = Icons.GetIcon('power-standby') + '~33840~1~' + 'POWER' + '~'; + } + } else i--; + break; + case 'ERROR': + if (existsState(id + '.ERROR') && getState(id + '.ERROR').val != null) { + if (getState(id + '.ERROR').val) { + bt[i - 1] = Icons.GetIcon('alert-circle') + '~63488~1~' + 'ERR' + '~'; + } else { + bt[i - 1] = Icons.GetIcon('alert-circle') + '~33840~1~' + 'ERR' + '~'; + } + } else i--; + break; + case 'WORKING': + if (existsState(id + '.WORKING') && getState(id + '.WORKING').val != null) { + if (getState(id + '.WORKING').val) { + bt[i - 1] = Icons.GetIcon('briefcase-check') + '~2016~1~' + 'WORK' + '~'; + } else { + bt[i - 1] = Icons.GetIcon('briefcase-check') + '~33840~1~' + 'WORK' + '~'; + } + } else i--; + break; + case 'WINDOWOPEN': + if (existsState(id + '.WINDOWOPEN') && getState(id + '.WINDOWOPEN').val != null) { + if (getState(id + '.WINDOWOPEN').val) { + bt[i - 1] = Icons.GetIcon('window-open-variant') + '~63488~1~' + 'WIN' + '~'; + } else { + bt[i - 1] = Icons.GetIcon('window-closed-variant') + '~2016~1~' + 'WIN' + '~'; + } + } else i--; + break; + default: + i--; + break; + } } - if (getState(id + '.POWER').val && getState(id + '.SWING').val == 1) { //0=ON oder .SWING = true - bt[7] = Icons.GetIcon(tempIcon) + '~2016~1~' + 'SWING' + '~'; - } else { - bt[7] = Icons.GetIcon(tempIcon) + '~35921~0~' + 'SWING' + '~'; - } - iconIndex++; } - // Power Icon zuletzt pruefen, damit der Mode ggf. mit OFF ueberschrieben werden kann - if (existsState(id + '.POWER') && getState(id + '.POWER').val != null) { - if (page.items[0].iconArray !== undefined && page.items[0].iconArray[0] !== '') { - tempIcon = page.items[0].iconArray[0]; - } else { - tempIcon = 'power-standby'; + for (let j = i; j < 9; j++) { + bt[j] = '~~~~'; + } + } + break; + case 'airCondition': + { + if (existsState(id + '.MODE') && getState(id + '.MODE').val != null) { + let Mode = getState(id + '.MODE').val; + let States = getObject(id + '.MODE').common.states; + + let iconIndex: number = 1; + for (const statekey in States) { + let stateName: string = States[statekey]; + let stateKeyNumber: number = parseInt(statekey); + if (stateName == 'OFF' || stateKeyNumber > 6) { + continue; + } + if (stateKeyNumber == Mode) { + statusStr = stateName.replace('_', ' '); + } + + switch (stateName) { + case 'AUTO': + if (page.items[0].iconArray !== undefined && page.items[0].iconArray[1] !== '') { + tempIcon = page.items[0].iconArray[1]; + } else { + tempIcon = 'air-conditioner'; + } + if (stateKeyNumber == Mode) { + bt[iconIndex] = Icons.GetIcon(tempIcon) + '~1024~1~' + 'AUTO' + '~'; + } else { + bt[iconIndex] = Icons.GetIcon(tempIcon) + '~35921~0~' + 'AUTO' + '~'; + } + break; + case 'COOL': + if (page.items[0].iconArray !== undefined && page.items[0].iconArray[2] !== '') { + tempIcon = page.items[0].iconArray[2]; + } else { + tempIcon = 'snowflake'; + } + if (stateKeyNumber == Mode) { + bt[iconIndex] = Icons.GetIcon(tempIcon) + '~11487~1~' + 'COOL' + '~'; + } else { + bt[iconIndex] = Icons.GetIcon(tempIcon) + '~35921~0~' + 'COOL' + '~'; + } + break; + case 'HEAT': + if (page.items[0].iconArray !== undefined && page.items[0].iconArray[3] !== '') { + tempIcon = page.items[0].iconArray[3]; + } else { + tempIcon = 'fire'; + } + if (stateKeyNumber == Mode) { + bt[iconIndex] = Icons.GetIcon(tempIcon) + '~64512~1~' + 'HEAT' + '~'; + } else { + bt[iconIndex] = Icons.GetIcon(tempIcon) + '~35921~0~' + 'HEAT' + '~'; + } + break; + case 'ECO': + if (page.items[0].iconArray !== undefined && page.items[0].iconArray[4] !== '') { + tempIcon = page.items[0].iconArray[4]; + } else { + tempIcon = 'alpha-e-circle-outline'; + } + if (stateKeyNumber == Mode) { + bt[iconIndex] = Icons.GetIcon(tempIcon) + '~2016~1~' + 'ECO' + '~'; + } else { + bt[iconIndex] = Icons.GetIcon(tempIcon) + '~35921~0~' + 'ECO' + '~'; + } + break; + case 'FAN_ONLY': + if (page.items[0].iconArray !== undefined && page.items[0].iconArray[5] !== '') { + tempIcon = page.items[0].iconArray[5]; + } else { + tempIcon = 'fan'; + } + if (stateKeyNumber == Mode) { + bt[iconIndex] = Icons.GetIcon(tempIcon) + '~11487~1~' + 'FAN_ONLY' + '~'; + } else { + bt[iconIndex] = Icons.GetIcon(tempIcon) + '~35921~0~' + 'FAN_ONLY' + '~'; + } + break; + case 'DRY': + if (page.items[0].iconArray !== undefined && page.items[0].iconArray[6] !== '') { + tempIcon = page.items[0].iconArray[6]; + } else { + tempIcon = 'water-percent'; + } + if (stateKeyNumber == Mode) { + bt[iconIndex] = Icons.GetIcon(tempIcon) + '~60897~1~' + 'DRY' + '~'; + } else { + bt[iconIndex] = Icons.GetIcon(tempIcon) + '~35921~0~' + 'DRY' + '~'; + } + break; + } + iconIndex++; } - if (States[Mode] == 'OFF' || !getState(id + '.POWER').val) { - bt[0] = Icons.GetIcon(tempIcon) + '~35921~0~' + 'POWER' + '~'; - statusStr = 'OFF'; + + if (iconIndex <= 7 && existsState(id + '.ECO') && getState(id + '.ECO').val != null) { + if (page.items[0].iconArray !== undefined && page.items[0].iconArray[4] !== '') { + tempIcon = page.items[0].iconArray[4]; + } else { + tempIcon = 'alpha-e-circle-outline'; + } + if (getState(id + '.ECO').val && getState(id + '.ECO').val == 1) { + bt[iconIndex] = Icons.GetIcon(tempIcon) + '~2016~1~' + 'ECO' + '~'; + statusStr = 'ECO'; + } else { + bt[iconIndex] = Icons.GetIcon(tempIcon) + '~35921~0~' + 'ECO' + '~'; + } + iconIndex++; } - else { - bt[0] = Icons.GetIcon(tempIcon) + '~2016~1~' + 'POWER' + '~'; + + if (iconIndex <= 7 && existsState(id + '.SWING') && getState(id + '.SWING').val != null) { + if (page.items[0].iconArray !== undefined && page.items[0].iconArray[7] !== '') { + tempIcon = page.items[0].iconArray[7]; + } else { + tempIcon = 'swap-vertical-bold'; + } + if (getState(id + '.POWER').val && getState(id + '.SWING').val == 1) { + //0=ON oder .SWING = true + bt[7] = Icons.GetIcon(tempIcon) + '~2016~1~' + 'SWING' + '~'; + } else { + bt[7] = Icons.GetIcon(tempIcon) + '~35921~0~' + 'SWING' + '~'; + } + iconIndex++; + } + + // Power Icon zuletzt pruefen, damit der Mode ggf. mit OFF ueberschrieben werden kann + if (existsState(id + '.POWER') && getState(id + '.POWER').val != null) { + if (page.items[0].iconArray !== undefined && page.items[0].iconArray[0] !== '') { + tempIcon = page.items[0].iconArray[0]; + } else { + tempIcon = 'power-standby'; + } + if (States[Mode] == 'OFF' || !getState(id + '.POWER').val) { + bt[0] = Icons.GetIcon(tempIcon) + '~35921~0~' + 'POWER' + '~'; + statusStr = 'OFF'; + } else { + bt[0] = Icons.GetIcon(tempIcon) + '~2016~1~' + 'POWER' + '~'; + } } } } - } - break; + break; } } @@ -4701,31 +5226,44 @@ function GenerateThermoPage(page: NSPanel.PageThermo): NSPanel.Payload[] { if (page.items[0].popupThermoMode1 != undefined) { thermoPopup = 0; } - + let temperatureUnit = getState(NSPanel_Path + 'Config.temperatureUnit').val; let icon_res = bt[0] + bt[1] + bt[2] + bt[3] + bt[4] + bt[5] + bt[6] + bt[7]; out_msgs.push({ - payload: 'entityUpd~' - + name + '~' // Heading - + GetNavigationString(pageId) + '~' // Page Navigation - + id + '~' // internalNameEntity - + currentTemp + temperatureUnit+ '~' // Actual temperature (string) - + destTemp + '~' // Target temperature (numeric without comma) - + statusStr + '~' // Mode - + minTemp + '~' // Thermostat min temperature - + maxTemp + '~' // Thermostat max temperatur - + stepTemp + '~' // Steps for Target (5°C) - + icon_res // Icons Status - + findLocale('thermostat', 'Currently') + '~' // Identifier in front of Current room temperature - + findLocale('thermostat', 'State') + '~~' // Bezeichner vor State - + temperatureUnit + '~' // iconTemperature dstTempTwoTempMode - + destTemp2 + '~' // dstTempTwoTempMode --> Wenn Wert, dann 2 Temp - + thermoPopup // PopUp - + payload: + 'entityUpd~' + + name + + '~' + // Heading + GetNavigationString(pageId) + + '~' + // Page Navigation + id + + '~' + // internalNameEntity + currentTemp + + temperatureUnit + + '~' + // Actual temperature (string) + destTemp + + '~' + // Target temperature (numeric without comma) + statusStr + + '~' + // Mode + minTemp + + '~' + // Thermostat min temperature + maxTemp + + '~' + // Thermostat max temperatur + stepTemp + + '~' + // Steps for Target (5°C) + icon_res + // Icons Status + findLocale('thermostat', 'Currently') + + '~' + // Identifier in front of Current room temperature + findLocale('thermostat', 'State') + + '~~' + // Bezeichner vor State + temperatureUnit + + '~' + // iconTemperature dstTempTwoTempMode + destTemp2 + + '~' + // dstTempTwoTempMode --> Wenn Wert, dann 2 Temp + thermoPopup, // PopUp }); - } if (Debug) { @@ -4741,7 +5279,7 @@ function GenerateThermoPage(page: NSPanel.PageThermo): NSPanel.Payload[] { function unsubscribeMediaSubscriptions(): void { for (let i = 0; i < config.pages.length; i++) { const page: NSPanel.PageType = config.pages[i]; - if (isPageMedia(page)) { + if (isPageMedia(page)) { let mediaID = page.items[0].id; unsubscribe(mediaID + '.STATE'); unsubscribe(mediaID + '.ARTIST'); @@ -4757,7 +5295,7 @@ function unsubscribeMediaSubscriptions(): void { } for (let i = 0; i < config.subPages.length; i++) { const page: NSPanel.PageType = config.subPages[i]; - if (isPageMedia(page)) { + if (isPageMedia(page)) { let mediaID = page.items[0].id; unsubscribe(mediaID + '.STATE'); unsubscribe(mediaID + '.ARTIST'); @@ -4772,281 +5310,300 @@ function unsubscribeMediaSubscriptions(): void { } } if (Debug) log('unsubscribeMediaSubscriptions gestartet', 'info'); -} +} function subscribeMediaSubscriptions(id: string): void { - on({id: [id + '.STATE', - id + '.ARTIST', - id + '.TITLE', - id + '.ALBUM', - id + '.VOLUME', - id + '.REPEAT', - id + '.SHUFFLE', - id + '.DURATION', - id + '.ELAPSED'], change: "any", ack: true}, async function () { - if (useMediaEvents && pageCounter == 1) { - GeneratePage(activePage!); + on( + { id: [id + '.STATE', id + '.ARTIST', id + '.TITLE', id + '.ALBUM', id + '.VOLUME', id + '.REPEAT', id + '.SHUFFLE', id + '.DURATION', id + '.ELAPSED'], change: 'any', ack: true }, + async function () { + if (useMediaEvents && pageCounter == 1) { + GeneratePage(activePage!); + } } - }); -} + ); +} function subscribeMediaSubscriptionsSonosAdd(id: string): void { - on({id: [id + '.QUEUE'], change: "any", ack: true}, async function () { + on({ id: [id + '.QUEUE'], change: 'any', ack: true }, async function () { if (useMediaEvents && pageCounter == 1) { GeneratePage(activePage!); } }); -} +} -async function createAutoMediaAlias (id: string, mediaDevice: string, adapterPlayerInstance: NSPanel.adapterPlayerInstanceType) { +async function createAutoMediaAlias(id: string, mediaDevice: string, adapterPlayerInstance: NSPanel.adapterPlayerInstanceType) { if (autoCreateAlias) { - if (isSetOptionActive) { + if (isSetOptionActive) { switch (adapterPlayerInstance) { - case "alexa2.0.": - case "alexa2.1.": - case "alexa2.2.": - case "alexa2.3.": - case "alexa2.4.": - case "alexa2.5.": - case "alexa2.6.": - case "alexa2.7.": - case "alexa2.8.": - case "alexa2.9.": { - if (existsObject(id) == false) { - log('Alexa Alias ' + id + ' does not exist - will be created now', 'info'); + case 'alexa2.0.': + case 'alexa2.1.': + case 'alexa2.2.': + case 'alexa2.3.': + case 'alexa2.4.': + case 'alexa2.5.': + case 'alexa2.6.': + case 'alexa2.7.': + case 'alexa2.8.': + case 'alexa2.9.': + { + if (existsObject(id) == false) { + log('Alexa Alias ' + id + ' does not exist - will be created now', 'info'); - const dpPath: string = adapterPlayerInstance + 'Echo-Devices.' + mediaDevice; - try { - setObject(id, {_id: id, type: 'channel', common: {role: 'media', name: 'media'}, native: {}}); - await createAliasAsync(id + '.ACTUAL', dpPath + '.Player.volume', true, {type: 'number', role: 'value.volume', name: 'ACTUAL'}); - await createAliasAsync(id + '.ALBUM', dpPath + '.Player.currentAlbum', true, {type: 'string', role: 'media.album', name: 'ALBUM'}); - await createAliasAsync(id + '.ARTIST', dpPath + '.Player.currentArtist', true, {type: 'string', role: 'media.artist', name: 'ARTIST'}); - await createAliasAsync(id + '.TITLE', dpPath + '.Player.currentTitle', true, {type: 'string', role: 'media.title', name: 'TITLE'}); - await createAliasAsync(id + '.NEXT', dpPath + '.Player.controlNext', true, {type: 'boolean', role: 'button.next', name: 'NEXT'}); - await createAliasAsync(id + '.PREV', dpPath + '.Player.controlPrevious', true, {type: 'boolean', role: 'button.prev', name: 'PREV'}); - await createAliasAsync(id + '.PLAY', dpPath + '.Player.controlPlay', true, {type: 'boolean', role: 'button.play', name: 'PLAY'}); - await createAliasAsync(id + '.PAUSE', dpPath + '.Player.controlPause', true, {type: 'boolean', role: 'button.pause', name: 'PAUSE'}); - await createAliasAsync(id + '.STOP', dpPath + '.Commands.deviceStop', true, {type: 'boolean', role: 'button.stop', name: 'STOP'}); - await createAliasAsync(id + '.STATE', dpPath + '.Player.currentState', true, {type: 'boolean', role: 'media.state', name: 'STATE'}); - await createAliasAsync(id + '.VOLUME', dpPath + '.Player.volume', true, {type: 'number', role: 'level.volume', name: 'VOLUME'}); - await createAliasAsync(id + '.REPEAT', dpPath + '.Player.controlRepeat', true, {type: 'boolean', role: 'media.mode.repeat', name: 'REPEAT'}); - await createAliasAsync(id + '.SHUFFLE', dpPath + '.Player.controlShuffle', true, {type: 'boolean', role: 'media.mode.shuffle', name: 'SHUFFLE'}); - } catch (err: any) { - log('error at function createAutoMediaAlias Adapter Alexa2: ' + err.message, 'warn'); + const dpPath: string = adapterPlayerInstance + 'Echo-Devices.' + mediaDevice; + try { + setObject(id, { _id: id, type: 'channel', common: { role: 'media', name: 'media' }, native: {} }); + await createAliasAsync(id + '.ACTUAL', dpPath + '.Player.volume', true, { type: 'number', role: 'value.volume', name: 'ACTUAL' }); + await createAliasAsync(id + '.ALBUM', dpPath + '.Player.currentAlbum', true, { type: 'string', role: 'media.album', name: 'ALBUM' }); + await createAliasAsync(id + '.ARTIST', dpPath + '.Player.currentArtist', true, { type: 'string', role: 'media.artist', name: 'ARTIST' }); + await createAliasAsync(id + '.TITLE', dpPath + '.Player.currentTitle', true, { type: 'string', role: 'media.title', name: 'TITLE' }); + await createAliasAsync(id + '.NEXT', dpPath + '.Player.controlNext', true, { type: 'boolean', role: 'button.next', name: 'NEXT' }); + await createAliasAsync(id + '.PREV', dpPath + '.Player.controlPrevious', true, { type: 'boolean', role: 'button.prev', name: 'PREV' }); + await createAliasAsync(id + '.PLAY', dpPath + '.Player.controlPlay', true, { type: 'boolean', role: 'button.play', name: 'PLAY' }); + await createAliasAsync(id + '.PAUSE', dpPath + '.Player.controlPause', true, { type: 'boolean', role: 'button.pause', name: 'PAUSE' }); + await createAliasAsync(id + '.STOP', dpPath + '.Commands.deviceStop', true, { type: 'boolean', role: 'button.stop', name: 'STOP' }); + await createAliasAsync(id + '.STATE', dpPath + '.Player.currentState', true, { type: 'boolean', role: 'media.state', name: 'STATE' }); + await createAliasAsync(id + '.VOLUME', dpPath + '.Player.volume', true, { type: 'number', role: 'level.volume', name: 'VOLUME' }); + await createAliasAsync(id + '.REPEAT', dpPath + '.Player.controlRepeat', true, { type: 'boolean', role: 'media.mode.repeat', name: 'REPEAT' }); + await createAliasAsync(id + '.SHUFFLE', dpPath + '.Player.controlShuffle', true, { type: 'boolean', role: 'media.mode.shuffle', name: 'SHUFFLE' }); + } catch (err: any) { + log('error at function createAutoMediaAlias Adapter Alexa2: ' + err.message, 'warn'); + } + } + //Add Alexa Datapoints > v4.3.3.18 + if (existsObject(id + '.DURATION') == false) { + let dpPath: string = adapterPlayerInstance + 'Echo-Devices.' + mediaDevice; + await createAliasAsync(id + '.DURATION', dpPath + '.Player.mediaLength', true, { type: 'string', role: 'media.duration.text', name: 'DURATION' }); + await createAliasAsync(id + '.ELAPSED', dpPath + '.Player.mediaProgressStr', true, { type: 'string', role: 'media.elapsed.text', name: 'ELAPSED' }); } } - //Add Alexa Datapoints > v4.3.3.18 - if (existsObject(id + '.DURATION') == false) { - let dpPath: string = adapterPlayerInstance + 'Echo-Devices.' + mediaDevice; - await createAliasAsync(id + '.DURATION', dpPath + '.Player.mediaLength', true, {type: 'string', role: 'media.duration.text', name: 'DURATION'}); - await createAliasAsync(id + '.ELAPSED', dpPath + '.Player.mediaProgressStr', true, {type: 'string', role: 'media.elapsed.text', name: 'ELAPSED'}); - } - - } break; - case "sonos.0.": - case "sonos.1.": - case "sonos.2.": - case "sonos.3.": - case "sonos.4.": - case "sonos.5.": - case "sonos.6.": - case "sonos.7.": - case "sonos.8.": - case "sonos.9.": { - if (existsObject(id) == false) { - log('Sonos Alias ' + id + ' does not exist - will be created now', 'info'); + case 'sonos.0.': + case 'sonos.1.': + case 'sonos.2.': + case 'sonos.3.': + case 'sonos.4.': + case 'sonos.5.': + case 'sonos.6.': + case 'sonos.7.': + case 'sonos.8.': + case 'sonos.9.': + { + if (existsObject(id) == false) { + log('Sonos Alias ' + id + ' does not exist - will be created now', 'info'); - const dpPath: string = adapterPlayerInstance + 'root.' + mediaDevice; - try { - setObject(id, {_id: id, type: 'channel', common: {role: 'media', name: 'media'}, native: {}}); - await createAliasAsync(id + '.ACTUAL', dpPath + '.volume', true, {type: 'number', role: 'value.volume', name: 'ACTUAL'}); - await createAliasAsync(id + '.ALBUM', dpPath + '.current_album', true, {type: 'string', role: 'media.album', name: 'ALBUM'}); - await createAliasAsync(id + '.ARTIST', dpPath + '.current_artist', true, {type: 'string', role: 'media.artist', name: 'ARTIST'}); - await createAliasAsync(id + '.TITLE', dpPath + '.current_title', true, {type: 'string', role: 'media.title', name: 'TITLE'}); - await createAliasAsync(id + '.CONTEXT_DESCRIPTION', dpPath + '.current_station', true, {type: 'string', role: 'media.station', name: 'CONTEXT_DESCRIPTION'}); - await createAliasAsync(id + '.NEXT', dpPath + '.next', true, {type: 'boolean', role: 'button.next', name: 'NEXT'}); - await createAliasAsync(id + '.PREV', dpPath + '.prev', true, {type: 'boolean', role: 'button.prev', name: 'PREV'}); - await createAliasAsync(id + '.PLAY', dpPath + '.play', true, {type: 'boolean', role: 'button.play', name: 'PLAY'}); - await createAliasAsync(id + '.PAUSE', dpPath + '.pause', true, {type: 'boolean', role: 'button.pause', name: 'PAUSE'}); - await createAliasAsync(id + '.STOP', dpPath + '.stop', true, {type: 'boolean', role: 'button.stop', name: 'STOP'}); - await createAliasAsync(id + '.STATE', dpPath + '.state_simple', true, {type: 'boolean', role: 'media.state', name: 'STATE'}); - await createAliasAsync(id + '.VOLUME', dpPath + '.volume', true, {type: 'number', role: 'level.volume', name: 'VOLUME'}); - await createAliasAsync(id + '.REPEAT', dpPath + '.repeat', true, {type: 'number', role: 'media.mode.repeat', name: 'REPEAT'}); - await createAliasAsync(id + '.SHUFFLE', dpPath + '.shuffle', true, {type: 'boolean', role: 'media.mode.shuffle', name: 'SHUFFLE'}); - } catch (err: any) { - log('error at function createAutoMediaAlias Adapter sonos: ' + err.message, 'warn'); + const dpPath: string = adapterPlayerInstance + 'root.' + mediaDevice; + try { + setObject(id, { _id: id, type: 'channel', common: { role: 'media', name: 'media' }, native: {} }); + await createAliasAsync(id + '.ACTUAL', dpPath + '.volume', true, { type: 'number', role: 'value.volume', name: 'ACTUAL' }); + await createAliasAsync(id + '.ALBUM', dpPath + '.current_album', true, { type: 'string', role: 'media.album', name: 'ALBUM' }); + await createAliasAsync(id + '.ARTIST', dpPath + '.current_artist', true, { type: 'string', role: 'media.artist', name: 'ARTIST' }); + await createAliasAsync(id + '.TITLE', dpPath + '.current_title', true, { type: 'string', role: 'media.title', name: 'TITLE' }); + await createAliasAsync(id + '.CONTEXT_DESCRIPTION', dpPath + '.current_station', true, { + type: 'string', + role: 'media.station', + name: 'CONTEXT_DESCRIPTION', + }); + await createAliasAsync(id + '.NEXT', dpPath + '.next', true, { type: 'boolean', role: 'button.next', name: 'NEXT' }); + await createAliasAsync(id + '.PREV', dpPath + '.prev', true, { type: 'boolean', role: 'button.prev', name: 'PREV' }); + await createAliasAsync(id + '.PLAY', dpPath + '.play', true, { type: 'boolean', role: 'button.play', name: 'PLAY' }); + await createAliasAsync(id + '.PAUSE', dpPath + '.pause', true, { type: 'boolean', role: 'button.pause', name: 'PAUSE' }); + await createAliasAsync(id + '.STOP', dpPath + '.stop', true, { type: 'boolean', role: 'button.stop', name: 'STOP' }); + await createAliasAsync(id + '.STATE', dpPath + '.state_simple', true, { type: 'boolean', role: 'media.state', name: 'STATE' }); + await createAliasAsync(id + '.VOLUME', dpPath + '.volume', true, { type: 'number', role: 'level.volume', name: 'VOLUME' }); + await createAliasAsync(id + '.REPEAT', dpPath + '.repeat', true, { type: 'number', role: 'media.mode.repeat', name: 'REPEAT' }); + await createAliasAsync(id + '.SHUFFLE', dpPath + '.shuffle', true, { type: 'boolean', role: 'media.mode.shuffle', name: 'SHUFFLE' }); + } catch (err: any) { + log('error at function createAutoMediaAlias Adapter sonos: ' + err.message, 'warn'); + } + } + //Add Sonos Datapoints > v4.3.3.15 + if (existsObject(id + '.QUEUE') == false) { + let dpPath: string = adapterPlayerInstance + 'root.' + mediaDevice; + await createAliasAsync(id + '.QUEUE', dpPath + '.queue', true, { type: 'string', role: 'state', name: 'QUEUE' }); + await createAliasAsync(id + '.DURATION', dpPath + '.current_duration_s', true, { type: 'string', role: 'media.duration.text', name: 'DURATION' }); + await createAliasAsync(id + '.ELAPSED', dpPath + '.current_elapsed_s', true, { type: 'string', role: 'media.elapsed.text', name: 'ELAPSED' }); } } - //Add Sonos Datapoints > v4.3.3.15 - if (existsObject(id + '.QUEUE') == false) { - let dpPath: string = adapterPlayerInstance + 'root.' + mediaDevice; - await createAliasAsync(id + '.QUEUE', dpPath + '.queue', true, {type: 'string', role: 'state', name: 'QUEUE'}); - await createAliasAsync(id + '.DURATION', dpPath + '.current_duration_s', true, {type: 'string', role: 'media.duration.text', name: 'DURATION'}); - await createAliasAsync(id + '.ELAPSED', dpPath + '.current_elapsed_s', true, {type: 'string', role: 'media.elapsed.text', name: 'ELAPSED'}); - } - - } break; - case "spotify-premium.0.": - case "spotify-premium.1.": - case "spotify-premium.2.": - case "spotify-premium.3.": - case "spotify-premium.4.": - case "spotify-premium.5.": - case "spotify-premium.6.": - case "spotify-premium.7.": - case "spotify-premium.8.": - case "spotify-premium.9.": { - if (existsObject(id) == false) { - log('Spotify Alias ' + id + ' does not exist - will be created now', 'info'); + case 'spotify-premium.0.': + case 'spotify-premium.1.': + case 'spotify-premium.2.': + case 'spotify-premium.3.': + case 'spotify-premium.4.': + case 'spotify-premium.5.': + case 'spotify-premium.6.': + case 'spotify-premium.7.': + case 'spotify-premium.8.': + case 'spotify-premium.9.': + { + if (existsObject(id) == false) { + log('Spotify Alias ' + id + ' does not exist - will be created now', 'info'); - const dpPath: string = adapterPlayerInstance; - try { - setObject(id, {_id: id + 'player', type: 'channel', common: {role: 'media', name: 'media'}, native: {}}); - await createAliasAsync(id + '.ACTUAL', dpPath + 'player.volume', true, {type: 'number', role: 'value.volume', name: 'ACTUAL'}); - await createAliasAsync(id + '.ALBUM', dpPath + 'player.album', true, {type: 'string', role: 'media.album', name: 'ALBUM'}); - await createAliasAsync(id + '.ARTIST', dpPath + 'player.artistName', true, {type: 'string', role: 'media.artist', name: 'ARTIST'}); - await createAliasAsync(id + '.TITLE', dpPath + 'player.trackName', true, {type: 'string', role: 'media.title', name: 'TITLE'}); - await createAliasAsync(id + '.CONTEXT_DESCRIPTION', dpPath + 'player.contextDescription', true, {type: 'string', role: 'media.station', name: 'CONTEXT_DESCRIPTION'}); - await createAliasAsync(id + '.NEXT', dpPath + 'player.skipPlus', true, {type: 'boolean', role: 'button.next', name: 'NEXT'}); - await createAliasAsync(id + '.PREV', dpPath + 'player.skipMinus', true, {type: 'boolean', role: 'button.prev', name: 'PREV'}); - await createAliasAsync(id + '.PLAY', dpPath + 'player.play', true, {type: 'boolean', role: 'button.play', name: 'PLAY'}); - await createAliasAsync(id + '.PAUSE', dpPath + 'player.pause', true, {type: 'boolean', role: 'button.pause', name: 'PAUSE'}); - await createAliasAsync(id + '.STOP', dpPath + 'player.pause', true, {type: 'boolean', role: 'button.stop', name: 'STOP'}); - await createAliasAsync(id + '.STATE', dpPath + 'player.isPlaying', true, {type: 'boolean', role: 'media.state', name: 'STATE'}); - await createAliasAsync(id + '.VOLUME', dpPath + 'player.volume', true, {type: 'number', role: 'level.volume', name: 'VOLUME'}); - await createAliasAsync(id + '.REPEAT', dpPath + 'player.repeat', true, {type: 'string', role: 'value', name: 'REPEAT'}); - await createAliasAsync(id + '.SHUFFLE', dpPath + 'player.shuffle', true, {type: 'string', role: 'value', name: 'SHUFFLE'}); - - } catch (err: any) { - log('error at function createAutoMediaAlias Adapter spotify-premium: ' + err.message, 'warn'); + const dpPath: string = adapterPlayerInstance; + try { + setObject(id, { _id: id + 'player', type: 'channel', common: { role: 'media', name: 'media' }, native: {} }); + await createAliasAsync(id + '.ACTUAL', dpPath + 'player.volume', true, { type: 'number', role: 'value.volume', name: 'ACTUAL' }); + await createAliasAsync(id + '.ALBUM', dpPath + 'player.album', true, { type: 'string', role: 'media.album', name: 'ALBUM' }); + await createAliasAsync(id + '.ARTIST', dpPath + 'player.artistName', true, { type: 'string', role: 'media.artist', name: 'ARTIST' }); + await createAliasAsync(id + '.TITLE', dpPath + 'player.trackName', true, { type: 'string', role: 'media.title', name: 'TITLE' }); + await createAliasAsync(id + '.CONTEXT_DESCRIPTION', dpPath + 'player.contextDescription', true, { + type: 'string', + role: 'media.station', + name: 'CONTEXT_DESCRIPTION', + }); + await createAliasAsync(id + '.NEXT', dpPath + 'player.skipPlus', true, { type: 'boolean', role: 'button.next', name: 'NEXT' }); + await createAliasAsync(id + '.PREV', dpPath + 'player.skipMinus', true, { type: 'boolean', role: 'button.prev', name: 'PREV' }); + await createAliasAsync(id + '.PLAY', dpPath + 'player.play', true, { type: 'boolean', role: 'button.play', name: 'PLAY' }); + await createAliasAsync(id + '.PAUSE', dpPath + 'player.pause', true, { type: 'boolean', role: 'button.pause', name: 'PAUSE' }); + await createAliasAsync(id + '.STOP', dpPath + 'player.pause', true, { type: 'boolean', role: 'button.stop', name: 'STOP' }); + await createAliasAsync(id + '.STATE', dpPath + 'player.isPlaying', true, { type: 'boolean', role: 'media.state', name: 'STATE' }); + await createAliasAsync(id + '.VOLUME', dpPath + 'player.volume', true, { type: 'number', role: 'level.volume', name: 'VOLUME' }); + await createAliasAsync(id + '.REPEAT', dpPath + 'player.repeat', true, { type: 'string', role: 'value', name: 'REPEAT' }); + await createAliasAsync(id + '.SHUFFLE', dpPath + 'player.shuffle', true, { type: 'string', role: 'value', name: 'SHUFFLE' }); + } catch (err: any) { + log('error at function createAutoMediaAlias Adapter spotify-premium: ' + err.message, 'warn'); + } + } + //Add Spotify Datapoints > v4.3.3.42 + //Spotify-Premium has Role value and a known Bug in player.progress + if (existsObject(id + '.DURATION') == false) { + const dpPath: string = adapterPlayerInstance; + await createAliasAsync(id + '.DURATION', dpPath + 'player.duration', true, { type: 'string', role: 'media.duration.text', name: 'DURATION' }); + await createAliasAsync(id + '.ELAPSED', dpPath + 'player.progress', true, { type: 'string', role: 'media.elapsed.text', name: 'ELAPSED' }); } } - //Add Spotify Datapoints > v4.3.3.42 - //Spotify-Premium has Role value and a known Bug in player.progress - if (existsObject(id + '.DURATION') == false) { - const dpPath: string = adapterPlayerInstance; - await createAliasAsync(id + '.DURATION', dpPath + 'player.duration', true, {type: 'string', role: 'media.duration.text', name: 'DURATION'}); - await createAliasAsync(id + '.ELAPSED', dpPath + 'player.progress', true, {type: 'string', role: 'media.elapsed.text', name: 'ELAPSED'}); - } - - } break; - case "volumio.0.": - case "volumio.1.": - case "volumio.2.": - case "volumio.3.": - case "volumio.4.": - case "volumio.5.": - case "volumio.6.": - case "volumio.7.": - case "volumio.8.": - case "volumio.9.": { - if (existsObject(id) == false) { - log('Volumio Alias ' + id + ' does not exist - will be created now', 'info'); + case 'volumio.0.': + case 'volumio.1.': + case 'volumio.2.': + case 'volumio.3.': + case 'volumio.4.': + case 'volumio.5.': + case 'volumio.6.': + case 'volumio.7.': + case 'volumio.8.': + case 'volumio.9.': + { + if (existsObject(id) == false) { + log('Volumio Alias ' + id + ' does not exist - will be created now', 'info'); - const dpPath: string = adapterPlayerInstance; - try { - setObject(id, {_id: id, type: 'channel', common: {role: 'media', name: 'media'}, native: {}}); - await createAliasAsync(id + '.ACTUAL', dpPath + 'playbackInfo.volume', true, {type: 'number', role: 'value.volume', name: 'ACTUAL'}); - await createAliasAsync(id + '.ALBUM', dpPath + 'playbackInfo.album', true, {type: 'string', role: 'media.album', name: 'ALBUM'}); - await createAliasAsync(id + '.ARTIST', dpPath + 'playbackInfo.artist', true, {type: 'string', role: 'media.artist', name: 'ARTIST'}); - await createAliasAsync(id + '.TITLE', dpPath + 'playbackInfo.title', true, {type: 'string', role: 'media.title', name: 'TITLE'}); - await createAliasAsync(id + '.NEXT', dpPath + 'player.next', true, {type: 'boolean', role: 'button.next', name: 'NEXT'}); - await createAliasAsync(id + '.PREV', dpPath + 'player.prev', true, {type: 'boolean', role: 'button.prev', name: 'PREV'}); - await createAliasAsync(id + '.PLAY', dpPath + 'player.play', true, {type: 'boolean', role: 'button.play', name: 'PLAY'}); - await createAliasAsync(id + '.PAUSE', dpPath + 'player.toggle', true, {type: 'boolean', role: 'button.pause', name: 'PAUSE'}); - await createAliasAsync(id + '.STOP', dpPath + 'player.stop', true, {type: 'boolean', role: 'button.stop', name: 'STOP'}); - await createAliasAsync(id + '.STATE', dpPath + 'playbackInfo.status', true, {type: 'boolean', role: 'media.state', name: 'STATE'}); - await createAliasAsync(id + '.VOLUME', dpPath + 'playbackInfo.volume', true, {type: 'number', role: 'level.volume', name: 'VOLUME'}); - await createAliasAsync(id + '.REPEAT', dpPath + 'playbackInfo.repeat', true, {type: 'number', role: 'media.mode.repeat', name: 'REPEAT'}); - await createAliasAsync(id + '.SHUFFLE', dpPath + 'queue.shuffle', true, {type: 'boolean', role: 'media.mode.shuffle', name: 'SHUFFLE'}); - await createAliasAsync(id + '.status', dpPath + 'playbackInfo.status', true, {type: 'string', role: 'media.state', name: 'status'}); - } catch (err: any) { - log('error function createAutoMediaAlias Adapter volumio: ' + err.message, 'warn'); + const dpPath: string = adapterPlayerInstance; + try { + setObject(id, { _id: id, type: 'channel', common: { role: 'media', name: 'media' }, native: {} }); + await createAliasAsync(id + '.ACTUAL', dpPath + 'playbackInfo.volume', true, { type: 'number', role: 'value.volume', name: 'ACTUAL' }); + await createAliasAsync(id + '.ALBUM', dpPath + 'playbackInfo.album', true, { type: 'string', role: 'media.album', name: 'ALBUM' }); + await createAliasAsync(id + '.ARTIST', dpPath + 'playbackInfo.artist', true, { type: 'string', role: 'media.artist', name: 'ARTIST' }); + await createAliasAsync(id + '.TITLE', dpPath + 'playbackInfo.title', true, { type: 'string', role: 'media.title', name: 'TITLE' }); + await createAliasAsync(id + '.NEXT', dpPath + 'player.next', true, { type: 'boolean', role: 'button.next', name: 'NEXT' }); + await createAliasAsync(id + '.PREV', dpPath + 'player.prev', true, { type: 'boolean', role: 'button.prev', name: 'PREV' }); + await createAliasAsync(id + '.PLAY', dpPath + 'player.play', true, { type: 'boolean', role: 'button.play', name: 'PLAY' }); + await createAliasAsync(id + '.PAUSE', dpPath + 'player.toggle', true, { type: 'boolean', role: 'button.pause', name: 'PAUSE' }); + await createAliasAsync(id + '.STOP', dpPath + 'player.stop', true, { type: 'boolean', role: 'button.stop', name: 'STOP' }); + await createAliasAsync(id + '.STATE', dpPath + 'playbackInfo.status', true, { type: 'boolean', role: 'media.state', name: 'STATE' }); + await createAliasAsync(id + '.VOLUME', dpPath + 'playbackInfo.volume', true, { type: 'number', role: 'level.volume', name: 'VOLUME' }); + await createAliasAsync(id + '.REPEAT', dpPath + 'playbackInfo.repeat', true, { type: 'number', role: 'media.mode.repeat', name: 'REPEAT' }); + await createAliasAsync(id + '.SHUFFLE', dpPath + 'queue.shuffle', true, { type: 'boolean', role: 'media.mode.shuffle', name: 'SHUFFLE' }); + await createAliasAsync(id + '.status', dpPath + 'playbackInfo.status', true, { type: 'string', role: 'media.state', name: 'status' }); + } catch (err: any) { + log('error function createAutoMediaAlias Adapter volumio: ' + err.message, 'warn'); + } + } + //Add Volumio Datapoints > v4.3.3.42 + if (existsObject(id + '.DURATION') == false) { + const dpPath: string = adapterPlayerInstance; + await createAliasAsync(id + '.DURATION', dpPath + 'playbackInfo.duration', true, { type: 'string', role: 'media.duration', name: 'DURATION' }); + //await createAliasAsync(id + '.ELAPSED', dpPath + 'player.progress', true, {type: 'string', role: 'media.elapsed.text', name: 'ELAPSED'}); } } - //Add Volumio Datapoints > v4.3.3.42 - if (existsObject(id + '.DURATION') == false) { - const dpPath: string = adapterPlayerInstance; - await createAliasAsync(id + '.DURATION', dpPath + 'playbackInfo.duration', true, {type: 'string', role: 'media.duration', name: 'DURATION'}); - //await createAliasAsync(id + '.ELAPSED', dpPath + 'player.progress', true, {type: 'string', role: 'media.elapsed.text', name: 'ELAPSED'}); - } - } break; - case "squeezeboxrpc.0.": - case "squeezeboxrpc.1.": - case "squeezeboxrpc.2.": - case "squeezeboxrpc.3.": - case "squeezeboxrpc.4.": - case "squeezeboxrpc.5.": - case "squeezeboxrpc.6.": - case "squeezeboxrpc.7.": - case "squeezeboxrpc.8.": - case "squeezeboxrpc.9.": { - if (existsObject(id) == false) { - log('Squeezebox Alias ' + id + ' does not exist - will be created now', 'info'); + case 'squeezeboxrpc.0.': + case 'squeezeboxrpc.1.': + case 'squeezeboxrpc.2.': + case 'squeezeboxrpc.3.': + case 'squeezeboxrpc.4.': + case 'squeezeboxrpc.5.': + case 'squeezeboxrpc.6.': + case 'squeezeboxrpc.7.': + case 'squeezeboxrpc.8.': + case 'squeezeboxrpc.9.': + { + if (existsObject(id) == false) { + log('Squeezebox Alias ' + id + ' does not exist - will be created now', 'info'); - const dpPath: string = adapterPlayerInstance + 'Players.' + mediaDevice; - try { - setObject(id, {_id: id, type: 'channel', common: {role: 'media', name: 'media'}, native: {}}); - await createAliasAsync(id + '.ALBUM', dpPath + '.Album', true, {type: 'string', role: 'media.album', name: 'ALBUM'}); - await createAliasAsync(id + '.ARTIST', dpPath + '.Artist', true, {type: 'string', role: 'media.artist', name: 'ARTIST'}); - await createAliasAsync(id + '.TITLE', dpPath + '.Title', true, {type: 'string', role: 'media.title', name: 'TITLE'}); - await createAliasAsync(id + '.NEXT', dpPath + '.btnForward', true, {type: 'boolean', role: 'button.forward', name: 'NEXT'}); - await createAliasAsync(id + '.PREV', dpPath + '.btnRewind', true, {type: 'boolean', role: 'button.reverse', name: 'PREV'}); - await createAliasAsync(id + '.PLAY', dpPath + '.state', true, {type: 'boolean', role: 'media.state', name: 'PLAY', alias: {id: dpPath + '.state', read: 'val === 1 ? true : false'}}); - await createAliasAsync(id + '.PAUSE', dpPath + '.state', true, {type: 'boolean', role: 'media.state', name: 'PAUSE', alias: {id: dpPath + '.state', read: 'val === 0 ? true : false'}}); - await createAliasAsync(id + '.STOP', dpPath + '.state', true, {type: 'boolean', role: 'media.state', name: 'STOP', alias: {id: dpPath + '.state', read: 'val === 0 ? true : false'}}); - await createAliasAsync(id + '.STATE', dpPath + '.Power', true, {type: 'number', role: 'switch', name: 'STATE'}); - await createAliasAsync(id + '.VOLUME', dpPath + '.Volume', true, {type: 'number', role: 'level.volume', name: 'VOLUME'}); - await createAliasAsync(id + '.VOLUME_ACTUAL', dpPath + '.Volume', true, {type: 'number', role: 'value.volume', name: 'VOLUME_ACTUAL'}); - await createAliasAsync(id + '.SHUFFLE', dpPath + '.PlaylistShuffle', true, {type: 'string', role: 'media.mode.shuffle', name: 'SHUFFLE'}); - await createAliasAsync(id + '.REPEAT', dpPath + '.PlaylistRepeat', true, {type: 'number', role: 'media.mode.repeat', name: 'REPEAT'}); - await createAliasAsync(id + '.DURATION', dpPath + '.Duration', true, {type: 'string', role: 'media.duration', name: 'DURATION'}); - await createAliasAsync(id + '.ELAPSED', dpPath + '.Time', true, {type: 'string', role: 'media.elapsed', name: 'ELAPSED'}); - } catch (err: any) { - log('error at function createAutoMediaAlias Adapter Squeezebox: ' + err.message, 'warn'); + const dpPath: string = adapterPlayerInstance + 'Players.' + mediaDevice; + try { + setObject(id, { _id: id, type: 'channel', common: { role: 'media', name: 'media' }, native: {} }); + await createAliasAsync(id + '.ALBUM', dpPath + '.Album', true, { type: 'string', role: 'media.album', name: 'ALBUM' }); + await createAliasAsync(id + '.ARTIST', dpPath + '.Artist', true, { type: 'string', role: 'media.artist', name: 'ARTIST' }); + await createAliasAsync(id + '.TITLE', dpPath + '.Title', true, { type: 'string', role: 'media.title', name: 'TITLE' }); + await createAliasAsync(id + '.NEXT', dpPath + '.btnForward', true, { type: 'boolean', role: 'button.forward', name: 'NEXT' }); + await createAliasAsync(id + '.PREV', dpPath + '.btnRewind', true, { type: 'boolean', role: 'button.reverse', name: 'PREV' }); + await createAliasAsync(id + '.PLAY', dpPath + '.state', true, { + type: 'boolean', + role: 'media.state', + name: 'PLAY', + alias: { id: dpPath + '.state', read: 'val === 1 ? true : false' }, + }); + await createAliasAsync(id + '.PAUSE', dpPath + '.state', true, { + type: 'boolean', + role: 'media.state', + name: 'PAUSE', + alias: { id: dpPath + '.state', read: 'val === 0 ? true : false' }, + }); + await createAliasAsync(id + '.STOP', dpPath + '.state', true, { + type: 'boolean', + role: 'media.state', + name: 'STOP', + alias: { id: dpPath + '.state', read: 'val === 0 ? true : false' }, + }); + await createAliasAsync(id + '.STATE', dpPath + '.Power', true, { type: 'number', role: 'switch', name: 'STATE' }); + await createAliasAsync(id + '.VOLUME', dpPath + '.Volume', true, { type: 'number', role: 'level.volume', name: 'VOLUME' }); + await createAliasAsync(id + '.VOLUME_ACTUAL', dpPath + '.Volume', true, { type: 'number', role: 'value.volume', name: 'VOLUME_ACTUAL' }); + await createAliasAsync(id + '.SHUFFLE', dpPath + '.PlaylistShuffle', true, { type: 'string', role: 'media.mode.shuffle', name: 'SHUFFLE' }); + await createAliasAsync(id + '.REPEAT', dpPath + '.PlaylistRepeat', true, { type: 'number', role: 'media.mode.repeat', name: 'REPEAT' }); + await createAliasAsync(id + '.DURATION', dpPath + '.Duration', true, { type: 'string', role: 'media.duration', name: 'DURATION' }); + await createAliasAsync(id + '.ELAPSED', dpPath + '.Time', true, { type: 'string', role: 'media.elapsed', name: 'ELAPSED' }); + } catch (err: any) { + log('error at function createAutoMediaAlias Adapter Squeezebox: ' + err.message, 'warn'); + } } } - } break; - case "bosesoundtouch.0.": - case "bosesoundtouch.1.": - case "bosesoundtouch.2.": - case "bosesoundtouch.3.": - case "bosesoundtouch.4.": - case "bosesoundtouch.5.": - case "bosesoundtouch.6.": - case "bosesoundtouch.7.": - case "bosesoundtouch.8.": - case "bosesoundtouch.9.": { + case 'bosesoundtouch.0.': + case 'bosesoundtouch.1.': + case 'bosesoundtouch.2.': + case 'bosesoundtouch.3.': + case 'bosesoundtouch.4.': + case 'bosesoundtouch.5.': + case 'bosesoundtouch.6.': + case 'bosesoundtouch.7.': + case 'bosesoundtouch.8.': + case 'bosesoundtouch.9.': { if (existsObject(id) == false) { log('bosesoundtouch Alias ' + id + ' does not exist - will be created now', 'info'); try { let dpPath: string = adapterPlayerInstance; - await extendObjectAsync(id, {_id: id, type: 'channel', common: {role: 'media', name: 'media'}, native: {}}); - await createAliasAsync(id + '.ACTUAL', dpPath + 'volume', true, {type: 'number', role: 'value.volume', name: 'ACTUAL'}); - await createAliasAsync(id + '.VOLUME', dpPath + 'volume', true, {type: 'number', role: 'level.volume', name: 'VOLUME'}); - await createAliasAsync(id + '.STATE', dpPath + 'on', true, {type: 'boolean', role: 'media.state', name: 'STATE'}); + await extendObjectAsync(id, { _id: id, type: 'channel', common: { role: 'media', name: 'media' }, native: {} }); + await createAliasAsync(id + '.ACTUAL', dpPath + 'volume', true, { type: 'number', role: 'value.volume', name: 'ACTUAL' }); + await createAliasAsync(id + '.VOLUME', dpPath + 'volume', true, { type: 'number', role: 'level.volume', name: 'VOLUME' }); + await createAliasAsync(id + '.STATE', dpPath + 'on', true, { type: 'boolean', role: 'media.state', name: 'STATE' }); dpPath = adapterPlayerInstance + 'nowPlaying'; - await createAliasAsync(id + '.ALBUM', dpPath + '.album', true, {type: 'string', role: 'media.album', name: 'ALBUM'}); - await createAliasAsync(id + '.ARTIST', dpPath + '.artist', true, {type: 'string', role: 'media.artist', name: 'ARTIST'}); - await createAliasAsync(id + '.TITLE', dpPath + '.track', true, {type: 'string', role: 'media.title', name: 'TITLE'}); - await createAliasAsync(id + '.DURATION', dpPath + '.total', true, {type: 'string', role: 'media.duration.text', name: 'DURATION'}); - await createAliasAsync(id + '.ELAPSED', dpPath + '.time', true, {type: 'string', role: 'media.elapsed.text', name: 'ELAPSED'}); - await createAliasAsync(id + '.REPEAT', dpPath + '.repeat', true, {type: 'boolean', role: 'media.mode.repeat', name: 'REPEAT'}); - await createAliasAsync(id + '.SHUFFLE', dpPath + '.shuffle', true, {type: 'boolean', role: 'media.mode.shuffle', name: 'SHUFFLE'}); - + await createAliasAsync(id + '.ALBUM', dpPath + '.album', true, { type: 'string', role: 'media.album', name: 'ALBUM' }); + await createAliasAsync(id + '.ARTIST', dpPath + '.artist', true, { type: 'string', role: 'media.artist', name: 'ARTIST' }); + await createAliasAsync(id + '.TITLE', dpPath + '.track', true, { type: 'string', role: 'media.title', name: 'TITLE' }); + await createAliasAsync(id + '.DURATION', dpPath + '.total', true, { type: 'string', role: 'media.duration.text', name: 'DURATION' }); + await createAliasAsync(id + '.ELAPSED', dpPath + '.time', true, { type: 'string', role: 'media.elapsed.text', name: 'ELAPSED' }); + await createAliasAsync(id + '.REPEAT', dpPath + '.repeat', true, { type: 'boolean', role: 'media.mode.repeat', name: 'REPEAT' }); + await createAliasAsync(id + '.SHUFFLE', dpPath + '.shuffle', true, { type: 'boolean', role: 'media.mode.shuffle', name: 'SHUFFLE' }); + dpPath = adapterPlayerInstance + 'keys'; - await createAliasAsync(id + '.NEXT', dpPath + '.NEXT_TRACK', true, {type: 'boolean', role: 'button.next', name: 'NEXT'}); - await createAliasAsync(id + '.PREV', dpPath + '.PREV_TRACK', true, {type: 'boolean', role: 'button.prev', name: 'PREV'}); - await createAliasAsync(id + '.PLAY', dpPath + '.PLAY', true, {type: 'boolean', role: 'button.play', name: 'PLAY'}); - await createAliasAsync(id + '.PAUSE', dpPath + '.PAUSE', true, {type: 'boolean', role: 'button.pause', name: 'PAUSE'}); - await createAliasAsync(id + '.STOP', dpPath + '.STOP', true, {type: 'boolean', role: 'button.stop', name: 'STOP'}); + await createAliasAsync(id + '.NEXT', dpPath + '.NEXT_TRACK', true, { type: 'boolean', role: 'button.next', name: 'NEXT' }); + await createAliasAsync(id + '.PREV', dpPath + '.PREV_TRACK', true, { type: 'boolean', role: 'button.prev', name: 'PREV' }); + await createAliasAsync(id + '.PLAY', dpPath + '.PLAY', true, { type: 'boolean', role: 'button.play', name: 'PLAY' }); + await createAliasAsync(id + '.PAUSE', dpPath + '.PAUSE', true, { type: 'boolean', role: 'button.pause', name: 'PAUSE' }); + await createAliasAsync(id + '.STOP', dpPath + '.STOP', true, { type: 'boolean', role: 'button.stop', name: 'STOP' }); } catch (err: any) { log('error at function createAutoMediaAlias Adapter bosesoundtouch: ' + err.message, 'warn'); } @@ -5054,7 +5611,7 @@ async function createAutoMediaAlias (id: string, mediaDevice: string, adapterPla break; } default: { - log(`Dont find adapterPlayerInstance: ${adapterPlayerInstance}!`, 'warn') + log(`Dont find adapterPlayerInstance: ${adapterPlayerInstance}!`, 'warn'); } } } @@ -5065,24 +5622,24 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { try { unsubscribeMediaSubscriptions(); - if (!page.items[0].id) throw new Error ('Missing page id for cardMedia!'); + if (!page.items[0].id) throw new Error('Missing page id for cardMedia!'); let id = page.items[0].id; let tid = 0; let out_msgs: NSPanel.Payload[] = []; - - if (!page.items[0].adapterPlayerInstance!) throw new Error('page.items[0].adapterPlayerInstance is undefined!') + + if (!page.items[0].adapterPlayerInstance!) throw new Error('page.items[0].adapterPlayerInstance is undefined!'); let vInstance = page.items[0].adapterPlayerInstance!; let v1Adapter = vInstance.split('.'); - let v2Adapter:NSPanel.PlayerType = v1Adapter[0] as NSPanel.PlayerType; + let v2Adapter: NSPanel.PlayerType = v1Adapter[0] as NSPanel.PlayerType; - let vMediaDevice = (page.items[0].mediaDevice != undefined) ? page.items[0].mediaDevice : ''; + let vMediaDevice = page.items[0].mediaDevice != undefined ? page.items[0].mediaDevice : ''; if (isPlayerWithMediaDevice(v2Adapter)) { if (!vMediaDevice) throw new Error(`Error in cardMedia! mediaDevice is empty! Page: ${JSON.stringify(page)}`); } createAutoMediaAlias(id, vMediaDevice, page.items[0].adapterPlayerInstance!); - + // Leave the display on if the alwaysOnDisplay parameter is specified (true) if (page.type == 'cardMedia' && pageCounter == 0 && page.items[0].alwaysOnDisplay != undefined) { out_msgs.push({ payload: 'pageType~cardMedia' }); @@ -5107,7 +5664,7 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { alwaysOn = true; subscribeMediaSubscriptions(page.items[0].id); if (v2Adapter == 'sonos') { - subscribeMediaSubscriptionsSonosAdd(page.items[0].id); + subscribeMediaSubscriptionsSonosAdd(page.items[0].id); } } else if (page.type == 'cardMedia' && pageCounter == -1) { //Do Nothing @@ -5124,21 +5681,21 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { if (existsObject(id + '.DURATION') && existsObject(id + '.ELAPSED')) { if (v2Adapter == 'alexa2') { if (Debug) log(getState(id + '.DURATION').val, 'info'); - let Seconds = parseInt(getState(id + '.DURATION').val)%60 < 10 ? '0' : '' - let Duration = Math.floor(getState(id + '.DURATION').val/60) + ":" + Seconds + getState(id + '.DURATION').val%60 + let Seconds = parseInt(getState(id + '.DURATION').val) % 60 < 10 ? '0' : ''; + let Duration = Math.floor(getState(id + '.DURATION').val / 60) + ':' + Seconds + (getState(id + '.DURATION').val % 60); let vElapsed = getState(id + '.ELAPSED').val; if (vElapsed.length == 5) { - if(parseInt(vElapsed.slice(0,2)) < 9) { - vElapsed = vElapsed.slice(1); + if (parseInt(vElapsed.slice(0, 2)) < 9) { + vElapsed = vElapsed.slice(1); } - } + } if (vElapsed == 0) { - vElapsed = '0:00'; - } + vElapsed = '0:00'; + } let vDuration = Duration; if (vDuration.length == 5) { - if(parseInt(vDuration.slice(0,2)) < 9) { - vDuration = vDuration.slice(1); + if (parseInt(vDuration.slice(0, 2)) < 9) { + vDuration = vDuration.slice(1); } } if (vDuration != '0:00') { @@ -5152,16 +5709,16 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { } else if (v2Adapter == 'sonos' && getState(page.items[0].adapterPlayerInstance + 'root.' + page.items[0].mediaDevice + '.current_type').val == 0) { let vElapsed = getState(id + '.ELAPSED').val; if (vElapsed.length == 5) { - if(parseInt(vElapsed.slice(0,2)) < 9) { - vElapsed = vElapsed.slice(1); + if (parseInt(vElapsed.slice(0, 2)) < 9) { + vElapsed = vElapsed.slice(1); } } else if (vElapsed.length == 8) { vElapsed = vElapsed.slice(4); } let vDuration = getState(id + '.DURATION').val; if (vDuration.length == 5) { - if(parseInt(vDuration.slice(0,2)) < 9) { - vDuration = vDuration.slice(1); + if (parseInt(vDuration.slice(0, 2)) < 9) { + vDuration = vDuration.slice(1); } } else if (vDuration.length == 8) { vDuration = vDuration.slice(4); @@ -5169,33 +5726,33 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { title = title + ' (' + vElapsed + '|' + vDuration + ')'; } else if (v2Adapter == 'bosesoundtouch') { if (Debug) log(getState(id + '.ELAPSED').val, 'info'); - let elapsedSeconds = parseInt(getState(id + '.ELAPSED').val)%60 < 10 ? '0' : '' - let vElapsed = Math.floor(getState(id + '.ELAPSED').val/60) + ":" + elapsedSeconds + getState(id + '.ELAPSED').val%60 + let elapsedSeconds = parseInt(getState(id + '.ELAPSED').val) % 60 < 10 ? '0' : ''; + let vElapsed = Math.floor(getState(id + '.ELAPSED').val / 60) + ':' + elapsedSeconds + (getState(id + '.ELAPSED').val % 60); if (Debug) log(getState(id + '.DURATION').val, 'info'); - let durationSeconds = parseInt(getState(id + '.DURATION').val)%60 < 10 ? '0' : '' - let vDuration = Math.floor(getState(id + '.DURATION').val/60) + ":" + durationSeconds + getState(id + '.DURATION').val%60 + let durationSeconds = parseInt(getState(id + '.DURATION').val) % 60 < 10 ? '0' : ''; + let vDuration = Math.floor(getState(id + '.DURATION').val / 60) + ':' + durationSeconds + (getState(id + '.DURATION').val % 60); title = title + ' (' + vElapsed + '|' + vDuration + ')'; } - } + } let author = getState(id + '.ARTIST').val; if (v2Adapter == 'squeezeboxrpc' && author.length == 0) { - if(existsObject(([page.items[0].adapterPlayerInstance, 'Players.', page.items[0].mediaDevice, '.Playlist'].join('')))) { - if(existsObject(([page.items[0].adapterPlayerInstance, 'Players.', page.items[0].mediaDevice, '.Playlist'].join('')))) { - let lmstracklist = JSON.parse(getState(([page.items[0].adapterPlayerInstance, 'Players.', page.items[0].mediaDevice, '.Playlist'].join(''))).val); + if (existsObject([page.items[0].adapterPlayerInstance, 'Players.', page.items[0].mediaDevice, '.Playlist'].join(''))) { + if (existsObject([page.items[0].adapterPlayerInstance, 'Players.', page.items[0].mediaDevice, '.Playlist'].join(''))) { + let lmstracklist = JSON.parse(getState([page.items[0].adapterPlayerInstance, 'Players.', page.items[0].mediaDevice, '.Playlist'].join('')).val); let currentIndex: number = parseInt(getState([page.items[0].adapterPlayerInstance, 'Players.', page.items[0].mediaDevice, '.PlaylistCurrentIndex'].join('')).val); author = lmstracklist[currentIndex].Artist + '|' + lmstracklist[currentIndex].Album; if (author.length > 37) { author = author.slice(0, 37) + '...'; } let elapsedTime: number = parseInt(getState([page.items[0].adapterPlayerInstance, 'Players.', page.items[0].mediaDevice, '.Time'].join('')).val); - let elapsedSeconds = elapsedTime%60 < 10 ? '0' : ''; - let vElapsed = Math.floor(elapsedTime/60) + ":" + elapsedSeconds + elapsedTime%60; + let elapsedSeconds = elapsedTime % 60 < 10 ? '0' : ''; + let vElapsed = Math.floor(elapsedTime / 60) + ':' + elapsedSeconds + (elapsedTime % 60); - let durationSeconds = parseInt(lmstracklist[currentIndex].Duration)%60 < 10 ? '0' : ''; - let vDuration = Math.floor(parseInt(lmstracklist[currentIndex].Duration)/60) + ":" + durationSeconds + parseInt(lmstracklist[currentIndex].Duration)%60; - title = lmstracklist[currentIndex].title; + let durationSeconds = parseInt(lmstracklist[currentIndex].Duration) % 60 < 10 ? '0' : ''; + let vDuration = Math.floor(parseInt(lmstracklist[currentIndex].Duration) / 60) + ':' + durationSeconds + (parseInt(lmstracklist[currentIndex].Duration) % 60); + title = lmstracklist[currentIndex].title; if (title.length > 25) { title = title.slice(0, 25) + '...'; } @@ -5205,16 +5762,16 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { } // Settings >>Aktualisierungsintervall für Statusinformationen<< = 1 ! - // If the refresh time is set to 1 second in the spotify-premium.X instance, - // the elapsed refresh bug '00:00' is not visible + // If the refresh time is set to 1 second in the spotify-premium.X instance, + // the elapsed refresh bug '00:00' is not visible if (v2Adapter == 'spotify-premium') { let vElapsed: string = getState(id + '.ELAPSED').val; - if (vElapsed.substring(0,1) == '0') { - vElapsed = vElapsed.slice(1) + if (vElapsed.substring(0, 1) == '0') { + vElapsed = vElapsed.slice(1); } let vDuration: string = getState(id + '.DURATION').val; - if (vDuration.substring(0,1) == '0') { - vDuration = vDuration.slice(1) + if (vDuration.substring(0, 1) == '0') { + vDuration = vDuration.slice(1); } title = title + ' (' + vElapsed + '|' + vDuration + ')'; if (title == ' (0:00|0:00)') { @@ -5232,15 +5789,15 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { media_icon = Icons.GetIcon('spotify'); name = getState(id + '.CONTEXT_DESCRIPTION').val; let nameLength = name.length; - if (name.substring(0,17) == 'Playlist: This Is') { + if (name.substring(0, 17) == 'Playlist: This Is') { name = name.slice(18, 34) + '...'; - } else if (name.substring(0,9) == 'Playlist:') { + } else if (name.substring(0, 9) == 'Playlist:') { name = name.slice(10, 26) + '...'; - } else if (name.substring(0,6) == 'Album:') { + } else if (name.substring(0, 6) == 'Album:') { name = name.slice(7, 23) + '...'; - } else if (name.substring(0,6) == 'Track:') { + } else if (name.substring(0, 6) == 'Track:') { name = name.slice(7, 23) + '...'; - } else if (name.substring(0,7) == 'Artist:') { + } else if (name.substring(0, 7) == 'Artist:') { name = name.slice(8, 24) + '...'; } if (nameLength == 0) { @@ -5248,10 +5805,10 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { } author = getState(id + '.ARTIST').val + ' | ' + getState(id + '.ALBUM').val; if (author.length > 37) { - author = author.slice(0,37) + '...'; + author = author.slice(0, 37) + '...'; } - if ((getState(id + '.ARTIST').val).length == 0) { - author = findLocale('media','no_music_to_control'); + if (getState(id + '.ARTIST').val.length == 0) { + author = findLocale('media', 'no_music_to_control'); } } @@ -5263,18 +5820,18 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { if (nameLenght == 0) { name = page.heading; } else if (nameLenght > 16) { - name = name.slice(0,16) + '...' + name = name.slice(0, 16) + '...'; } - if ((getState(id + '.ALBUM').val).length > 0) { + if (getState(id + '.ALBUM').val.length > 0) { author = getState(id + '.ARTIST').val + ' | ' + getState(id + '.ALBUM').val; if (author.length > 37) { - author = author.slice(0,37) + '...'; + author = author.slice(0, 37) + '...'; } } else { author = getState(id + '.ARTIST').val; } - if ((getState(id + '.ARTIST').val).length == 0) { - author = findLocale('media','no_music_to_control'); + if (getState(id + '.ARTIST').val.length == 0) { + author = findLocale('media', 'no_music_to_control'); } } @@ -5282,17 +5839,17 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { if (v2Adapter == 'bosesoundtouch') { media_icon = Icons.GetIcon('alpha-b-circle'); name = page.heading; - - if ((getState(id + '.ALBUM').val).length > 0) { + + if (getState(id + '.ALBUM').val.length > 0) { author = getState(id + '.ARTIST').val + ' | ' + getState(id + '.ALBUM').val; if (author.length > 37) { - author = author.slice(0,37) + '...'; + author = author.slice(0, 37) + '...'; } } else { author = getState(id + '.ARTIST').val; } - if ((getState(id + '.ARTIST').val).length == 0) { - author = findLocale('media','no_music_to_control'); + if (getState(id + '.ARTIST').val.length == 0) { + author = findLocale('media', 'no_music_to_control'); } } @@ -5302,7 +5859,7 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { if (name.length == 0) { name = page.heading; } else if (name.length > 16) { - name = name.slice(0,16) + '...' + name = name.slice(0, 16) + '...'; } } @@ -5311,31 +5868,33 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { media_icon = Icons.GetIcon('alpha-a-circle'); name = getState(id + '.ALBUM').val; let nameLength = name.length; - if (name.substring(0,9) == 'Playlist:') { + if (name.substring(0, 9) == 'Playlist:') { name = name.slice(10, 26) + '...'; - } else if (name.substring(0,6) == 'Album:') { + } else if (name.substring(0, 6) == 'Album:') { name = name.slice(7, 23) + '...'; - } else if (name.substring(0,6) == 'Track') { + } else if (name.substring(0, 6) == 'Track') { name = 'Alexa Player'; } if (nameLength == 0) { name = 'Alexa Player'; } else { - name = name.slice(0,16) + '...'; + name = name.slice(0, 16) + '...'; } author = getState(id + '.ARTIST').val + ' | ' + getState(id + '.ALBUM').val; if (author.length > 30) { author = getState(id + '.ARTIST').val; } - if ((getState(id + '.ARTIST').val).length == 0) { - author = findLocale('media','no_music_to_control'); + if (getState(id + '.ARTIST').val.length == 0) { + author = findLocale('media', 'no_music_to_control'); } } //Volumio if (v2Adapter == 'volumio') { media_icon = Icons.GetIcon('clock-time-twelve-outline'); - if (name != undefined) { author = author + " | " + name; } + if (name != undefined) { + author = author + ' | ' + name; + } name = page.heading; } @@ -5351,7 +5910,6 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { // Todo: Refresh automatisieren und dafür wieder Shuffle nutzen //if (v2Adapter == 'volumio') { shuffle_icon = Icons.GetIcon('shuffle-disabled'); } //Volumio: refresh playlist - //For all players if (getState(id + '.STATE').val) { onoffbutton = 65535; @@ -5380,20 +5938,20 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { } } - let currentSpeaker: string = findLocale('media','no_speaker_found'); + let currentSpeaker: string = findLocale('media', 'no_speaker_found'); if (v2Adapter == 'alexa2') { - currentSpeaker = getState(([page.items[0].adapterPlayerInstance, 'Echo-Devices.', page.items[0].mediaDevice, '.Info.name'].join(''))).val; + currentSpeaker = getState([page.items[0].adapterPlayerInstance, 'Echo-Devices.', page.items[0].mediaDevice, '.Info.name'].join('')).val; } else if (v2Adapter == 'spotify-premium') { - currentSpeaker = getState(([page.items[0].adapterPlayerInstance, 'player.device.name'].join(''))).val; + currentSpeaker = getState([page.items[0].adapterPlayerInstance, 'player.device.name'].join('')).val; } else if (v2Adapter == 'sonos') { - currentSpeaker = getState(([page.items[0].adapterPlayerInstance, 'root.', page.items[0].mediaDevice, '.members'].join(''))).val; + currentSpeaker = getState([page.items[0].adapterPlayerInstance, 'root.', page.items[0].mediaDevice, '.members'].join('')).val; } else if (v2Adapter == 'squeezeboxrpc') { - currentSpeaker = getState(([page.items[0].adapterPlayerInstance, 'Players.', page.items[0].mediaDevice, '.Playername'].join(''))).val; + currentSpeaker = getState([page.items[0].adapterPlayerInstance, 'Players.', page.items[0].mediaDevice, '.Playername'].join('')).val; } else if (v2Adapter == 'bosesoundtouch') { - currentSpeaker = getState(([page.items[0].adapterPlayerInstance, 'deviceInfo.name'].join(''))).val; + currentSpeaker = getState([page.items[0].adapterPlayerInstance, 'deviceInfo.name'].join('')).val; } else if (v2Adapter == 'volumio') { - currentSpeaker = getState(([page.items[0].adapterPlayerInstance, 'info.name'].join(''))).val; + currentSpeaker = getState([page.items[0].adapterPlayerInstance, 'info.name'].join('')).val; } //------------------------------------------------------------------------------------------------------------- // All Alexa devices (the online / player and commands directory is available) are listed and linked below @@ -5413,7 +5971,7 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { } else if (v2Adapter == 'spotify-premium') { // All possible Devices if page.items[0].speakerList empty if (Debug) log(getState(page.items[0].adapterPlayerInstance + 'devices.availableDeviceListString').val); - speakerListArray = (getState(page.items[0].adapterPlayerInstance + 'devices.availableDeviceListString').val).split(';'); + speakerListArray = getState(page.items[0].adapterPlayerInstance + 'devices.availableDeviceListString').val.split(';'); page.items[0].speakerList = speakerListArray; } else { let i_list = Array.prototype.slice.apply($('[state.id="' + page.items[0].adapterPlayerInstance + 'Echo-Devices.*.Info.name"]')); @@ -5421,84 +5979,88 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { let i = i_list[i_index]; let deviceId = i; deviceId = deviceId.split('.'); - if (getState(([page.items[0].adapterPlayerInstance, 'Echo-Devices.', deviceId[3], '.online'].join(''))).val && - existsObject(([page.items[0].adapterPlayerInstance, 'Echo-Devices.', deviceId[3], '.Player'].join(''))) && - existsObject(([page.items[0].adapterPlayerInstance, 'Echo-Devices.', deviceId[3], '.Commands'].join('')))) { - speakerListArray.push(getState(i).val); + if ( + getState([page.items[0].adapterPlayerInstance, 'Echo-Devices.', deviceId[3], '.online'].join('')).val && + existsObject([page.items[0].adapterPlayerInstance, 'Echo-Devices.', deviceId[3], '.Player'].join('')) && + existsObject([page.items[0].adapterPlayerInstance, 'Echo-Devices.', deviceId[3], '.Commands'].join('')) + ) { + speakerListArray.push(getState(i).val); } } } //-------------------------------------------------------------------------------------------------------------- - let colMediaIcon = (page.items[0].colorMediaIcon != undefined) ? page.items[0].colorMediaIcon : White; - let colMediaTitle = (page.items[0].colorMediaTitle != undefined) ? page.items[0].colorMediaTitle : White; - let colMediaArtist = (page.items[0].colorMediaArtist != undefined) ? page.items[0].colorMediaArtist : White; + let colMediaIcon = page.items[0].colorMediaIcon != undefined ? page.items[0].colorMediaIcon : White; + let colMediaTitle = page.items[0].colorMediaTitle != undefined ? page.items[0].colorMediaTitle : White; + let colMediaArtist = page.items[0].colorMediaArtist != undefined ? page.items[0].colorMediaArtist : White; //InSel Speaker - let speakerListString: string = '~~~~~~' + let speakerListString: string = '~~~~~~'; let speakerListIconCol = rgb_dec565(HMIOff); if (speakerListArray.length > 0) { speakerListIconCol = rgb_dec565(HMIOn); - speakerListString = 'input_sel' + '~' + - tid + '?speakerlist' + '~' + - Icons.GetIcon('speaker') + '~' + - speakerListIconCol + '~' + - findLocale('media','speaker') + '~' + - 'media0~' + speakerListString = 'input_sel' + '~' + tid + '?speakerlist' + '~' + Icons.GetIcon('speaker') + '~' + speakerListIconCol + '~' + findLocale('media', 'speaker') + '~' + 'media0~'; } //InSel Playlist - let playListString: string = '~~~~~~' + let playListString: string = '~~~~~~'; let playListIconCol = rgb_dec565(HMIOff); if (page.items[0].playList != undefined) { /* Volumio: get actual playlist if empty */ if (v2Adapter == 'volumio') { if (page.items[0].playList.length == 0) { + let urlString: string = `${getState(vInstance + 'info.host').val}/api/listplaylists`; - let urlString: string = `${getState(vInstance+'info.host').val}/api/listplaylists`; - - axios.get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) - .then(async function (response) { - if (response.status === 200) { - if (Debug) { - log(JSON.stringify(response.data), 'info'); + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + .then(async function (response) { + if (response.status === 200) { + if (Debug) { + log(JSON.stringify(response.data), 'info'); + } + page.items[0].playList = JSON.parse(JSON.stringify(response.data)); + if (Debug) log('volumio-playlist: ' + page.items[0].playList, 'info'); + } else { + log('Axios Status - get_volumio-playlist: ' + response.state, 'warn'); } - page.items[0].playList = JSON.parse(JSON.stringify(response.data)); - if (Debug) log('volumio-playlist: ' + page.items[0].playList, 'info'); - } else { - log('Axios Status - get_volumio-playlist: ' + response.state, 'warn'); - } - }) - .catch(function (error) { - log(error, 'warn'); - }); - + }) + .catch(function (error) { + log(error, 'warn'); + }); } /* Spotify: get all playlists if empty */ } else if (v2Adapter == 'spotify-premium') { - page.items[0].playList = (getState(page.items[0].adapterPlayerInstance + 'playlists.playlistListString').val).split(';'); + page.items[0].playList = getState(page.items[0].adapterPlayerInstance + 'playlists.playlistListString').val.split(';'); } playListIconCol = rgb_dec565(HMIOn); - playListString = 'input_sel' + '~' + - tid + '?playlist' + '~' + - Icons.GetIcon('playlist-play') + '~' + - playListIconCol + '~' + - //'PlayL ' + page.heading + '~' + - findLocale('media','playlist') + '~' + - 'media1~' - } + playListString = + 'input_sel' + + '~' + + tid + + '?playlist' + + '~' + + Icons.GetIcon('playlist-play') + + '~' + + playListIconCol + + '~' + + //'PlayL ' + page.heading + '~' + + findLocale('media', 'playlist') + + '~' + + 'media1~'; + } //InSel Tracklist - globalTracklist = '' + globalTracklist = ''; - let trackListString: string = '~~~~~~' + let trackListString: string = '~~~~~~'; let trackListIconCol = rgb_dec565(HMIOff); - if (v2Adapter == 'volumio') { /* Volumio: get queue */ + if (v2Adapter == 'volumio') { + /* Volumio: get queue */ setTimeout(async function () { + let urlString: string = `${getState(vInstance + 'info.host').val}/api/getQueue`; - let urlString: string = `${getState(vInstance+'info.host').val}/api/getQueue`; - - axios.get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) .then(async function (response) { if (response.status === 200) { if (Debug) { @@ -5506,11 +6068,11 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { } const QUEUELIST = JSON.parse(JSON.stringify(response.data)); page.items[0].globalTracklist = QUEUELIST.queue; - if (Debug) { - for (let i_index in QUEUELIST.queue) { - log('volumio-queue: ' + QUEUELIST.queue[i_index], 'info'); + if (Debug) { + for (let i_index in QUEUELIST.queue) { + log('volumio-queue: ' + QUEUELIST.queue[i_index], 'info'); } - } + } } else { log('Axios Status - get_volumio-queue: ' + response.state, 'warn'); } @@ -5518,24 +6080,23 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { .catch(function (error) { log(error, 'warn'); }); - }, 2000); globalTracklist = page.items[0].globalTracklist; - } else if(v2Adapter == 'squeezeboxrpc' && existsObject(([page.items[0].adapterPlayerInstance, 'Players.', page.items[0].mediaDevice, '.Playlist'].join('')))) { - let lmstracklist = JSON.parse(getState(([page.items[0].adapterPlayerInstance, 'Players.', page.items[0].mediaDevice, '.Playlist'].join(''))).val); + } else if (v2Adapter == 'squeezeboxrpc' && existsObject([page.items[0].adapterPlayerInstance, 'Players.', page.items[0].mediaDevice, '.Playlist'].join(''))) { + let lmstracklist = JSON.parse(getState([page.items[0].adapterPlayerInstance, 'Players.', page.items[0].mediaDevice, '.Playlist'].join('')).val); globalTracklist = lmstracklist; - } else if(v2Adapter == 'sonos' && existsObject(([page.items[0].adapterPlayerInstance, 'root.', page.items[0].mediaDevice, '.playlist_set'].join('')))) { - let lmstracklist = getState(([page.items[0].adapterPlayerInstance, 'root.', page.items[0].mediaDevice, '.queue'].join(''))).val; + } else if (v2Adapter == 'sonos' && existsObject([page.items[0].adapterPlayerInstance, 'root.', page.items[0].mediaDevice, '.playlist_set'].join(''))) { + let lmstracklist = getState([page.items[0].adapterPlayerInstance, 'root.', page.items[0].mediaDevice, '.queue'].join('')).val; lmstracklist = lmstracklist.replace(/\s*[\[{(].*?[)}\]]\s*/g, ''); let lmstracklistTemp = lmstracklist.split(', '); let trackList: string = '['; - if (getState(page.items[0].adapterPlayerInstance + 'root.' + page.items[0].mediaDevice + '.current_type').val == 0) { - for (let i=0; i < lmstracklistTemp.length; i++) { + if (getState(page.items[0].adapterPlayerInstance + 'root.' + page.items[0].mediaDevice + '.current_type').val == 0) { + for (let i = 0; i < lmstracklistTemp.length; i++) { let trackTemp = lmstracklistTemp[i].split(' - '); - trackList = trackList + '{"id":"' + i + '","name":"' + trackTemp[0] + '","title":"' + trackTemp[1] + '"}' - if (i < lmstracklistTemp.length -1) { + trackList = trackList + '{"id":"' + i + '","name":"' + trackTemp[0] + '","title":"' + trackTemp[1] + '"}'; + if (i < lmstracklistTemp.length - 1) { trackList = trackList + ','; - } + } } } trackList = trackList + ']'; @@ -5546,46 +6107,34 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { let tempTrackList = JSON.parse(getState(page.items[0].adapterPlayerInstance + 'player.playlist.trackListArray').val); globalTracklist = tempTrackList; } catch { - log('Hello Mr. Developer something went wrong in tracklist!', 'debug') + log('Hello Mr. Developer something went wrong in tracklist!', 'debug'); } } - + if (globalTracklist != null && globalTracklist.length != 0) { trackListIconCol = rgb_dec565(HMIOn); - trackListString = 'input_sel' + '~' + - tid + '?tracklist' + '~' + - Icons.GetIcon('animation-play-outline') + '~' + - trackListIconCol + '~' + - findLocale('media','tracklist') + '~' + - 'media2~' + trackListString = + 'input_sel' + '~' + tid + '?tracklist' + '~' + Icons.GetIcon('animation-play-outline') + '~' + trackListIconCol + '~' + findLocale('media', 'tracklist') + '~' + 'media2~'; } //InSel EQ - let equalizerListString: string = '~~~~~~' + let equalizerListString: string = '~~~~~~'; let equalizerListIconCol = rgb_dec565(HMIOff); if (page.items[0].equalizerList != undefined) { equalizerListIconCol = rgb_dec565(HMIOn); - equalizerListString = 'input_sel' + '~' + - tid + '?equalizer' + '~' + - Icons.GetIcon('equalizer-outline') + '~' + - equalizerListIconCol + '~' + - findLocale('media','equalizer') + '~' + - 'media3~' + equalizerListString = + 'input_sel' + '~' + tid + '?equalizer' + '~' + Icons.GetIcon('equalizer-outline') + '~' + equalizerListIconCol + '~' + findLocale('media', 'equalizer') + '~' + 'media3~'; } else if (page.items[0].equalizerList == undefined && v2Adapter == 'sonos') { let equalizerListIconCol = rgb_dec565(HMIOn); //equalizerListString is used for favariteList - equalizerListString = 'input_sel' + '~' + - tid + '?favorites' + '~' + - Icons.GetIcon('playlist-star') + '~' + - equalizerListIconCol + '~' + - findLocale('media','favorites') + '~' + - 'media3~' + equalizerListString = + 'input_sel' + '~' + tid + '?favorites' + '~' + Icons.GetIcon('playlist-star') + '~' + equalizerListIconCol + '~' + findLocale('media', 'favorites') + '~' + 'media3~'; } //Repeat Control Button let repeatIcon = Icons.GetIcon('repeat-variant'); let repeatIconCol = rgb_dec565(HMIOff); - let repeatButtonString: string = '~~~~~~' + let repeatButtonString: string = '~~~~~~'; if (v2Adapter == 'spotify-premium') { if (getState(id + '.REPEAT').val == 'context') { @@ -5624,119 +6173,103 @@ function GenerateMediaPage(page: NSPanel.PageMedia): NSPanel.Payload[] { repeatIcon = Icons.GetIcon('repeat'); repeatIconCol = rgb_dec565(HMIOn); } - } else if (v2Adapter == 'volumio') { /* Volumio: only Repeat true/false with API */ + } else if (v2Adapter == 'volumio') { + /* Volumio: only Repeat true/false with API */ if (getState(id + '.REPEAT').val == true) { repeatIcon = Icons.GetIcon('repeat-variant'); repeatIconCol = rgb_dec565(HMIOn); } } - if (v2Adapter == 'spotify-premium' || - v2Adapter == 'alexa2' || - v2Adapter == 'sonos' || - v2Adapter == 'bosesoundtouch' || - v2Adapter == 'volumio' || - v2Adapter == 'squeezeboxrpc') { - repeatButtonString = 'button' + '~' + - tid + '?repeat' + '~' + - repeatIcon + '~' + - repeatIconCol + '~' + - 'Repeat' + '~' + - 'media4' + if (v2Adapter == 'spotify-premium' || v2Adapter == 'alexa2' || v2Adapter == 'sonos' || v2Adapter == 'bosesoundtouch' || v2Adapter == 'volumio' || v2Adapter == 'squeezeboxrpc') { + repeatButtonString = 'button' + '~' + tid + '?repeat' + '~' + repeatIcon + '~' + repeatIconCol + '~' + 'Repeat' + '~' + 'media4'; } //popUp Tools - let toolsString: string = '~~~~~~' + let toolsString: string = '~~~~~~'; let toolsIconCol = rgb_dec565(colMediaIcon); if (v2Adapter == 'sonos') { if (page.items[0].crossfade == undefined || page.items[0].crossfade == false) { - toolsString = 'input_sel' + '~' + - tid + '?seek' + '~' + - media_icon + '~' + - toolsIconCol + '~' + - findLocale('media','seek') + '~' + - 'media5~' + toolsString = 'input_sel' + '~' + tid + '?seek' + '~' + media_icon + '~' + toolsIconCol + '~' + findLocale('media', 'seek') + '~' + 'media5~'; } else { - toolsString = 'input_sel' + '~' + - tid + '?crossfade' + '~' + - media_icon + '~' + - toolsIconCol + '~' + - findLocale('media','crossfade') + '~' + - 'media5~' + toolsString = 'input_sel' + '~' + tid + '?crossfade' + '~' + media_icon + '~' + toolsIconCol + '~' + findLocale('media', 'crossfade') + '~' + 'media5~'; } } else if (v2Adapter == 'squeezeboxrpc') { if (page.items[0].crossfade == undefined || page.items[0].crossfade == false) { - toolsString = 'input_sel' + '~' + - tid + '?seek' + '~' + - media_icon + '~' + - toolsIconCol + '~' + - findLocale('media','seek') + '~' + - 'media5~' + toolsString = 'input_sel' + '~' + tid + '?seek' + '~' + media_icon + '~' + toolsIconCol + '~' + findLocale('media', 'seek') + '~' + 'media5~'; } } else if (v2Adapter == 'spotify-premium') { if (page.items[0].crossfade == undefined || page.items[0].crossfade == false) { - toolsString = 'input_sel' + '~' + - tid + '?seek' + '~' + - media_icon + '~' + - toolsIconCol + '~' + - findLocale('media','seek') + '~' + - 'media5~' + toolsString = 'input_sel' + '~' + tid + '?seek' + '~' + media_icon + '~' + toolsIconCol + '~' + findLocale('media', 'seek') + '~' + 'media5~'; } } else { - toolsString = 'button' + '~' + - tid + '' + '~' + - media_icon + '~' + - toolsIconCol + '~' + - findLocale('media','tools') + '~' + - 'media5~' + toolsString = 'button' + '~' + tid + '' + '~' + media_icon + '~' + toolsIconCol + '~' + findLocale('media', 'tools') + '~' + 'media5~'; } out_msgs.push({ - payload: 'entityUpd~' + //entityUpd - name + '~' + //heading - GetNavigationString(pageId) + '~' + //navigation - tid + '~' + //internalNameEntiy - title + '~' + //title - rgb_dec565(colMediaTitle) + '~' + //titleColor - author + '~' + //author - rgb_dec565(colMediaArtist) + '~' + //authorColor - volume + '~' + //volume - iconplaypause + '~' + //playpauseicon - onoffbutton + '~' + //On/Off Button Color - shuffle_icon + '~' + //iconShuffle --> Code + payload: + 'entityUpd~' + //entityUpd + name + + '~' + //heading + GetNavigationString(pageId) + + '~' + //navigation + tid + + '~' + //internalNameEntiy + title + + '~' + //title + rgb_dec565(colMediaTitle) + + '~' + //titleColor + author + + '~' + //author + rgb_dec565(colMediaArtist) + + '~' + //authorColor + volume + + '~' + //volume + iconplaypause + + '~' + //playpauseicon + onoffbutton + + '~' + //On/Off Button Color + shuffle_icon + + '~' + //iconShuffle --> Code toolsString + speakerListString + playListString + trackListString + equalizerListString + - repeatButtonString + repeatButtonString, }); } if (Debug) { log('GenerateMediaPage payload: ' + JSON.stringify(out_msgs), 'info'); } - return out_msgs + return out_msgs; } catch (err: any) { log('error at function GenerateMediaPage: ' + err.message, 'warn'); return []; } } -async function createAutoAlarmAlias (id: string, nsPath: string){ +async function createAutoAlarmAlias(id: string, nsPath: string) { try { - if (Debug){ + if (Debug) { log('Alarm Alias Path: ' + id, 'info'); log('Alarm 0_userdata Path: ' + nsPath, 'info'); } if (autoCreateAlias) { if (isSetOptionActive) { - if (existsState(nsPath + '.AlarmPin') == false || existsState(nsPath + '.AlarmState') == false || existsState(nsPath + '.AlarmType') == false || existsState(nsPath + '.PIN_Failed') == false || existsState(nsPath + '.PANEL') == false) { + if ( + existsState(nsPath + '.AlarmPin') == false || + existsState(nsPath + '.AlarmState') == false || + existsState(nsPath + '.AlarmType') == false || + existsState(nsPath + '.PIN_Failed') == false || + existsState(nsPath + '.PANEL') == false + ) { await createStateAsync(nsPath + '.AlarmPin', '0000', { type: 'string', write: true }); await createStateAsync(nsPath + '.AlarmState', 'disarmed', { type: 'string', write: false }); await createStateAsync(nsPath + '.AlarmType', 'D1', { type: 'string', write: false }); await createStateAsync(nsPath + '.PIN_Failed', 0, { type: 'number', write: false }); - await createStateAsync(nsPath + '.PANEL', NSPanel_Path, { type: 'string', write: false }); - setObject(id, {_id: id, type: 'channel', common: {role: 'sensor.fire.alarm', name:'alarm'}, native: {}}); + await createStateAsync(nsPath + '.PANEL', NSPanel_Path, { type: 'string', write: false }); + setObject(id, { _id: id, type: 'channel', common: { role: 'sensor.fire.alarm', name: 'alarm' }, native: {} }); await createAliasAsync(id + '.ACTUAL', nsPath + '.AlarmState', true, { type: 'string', role: 'state', name: 'ACTUAL' }); await createAliasAsync(id + '.PIN', nsPath + '.AlarmPin', true, { type: 'string', role: 'state', name: 'PIN' }); await createAliasAsync(id + '.TYPE', nsPath + '.AlarmType', true, { type: 'string', role: 'state', name: 'TYPE' }); @@ -5753,8 +6286,8 @@ async function createAutoAlarmAlias (id: string, nsPath: string){ function GenerateAlarmPage(page: NSPanel.PageAlarm): NSPanel.Payload[] { try { activePage = page; - - let id = page.items[0].id + + let id = page.items[0].id; let name = page.heading; let out_msgs: NSPanel.Payload[] = []; @@ -5762,22 +6295,25 @@ function GenerateAlarmPage(page: NSPanel.PageAlarm): NSPanel.Payload[] { let nsPath = NSPanel_Alarm_Path + 'Alarm'; if (page.items[0].autoCreateALias) { - if (!id) throw new Error ('Missing pageItem.id for cardAlarm! Property autoCreateAlias is true!'); + if (!id) throw new Error('Missing pageItem.id for cardAlarm! Property autoCreateAlias is true!'); createAutoAlarmAlias(id, nsPath); } - + type AlarmEntityType = 'triggered' | 'armed' | 'disarmed' | 'pending' | 'arming'; - const AlarmEntityElements: AlarmEntityType[] = ['triggered', 'armed', 'disarmed', 'pending', 'arming'] - + const AlarmEntityElements: AlarmEntityType[] = ['triggered', 'armed', 'disarmed', 'pending', 'arming']; + if (existsState(nsPath + '.AlarmPin') && existsState(nsPath + '.AlarmState') && existsState(nsPath + '.AlarmType')) { //let entityPin = getState(nsPath + 'AlarmPin').val; let entityState: AlarmEntityType = getState(nsPath + '.AlarmState').val as AlarmEntityType; - if ( AlarmEntityElements.indexOf(entityState) == -1 ) { - throw new Error(`Invalid value in state ${nsPath}.AlarmPin!`) + if (AlarmEntityElements.indexOf(entityState) == -1) { + throw new Error(`Invalid value in state ${nsPath}.AlarmPin!`); } //let entityType = getState(nsPath + 'AlarmType').val; let arm1: string, arm2: string, arm3: string, arm4: string; - let arm1ActionName: NSPanel.ButtonActionType | '', arm2ActionName: NSPanel.ButtonActionType | '', arm3ActionName: NSPanel.ButtonActionType | '', arm4ActionName: NSPanel.ButtonActionType | ''; + let arm1ActionName: NSPanel.ButtonActionType | '', + arm2ActionName: NSPanel.ButtonActionType | '', + arm3ActionName: NSPanel.ButtonActionType | '', + arm4ActionName: NSPanel.ButtonActionType | ''; let icon = '0'; let iconcolor = 63488; let numpadStatus = 'disable'; @@ -5791,87 +6327,102 @@ function GenerateAlarmPage(page: NSPanel.PageAlarm): NSPanel.Payload[] { if (page.items[0].actionStringArray !== undefined && page.items[0].actionStringArray[4] !== '') { arm1 = page.items[0].actionStringArray[4]; } else { - arm1 = findLocale('alarm_control_panel', 'disarm'); //'Deactivate'; //arm1*~* - } - arm1ActionName = 'D1'; //arm1ActionName*~* - arm2 = ''; //arm2*~* - arm2ActionName = ''; //arm2ActionName*~* - arm3 = ''; //arm3*~* - arm3ActionName = ''; //arm3ActionName*~* - arm4 = ''; //arm4*~* - arm4ActionName = ''; //arm4ActionName*~* - } else/* if (entityState == 'disarmed' || entityState == 'arming' || entityState == 'pending')*/ { + arm1 = findLocale('alarm_control_panel', 'disarm'); //'Deactivate'; //arm1*~* + } + arm1ActionName = 'D1'; //arm1ActionName*~* + arm2 = ''; //arm2*~* + arm2ActionName = ''; //arm2ActionName*~* + arm3 = ''; //arm3*~* + arm3ActionName = ''; //arm3ActionName*~* + arm4 = ''; //arm4*~* + arm4ActionName = ''; //arm4ActionName*~* + } /* if (entityState == 'disarmed' || entityState == 'arming' || entityState == 'pending')*/ else { if (page.items[0].actionStringArray !== undefined && page.items[0].actionStringArray[0] !== '') { arm1 = page.items[0].actionStringArray[0]; } else { - arm1 = formatInSelText(findLocale('alarm_control_panel', 'arm_away')); //'Vollschutz' //arm1*~* + arm1 = formatInSelText(findLocale('alarm_control_panel', 'arm_away')); //'Vollschutz' //arm1*~* } - arm1ActionName = 'A1'; //arm1ActionName*~* + arm1ActionName = 'A1'; //arm1ActionName*~* if (page.items[0].actionStringArray !== undefined && page.items[0].actionStringArray[1] !== '') { arm2 = page.items[0].actionStringArray[1]; } else { - arm2 = formatInSelText(findLocale('alarm_control_panel', 'arm_home')); //'Zuhause'; //arm2*~* - } - arm2ActionName = 'A2'; //arm2ActionName*~* + arm2 = formatInSelText(findLocale('alarm_control_panel', 'arm_home')); //'Zuhause'; //arm2*~* + } + arm2ActionName = 'A2'; //arm2ActionName*~* if (page.items[0].actionStringArray !== undefined && page.items[0].actionStringArray[2] !== '') { arm3 = page.items[0].actionStringArray[2]; } else { - arm3 = formatInSelText(findLocale('alarm_control_panel', 'arm_night')); //'Nacht'; //arm3*~* + arm3 = formatInSelText(findLocale('alarm_control_panel', 'arm_night')); //'Nacht'; //arm3*~* } - arm3ActionName = 'A3'; //arm3ActionName*~* + arm3ActionName = 'A3'; //arm3ActionName*~* if (page.items[0].actionStringArray !== undefined && page.items[0].actionStringArray[3] !== '') { arm4 = page.items[0].actionStringArray[3]; } else { - arm4 = formatInSelText(findLocale('alarm_control_panel', 'arm_vacation')); //'Besuch'; //arm4*~* + arm4 = formatInSelText(findLocale('alarm_control_panel', 'arm_vacation')); //'Besuch'; //arm4*~* } - arm4ActionName = 'A4'; //arm4ActionName*~* + arm4ActionName = 'A4'; //arm4ActionName*~* if (Debug) { log('GenerateAlarmPage String for arm1: ' + arm1 + ', arm2: ' + arm2 + ', arm3: ' + arm3 + ', arm4: ' + arm4, 'info'); } - } + } if (entityState == 'armed') { - icon = Icons.GetIcon('shield-home'); //icon*~* - iconcolor = 63488; //iconcolor*~* - numpadStatus = 'enable'; //numpadStatus*~* - flashing = 'disable'; //flashing* + icon = Icons.GetIcon('shield-home'); //icon*~* + iconcolor = 63488; //iconcolor*~* + numpadStatus = 'enable'; //numpadStatus*~* + flashing = 'disable'; //flashing* } if (entityState == 'disarmed') { - icon = Icons.GetIcon('shield-off'); //icon*~* - iconcolor = 2016; //iconcolor*~* - numpadStatus = 'enable'; //numpadStatus*~* - flashing = 'disable'; //flashing* + icon = Icons.GetIcon('shield-off'); //icon*~* + iconcolor = 2016; //iconcolor*~* + numpadStatus = 'enable'; //numpadStatus*~* + flashing = 'disable'; //flashing* } if (entityState == 'arming' || entityState == 'pending') { - icon = Icons.GetIcon('shield'); //icon*~* - iconcolor = rgb_dec565({ red: 243, green: 179, blue: 0 }); //iconcolor*~* - numpadStatus = 'disable'; //numpadStatus*~* - flashing = 'enable' //flashing* + icon = Icons.GetIcon('shield'); //icon*~* + iconcolor = rgb_dec565({ red: 243, green: 179, blue: 0 }); //iconcolor*~* + numpadStatus = 'disable'; //numpadStatus*~* + flashing = 'enable'; //flashing* } if (entityState == 'triggered') { - iconcolor = rgb_dec565({ red: 223, green: 76, blue: 30 }); //icon*~* - icon = Icons.GetIcon('bell-ring'); //iconcolor*~* - numpadStatus = 'enable'; //numpadStatus*~* - flashing = 'enable' //flashing* + iconcolor = rgb_dec565({ red: 223, green: 76, blue: 30 }); //icon*~* + icon = Icons.GetIcon('bell-ring'); //iconcolor*~* + numpadStatus = 'enable'; //numpadStatus*~* + flashing = 'enable'; //flashing* } - + out_msgs.push({ - payload: 'entityUpd~' + //entityUpd~* - name + '~' + //heading - GetNavigationString(pageId) + '~' + //navigation*~* --> hiddenCardsv - id + '~' + //internalNameEntity*~* - arm1 + '~' + //arm1*~* - arm1ActionName + '~' + //arm1ActionName*~* - arm2 + '~' + //arm2*~* - arm2ActionName + '~' + //arm2ActionName*~* - arm3 + '~' + //arm3*~* - arm3ActionName + '~' + //arm3ActionName*~* - arm4 + '~' + //arm4*~* - arm4ActionName + '~' + //arm4ActionName*~* - icon + '~' + //icon*~* - iconcolor + '~' + //iconcolor*~* - numpadStatus + '~' + //numpadStatus*~* - flashing //flashing* + payload: + 'entityUpd~' + //entityUpd~* + name + + '~' + //heading + GetNavigationString(pageId) + + '~' + //navigation*~* --> hiddenCardsv + id + + '~' + //internalNameEntity*~* + arm1 + + '~' + //arm1*~* + arm1ActionName + + '~' + //arm1ActionName*~* + arm2 + + '~' + //arm2*~* + arm2ActionName + + '~' + //arm2ActionName*~* + arm3 + + '~' + //arm3*~* + arm3ActionName + + '~' + //arm3ActionName*~* + arm4 + + '~' + //arm4*~* + arm4ActionName + + '~' + //arm4ActionName*~* + icon + + '~' + //icon*~* + iconcolor + + '~' + //iconcolor*~* + numpadStatus + + '~' + //numpadStatus*~* + flashing, //flashing* }); if (Debug) { @@ -5888,7 +6439,7 @@ function GenerateAlarmPage(page: NSPanel.PageAlarm): NSPanel.Payload[] { async function createAutoUnlockAlias(id: string, dpPath: string) { try { - if (Debug){ + if (Debug) { log('Unlock Alias Path: ' + id, 'info'); log('Unlock 0_userdata Path: ' + dpPath, 'info'); } @@ -5906,71 +6457,78 @@ async function createAutoUnlockAlias(id: string, dpPath: string) { } catch (err: any) { log('error at function createAutoUnlockAlias: ' + err.message, 'warn'); } - } function GenerateUnlockPage(page: NSPanel.PageUnlock): NSPanel.Payload[] { try { activePage = page; - let id = page.items[0].id + let id = page.items[0].id; let name = page.heading; let out_msgs: NSPanel.Payload[] = []; out_msgs.push({ payload: 'pageType~cardAlarm' }); - let dpPath : string = '' + let dpPath: string = ''; let dpTempPath: any = NSPanel_Path.split('.'); - for (let i=0; i < dpTempPath.length - 2; i++) { + for (let i = 0; i < dpTempPath.length - 2; i++) { dpPath = dpPath + dpTempPath[i] + '.'; - } - dpPath = (dpPath + 'Unlock.'); + } + dpPath = dpPath + 'Unlock.'; if (page.items[0].autoCreateALias) { - if (!id) throw new Error ('Missing pageItem.id for cardUnlock! Property autoCreateAlias is true!'); - createAutoUnlockAlias(id, dpPath) + if (!id) throw new Error('Missing pageItem.id for cardUnlock! Property autoCreateAlias is true!'); + createAutoUnlockAlias(id, dpPath); } - let unlock1 = findLocale('lock', 'UNLOCK'); //unlock1*~* - let unlock1ActionName: NSPanel.ButtonActionType | '' = 'U1'; //unlock1ActionName*~* + let unlock1 = findLocale('lock', 'UNLOCK'); //unlock1*~* + let unlock1ActionName: NSPanel.ButtonActionType | '' = 'U1'; //unlock1ActionName*~* - let iconcolor = rgb_dec565({ red: 223, green: 76, blue: 30 }); //icon*~* - let icon = Icons.GetIcon('lock-remove'); //iconcolor*~* - let numpadStatus = 'enable'; //numpadStatus*~* - let flashing = 'disable' //flashing* + let iconcolor = rgb_dec565({ red: 223, green: 76, blue: 30 }); //icon*~* + let icon = Icons.GetIcon('lock-remove'); //iconcolor*~* + let numpadStatus = 'enable'; //numpadStatus*~* + let flashing = 'disable'; //flashing* out_msgs.push({ - payload: 'entityUpd~' + //entityUpd~* - name + '~' + //heading - GetNavigationString(pageId) + '~' + //navigation*~* --> hiddenCardsv - id + '~' + //internalNameEntity*~* - unlock1 + '~' + //unlock1*~* - unlock1ActionName + '~' + //unlock1ActionName*~* - '~' + - '~' + - '~' + - '~' + - '~' + - '~' + - icon + '~' + //icon*~* - iconcolor + '~' + //iconcolor*~* - numpadStatus + '~' + //numpadStatus*~* - flashing //flashing* - }); + payload: + 'entityUpd~' + //entityUpd~* + name + + '~' + //heading + GetNavigationString(pageId) + + '~' + //navigation*~* --> hiddenCardsv + id + + '~' + //internalNameEntity*~* + unlock1 + + '~' + //unlock1*~* + unlock1ActionName + + '~' + //unlock1ActionName*~* + '~' + + '~' + + '~' + + '~' + + '~' + + '~' + + icon + + '~' + //icon*~* + iconcolor + + '~' + //iconcolor*~* + numpadStatus + + '~' + //numpadStatus*~* + flashing, //flashing* + }); if (Debug) { log('GenerateUnlockPage payload: ' + JSON.stringify(out_msgs), 'info'); } return out_msgs; - } catch (err: any) { log('error at function GenerateUnlockPage: ' + err.message, 'warn'); return []; } } -async function createAutoQRAlias(id:string, dpPath:string) { +async function createAutoQRAlias(id: string, dpPath: string) { try { - if (Debug){ + if (Debug) { log('QRPage Alias Path: ' + id, 'info'); log('QRPage 0_userdata Path: ' + dpPath, 'info'); } @@ -5988,26 +6546,26 @@ async function createAutoQRAlias(id:string, dpPath:string) { } } catch (err: any) { log('error at function createAutoQRkAlias: ' + err.message, 'warn'); - } + } } function GenerateQRPage(page: NSPanel.PageQR): NSPanel.Payload[] { try { activePage = page; - if (!page.items[0].id) throw new Error ('Missing pageItem.id for cardQRPage!'); + if (!page.items[0].id) throw new Error('Missing pageItem.id for cardQRPage!'); let id = page.items[0].id; let out_msgs: NSPanel.Payload[] = []; out_msgs.push({ payload: 'pageType~cardQR' }); - let dpPath : string = '' + let dpPath: string = ''; let dpTempPath: any = NSPanel_Path.split('.'); - for (let i=0; i < dpTempPath.length - 2; i++) { + for (let i = 0; i < dpTempPath.length - 2; i++) { dpPath = dpPath + dpTempPath[i] + '.'; - } - dpPath = (dpPath + 'GuestWiFi.'); + } + dpPath = dpPath + 'GuestWiFi.'; if (page.items[0].autoCreateALias) { - createAutoQRAlias(id, dpPath) + createAutoQRAlias(id, dpPath); } let o = getObject(id); @@ -6024,10 +6582,12 @@ function GenerateQRPage(page: NSPanel.PageQR): NSPanel.Payload[] { let optionalValue2: any; for (let w = 0; w < tempstr.length - 1; w++) { if (tempstr[w].substring(5, 6) == 'T') { - tempstr[w].slice(7) == 'undefined' ? log('Adjust data (T) for the QR page under ' + dpPath + 'data. Follow the instructions in the wiki.', 'warn') : '' ; - } + tempstr[w].slice(7) == 'undefined' ? log('Adjust data (T) for the QR page under ' + dpPath + 'data. Follow the instructions in the wiki.', 'warn') : ''; + } if (tempstr[w].substring(0, 1) == 'S') { - tempstr[w].slice(2) == 'undefined' ? log('Adjust data (S) for the QR page under ' + dpPath + 'data. Follow the instructions in the wiki.', 'warn') : optionalValue1 = tempstr[w].slice(2); + tempstr[w].slice(2) == 'undefined' + ? log('Adjust data (S) for the QR page under ' + dpPath + 'data. Follow the instructions in the wiki.', 'warn') + : (optionalValue1 = tempstr[w].slice(2)); } if (tempstr[w].substring(0, 1) == 'P') { optionalValue2 = tempstr[w].slice(2); @@ -6048,36 +6608,50 @@ function GenerateQRPage(page: NSPanel.PageQR): NSPanel.Payload[] { if (hiddenPWD) { iconColor1 = getState(page.items[0].id + '.SWITCH').val ? rgb_dec565(colorScale0) : rgb_dec565(colorScale10); type2 = 'switch'; - internalName2 = id + internalName2 = id; iconId2 = ''; displayName2 = getState(page.items[0].id + '.SWITCH').val ? findLocale('qr', 'Wlan enabled') : findLocale('qr', 'Wlan disabled'); optionalValue2 = getState(page.items[0].id + '.SWITCH').val ? 1 : 0; } out_msgs.push({ - payload: 'entityUpd~' + //entityUpd - heading + '~' + //heading - GetNavigationString(pageId) + '~' + //navigation - textQR + '~' + //textQR - type1 + '~' + //type - internalName1 + '~' + //internalName - iconId1 + '~' + //iconId - iconColor1 + '~' + //iconColor - displayName1 + '~' + //displayName - optionalValue1 + '~' + //optionalValue - type2 + '~' + //type - internalName2 + '~' + //internalName - iconId2 + '~' + //iconId - iconColor2 + '~' + //iconColor - displayName2 + '~' + //displayName - optionalValue2 + payload: + 'entityUpd~' + //entityUpd + heading + + '~' + //heading + GetNavigationString(pageId) + + '~' + //navigation + textQR + + '~' + //textQR + type1 + + '~' + //type + internalName1 + + '~' + //internalName + iconId1 + + '~' + //iconId + iconColor1 + + '~' + //iconColor + displayName1 + + '~' + //displayName + optionalValue1 + + '~' + //optionalValue + type2 + + '~' + //type + internalName2 + + '~' + //internalName + iconId2 + + '~' + //iconId + iconColor2 + + '~' + //iconColor + displayName2 + + '~' + //displayName + optionalValue2, }); if (Debug) { log('GenerateQRPage payload: ' + JSON.stringify(out_msgs), 'info'); } return out_msgs; - } catch (err: any) { log('error at function GenerateQRPage: ' + err.message, 'warn'); return []; @@ -6095,28 +6669,32 @@ function unsubscribePowerSubscriptions(): void { for (let i = 0; i < config.subPages.length; i++) { const page: NSPanel.PageType = config.subPages[i]; if (isPagePower(page)) { - let powerID = page.items[0].id; + let powerID = page.items[0].id; unsubscribe(powerID + '.ACTUAL'); } } if (Debug) log('unsubscribePowerSubscriptions getstartet', 'info'); -} +} function subscribePowerSubscriptions(id: string): void { - on({id: id + '.ACTUAL', change: "ne"}, async function () { - (function () { if (timeoutPower) { clearTimeout(timeoutPower); timeoutPower = null; } })(); + on({ id: id + '.ACTUAL', change: 'ne' }, async function () { + (function () { + if (timeoutPower) { + clearTimeout(timeoutPower); + timeoutPower = null; + } + })(); timeoutPower = setTimeout(async function () { GeneratePage(activePage!); - },25) + }, 25); }); -} +} function GeneratePowerPage(page: NSPanel.PagePower): NSPanel.Payload[] { try { - - let obj:object = {}; - let demoMode = false; - if (page.items[0].id == undefined){ + let obj: object = {}; + let demoMode = false; + if (page.items[0].id == undefined) { log('No PageItem defined - cardPower demo mode active', 'info'); demoMode = true; } @@ -6128,15 +6706,15 @@ function GeneratePowerPage(page: NSPanel.PagePower): NSPanel.Payload[] { let heading = 'cardPower Example'; if (demoMode != true) { - let id = page.items[0].id + let id = page.items[0].id; unsubscribePowerSubscriptions(); let o = getObject(id); heading = page.heading !== undefined ? page.heading : o.common.name.de; - obj = JSON.parse((getState(page.items[0].id + '.ACTUAL').val)); + obj = JSON.parse(getState(page.items[0].id + '.ACTUAL').val); } - + let out_msgs: NSPanel.Payload[] = []; // Leave the display on if the alwaysOnDisplay parameter is specified (true) @@ -6176,55 +6754,71 @@ function GeneratePowerPage(page: NSPanel.PagePower): NSPanel.Payload[] { array_icon_color[obji] = arrayColorScale[color]; array_icon[obji] = obj[obji].icon; array_powerspeed[obji] = obj[obji].speed; - array_powerstate[obji] = obj[obji].value + ' ' + obj[obji].unit ; + array_powerstate[obji] = obj[obji].value + ' ' + obj[obji].unit; } array_icon[0] = obj[0].icon; array_powerstate[0] = obj[0].value + ' ' + obj[0].unit; array_icon_color[0] = arrayColorScale[obj[0].iconColor]; } - let power_string : any = ''; + let power_string: any = ''; - for (let i = 0; i < 6; i++ ) { - power_string = power_string + '~'; // type (ignored) - power_string = power_string + '~'; // intNameEntity (ignored) - power_string = power_string + Icons.GetIcon(array_icon[i+1]) + '~'; // icon~ - power_string = power_string + rgb_dec565(array_icon_color[i+1]) + '~'; // icon_color~ - power_string = power_string + '~'; // display (ignored in TS) - power_string = power_string + array_powerstate[i+1] + '~'; // optionalValue~ - power_string = power_string + array_powerspeed[i+1] + '~'; // speed~ + for (let i = 0; i < 6; i++) { + power_string = power_string + '~'; // type (ignored) + power_string = power_string + '~'; // intNameEntity (ignored) + power_string = power_string + Icons.GetIcon(array_icon[i + 1]) + '~'; // icon~ + power_string = power_string + rgb_dec565(array_icon_color[i + 1]) + '~'; // icon_color~ + power_string = power_string + '~'; // display (ignored in TS) + power_string = power_string + array_powerstate[i + 1] + '~'; // optionalValue~ + power_string = power_string + array_powerspeed[i + 1] + '~'; // speed~ if (Debug) log(power_string, 'info'); } power_string = power_string.substring(0, power_string.length - 1); - + out_msgs.push({ - payload: 'entityUpd~' + //entityUpd~* - heading + '~' + //internalNameEntity*~* - GetNavigationString(pageId) + '~' + //navigation*~* - // Home Icon / Value below Home Icon - '' + '~' + // type (ignored) - '' + '~' + // intNameEntity (ignored) - Icons.GetIcon(array_icon[0]) + '~' + // icon - rgb_dec565(array_icon_color[0]) + '~' + // icon_color - '' + '~' + // display (ignored in TS) - array_powerstate[0] + '~' + // optionalValue - '' + '~' + // speed - // Value above Home Icon - '' + '~' + // type (ignored) - '' + '~' + // intNameEntity (ignored) - '' + '~' + // icon - '' + '~' + // icon_color - '' + '~' + // display (ignored in TS) - '' + '~' + // optionalValue - '' + '~' + // speed~ - // 1st to 6th Item - power_string + payload: + 'entityUpd~' + //entityUpd~* + heading + + '~' + //internalNameEntity*~* + GetNavigationString(pageId) + + '~' + //navigation*~* + // Home Icon / Value below Home Icon + '' + + '~' + // type (ignored) + '' + + '~' + // intNameEntity (ignored) + Icons.GetIcon(array_icon[0]) + + '~' + // icon + rgb_dec565(array_icon_color[0]) + + '~' + // icon_color + '' + + '~' + // display (ignored in TS) + array_powerstate[0] + + '~' + // optionalValue + '' + + '~' + // speed + // Value above Home Icon + '' + + '~' + // type (ignored) + '' + + '~' + // intNameEntity (ignored) + '' + + '~' + // icon + '' + + '~' + // icon_color + '' + + '~' + // display (ignored in TS) + '' + + '~' + // optionalValue + '' + + '~' + // speed~ + // 1st to 6th Item + power_string, }); if (Debug) log('GeneratePowerPage payload: ' + JSON.stringify(out_msgs), 'info'); return out_msgs; - } catch (err: any) { log('error at function GeneratePowerPage: ' + err.message, 'warn'); return []; @@ -6237,55 +6831,59 @@ function GenerateChartPage(page: NSPanel.PageChart): NSPanel.Payload[] { activePage = page; let id = page.items[0].id; - let out_msgs: NSPanel.Payload[] = []; + let out_msgs: NSPanel.Payload[] = []; out_msgs.push({ payload: 'pageType~' + page.type }); - let heading = page.heading !== undefined ? page.heading : "Chart..."; + let heading = page.heading !== undefined ? page.heading : 'Chart...'; const txt = getState(id + '.ACTUAL')?.val; if (!txt) { - throw new Error(`Unable to get the state of ${id}.ACTUAL`) + throw new Error(`Unable to get the state of ${id}.ACTUAL`); } - let yAxisTicks : number[] = []; + let yAxisTicks: number[] = []; if (!page.items[0].yAxisTicks) { - const sorted = [...String(txt).matchAll(timeValueRegEx)].map(x => Number(x[1])).sort((x, y) => x < y ? -1 : 1); + const sorted = [...String(txt).matchAll(timeValueRegEx)].map((x) => Number(x[1])).sort((x, y) => (x < y ? -1 : 1)); if (sorted.length === 0) { - throw new Error (`Page item ${id} yAxisTicks is undefined and unable to be calculated!`) + throw new Error(`Page item ${id} yAxisTicks is undefined and unable to be calculated!`); } const minValue = sorted[0]; const maxValue = sorted[sorted.length - 1]; const tick = Math.max(Number(((maxValue - minValue) / 5).toFixed()), 10); let currentTick = minValue - tick; - while(currentTick < (maxValue + tick)) { + while (currentTick < maxValue + tick) { yAxisTicks.push(currentTick); currentTick += tick; - } + } if (Debug) { log(`Calculated yAxisTicks for ${id} (Min: ${minValue}, Max: ${maxValue}, Tick: ${tick}): ${yAxisTicks}`); } - } else { - yAxisTicks = typeof page.items[0].yAxisTicks === 'string' - ? JSON.parse(getState(page.items[0].yAxisTicks).val) - : page.items[0].yAxisTicks; + } else { + yAxisTicks = typeof page.items[0].yAxisTicks === 'string' ? JSON.parse(getState(page.items[0].yAxisTicks).val) : page.items[0].yAxisTicks; } if (!page.items[0].onColor) { - throw new Error (`Page item ${id} onColor is undefined!`) + throw new Error(`Page item ${id} onColor is undefined!`); } out_msgs.push({ - payload: 'entityUpd~' + //entityUpd - heading + '~' + //heading - GetNavigationString(pageId) + '~' + //navigation - rgb_dec565(page.items[0].onColor) + '~' + //color - page.items[0].yAxis + '~' + - yAxisTicks.join(':') + '~' + - txt - }); + payload: + 'entityUpd~' + //entityUpd + heading + + '~' + //heading + GetNavigationString(pageId) + + '~' + //navigation + rgb_dec565(page.items[0].onColor) + + '~' + //color + page.items[0].yAxis + + '~' + + yAxisTicks.join(':') + + '~' + + txt, + }); if (Debug) log('GenerateChartPage payload: ' + JSON.stringify(out_msgs), 'info'); return out_msgs; @@ -6328,26 +6926,26 @@ function toggleState(id: string): boolean { return false; } -// Begin Monobutton -function triggerButton(id: string): boolean{ - try { - let obj = getObject(id); - if (existsState(id) && obj.common.type !== undefined && obj.common.type === "boolean") { - setState(id, true); - setTimeout(function() { setState(id, false) }, 250); - return true; - } - - } catch (err: any) { - log('error at function triggerButton: ' + err.message, 'warn'); - } - return false; -} +// Begin Monobutton +function triggerButton(id: string): boolean { + try { + let obj = getObject(id); + if (existsState(id) && obj.common.type !== undefined && obj.common.type === 'boolean') { + setState(id, true); + setTimeout(function () { + setState(id, false); + }, 250); + return true; + } + } catch (err: any) { + log('error at function triggerButton: ' + err.message, 'warn'); + } + return false; +} // End Monobutton function HandleButtonEvent(words: any): void { try { - // Turn off the display if the alwaysOnDisplay parameter was specified if (alwaysOn == true) { unsubscribePowerSubscriptions(); @@ -6360,33 +6958,38 @@ function HandleButtonEvent(words: any): void { let pageItemID: string = ''; if (!isNaN(id)) { - if (activePage!.items[id].id == undefined) throw new Error ('Missing pageItem.id in HandleButtonEvent!'); + if (activePage!.items[id].id == undefined) throw new Error('Missing pageItem.id in HandleButtonEvent!'); pageItemID = activePage!.items[id].id!; if (Debug) { - log('HandleButtonEvent activePage: ' + activePage!.items.length + ' id: ' + id + ' tempid: ' + tempid + ' pageItemId: ' + pageItemID); + log('HandleButtonEvent activePage: ' + activePage!.items.length + ' id: ' + id + ' tempid: ' + tempid + ' pageItemId: ' + pageItemID); } - id = pageItemID - }; + id = pageItemID; + } if (Debug) { log('HandleButtonEvent übergebene Werte ' + words[0] + ' - ' + words[1] + ' - ' + words[2] + ' - ' + words[3] + ' - ' + words[4] + ' - PageId: ' + pageId, 'info'); } - if ((words[2]).substring(0, 8) == 'navigate') { - GeneratePage(eval((words[2]).substring(9, (words[2]).length))); + if (words[2].substring(0, 8) == 'navigate') { + let temppage: PageType = eval(words[2].substring(9, words[2].length)); + if (temppage.hiddenByTrigger && valueHiddenCards) { + log(`Subpage ${words[2].substring(9, words[2].length)} is hidden`); + return; + } + GeneratePage(temppage); return; } - if (words[2] == 'bNext' || words[2] == 'bPrev' || words[2] == 'bUp' || words[2] == 'bHome' || words[2] == 'bSubNext' || words[2] == 'bSubPrev' ) { + if (words[2] == 'bNext' || words[2] == 'bPrev' || words[2] == 'bUp' || words[2] == 'bHome' || words[2] == 'bSubNext' || words[2] == 'bSubPrev') { buttonAction = words[2]; pageCounter = 0; alwaysOn = false; SendToPanel({ payload: 'timeout~' + getState(NSPanel_Path + 'Config.Screensaver.timeoutScreensaver').val }); } - setOrCreate(NSPanel_Path + "Event.Button.Action", buttonAction ?? words[2], false, {name: 'Incoming button acion', type: 'string', role: 'text', write: false, read: true}); - setOrCreate(NSPanel_Path + "Event.Button.Value", words[4] != undefined ? words[4] : '', false, {name: 'Incoming button value', type: 'string', role: 'text', write: false, read: true}); - setOrCreate(NSPanel_Path + "Event.Button.Id", id, false, {name: 'Incoming button id', type: 'string', role: 'text', write: false, read: true}); + setOrCreate(NSPanel_Path + 'Event.Button.Action', buttonAction ?? words[2], false, { name: 'Incoming button acion', type: 'string', role: 'text', write: false, read: true }); + setOrCreate(NSPanel_Path + 'Event.Button.Value', words[4] != undefined ? words[4] : '', false, { name: 'Incoming button value', type: 'string', role: 'text', write: false, read: true }); + setOrCreate(NSPanel_Path + 'Event.Button.Id', id, false, { name: 'Incoming button id', type: 'string', role: 'text', write: false, read: true }); if (Debug) { log('HandleButtonEvent buttonAction: ' + buttonAction, 'info'); @@ -6396,11 +6999,12 @@ function HandleButtonEvent(words: any): void { buttonAction = 'bExit'; } - let pageNum:number = 0; + let pageNum: number = 0; switch (buttonAction) { case 'bUp': - if (pageId < 0) { // Check whether button1page or button2page + if (pageId < 0) { + // Check whether button1page or button2page pageId = 0; UnsubscribeWatcher(); GeneratePage(config.pages[pageId]); @@ -6417,8 +7021,7 @@ function HandleButtonEvent(words: any): void { } } GeneratePage(activePage!.parent); - } - else { + } else { GeneratePage(config.pages[pageId]); } break; @@ -6428,6 +7031,18 @@ function HandleButtonEvent(words: any): void { pageNum = (((pageId + 1) % config.pages.length) + config.pages.length) % config.pages.length; pageId = pageNum; UnsubscribeWatcher(); + //-Serching for next unhidden Page---------------------- + if (config.pages[pageId].hiddenByTrigger && valueHiddenCards) { + for (let i = pageId; i <= config.pages.length; i++) { + if (i == config.pages.length) { + i = 0; + } + if (!config.pages[i].hiddenByTrigger) { + pageId = i; + break; + } + } + } GeneratePage(config.pages[pageId]); break; case 'bSubNext': @@ -6439,6 +7054,15 @@ function HandleButtonEvent(words: any): void { pageNum = (((pageId - 1) % config.pages.length) + config.pages.length) % config.pages.length; pageId = pageNum; UnsubscribeWatcher(); + //-Searching for previous unhidden Page---------------------- + if (config.pages[pageId].hiddenByTrigger && valueHiddenCards) { + for (let i = pageId; i >= 0; i--) { + if (config.pages[i].hiddenByTrigger == false || config.pages[i].hiddenByTrigger == undefined) { + pageId = i; + break; + } + } + } if (activePage != undefined && activePage!.parent != undefined) { //update pageID for (let i = 0; i < config.pages.length; i++) { @@ -6448,12 +7072,11 @@ function HandleButtonEvent(words: any): void { } } GeneratePage(activePage!.parent); - } - else { + } else { GeneratePage(config.pages[pageId]); } break; - case 'bSubPrev': + case 'bSubPrev': UnsubscribeWatcher(); // check this please GeneratePage(eval(activePage!.prev!)); @@ -6465,7 +7088,11 @@ function HandleButtonEvent(words: any): void { if (words[2] == 'screensaver') { if (getState(NSPanel_Path + 'Config.Screensaver.screenSaverDoubleClick').val) { if (words[4] >= 2) { - if (existsObject(NSPanel_Path + 'ScreensaverInfo.bExitPage') && getState(NSPanel_Path + 'ScreensaverInfo.bExitPage').val != null && getState(NSPanel_Path + 'ScreensaverInfo.bExitPage').val != -1) { + if ( + existsObject(NSPanel_Path + 'ScreensaverInfo.bExitPage') && + getState(NSPanel_Path + 'ScreensaverInfo.bExitPage').val != null && + getState(NSPanel_Path + 'ScreensaverInfo.bExitPage').val != -1 + ) { pageId = getState(NSPanel_Path + 'ScreensaverInfo.bExitPage').val; } } else { @@ -6485,15 +7112,19 @@ function HandleButtonEvent(words: any): void { if (getState(NSPanel_Path + 'ScreensaverInfo.popupNotifyText').val != '') { setIfExists(NSPanel_Path + 'ScreensaverInfo.popupNotifyText', ''); } - if (existsObject(NSPanel_Path + 'ScreensaverInfo.bExitPage') && getState(NSPanel_Path + 'ScreensaverInfo.bExitPage').val != null && getState(NSPanel_Path + 'ScreensaverInfo.bExitPage').val != -1) { - pageId = getState(NSPanel_Path + 'ScreensaverInfo.bExitPage').val + if ( + existsObject(NSPanel_Path + 'ScreensaverInfo.bExitPage') && + getState(NSPanel_Path + 'ScreensaverInfo.bExitPage').val != null && + getState(NSPanel_Path + 'ScreensaverInfo.bExitPage').val != -1 + ) { + pageId = getState(NSPanel_Path + 'ScreensaverInfo.bExitPage').val; } screensaverEnabled = true; // Activating screensaver also on One-Time click } - activePage = config.pages[pageId]; - } + activePage = config.pages[pageId]; + } if (words[2] == 'popupInSel' && activePage!.type == 'cardMedia') { - if (Debug) log('Leave popupInsel without any action', 'info') + if (Debug) log('Leave popupInsel without any action', 'info'); pageCounter = 0; GeneratePage(activePage!); setTimeout(async function () { @@ -6501,25 +7132,25 @@ function HandleButtonEvent(words: any): void { GeneratePage(activePage!); }, 3000); } else { - pageCounter = 0; + pageCounter = 0; GeneratePage(activePage!); } break; - case 'bHome': - if (Debug) { - log('HandleButtonEvent -> bHome: ' + words[4] + ' - ' + pageId, 'info'); - } - UnsubscribeWatcher(); - const home = activePage!.home; - if (home !== undefined) { - pageId = config.pages.findIndex(a => a == eval(home)) - pageId = pageId === -1 ? 0 : pageId; - GeneratePage(eval(home)); - } else { - pageId = 0; - GeneratePage(config.pages[0]); - } - break; + case 'bHome': + if (Debug) { + log('HandleButtonEvent -> bHome: ' + words[4] + ' - ' + pageId, 'info'); + } + UnsubscribeWatcher(); + const home = activePage!.home; + if (home !== undefined) { + pageId = config.pages.findIndex((a) => a == eval(home)); + pageId = pageId === -1 ? 0 : pageId; + GeneratePage(eval(home)); + } else { + pageId = 0; + GeneratePage(config.pages[0]); + } + break; case 'notifyAction': if (words[4] == 'yes') { setState(popupNotifyInternalName, { val: words[2], ack: true }); @@ -6535,25 +7166,23 @@ function HandleButtonEvent(words: any): void { case 'OnOff': if (existsObject(id)) { let action = false; - if (words[4] == '1') - action = true; + if (words[4] == '1') action = true; let o = getObject(id); if (Debug) { - log('HandleButtonEvent -> OnOff: ' + words[4] + ' - ' + id + ' - Role - ' + o.common.role, 'info') + log('HandleButtonEvent -> OnOff: ' + words[4] + ' - ' + id + ' - Role - ' + o.common.role, 'info'); } const role = o.common.role as NSPanel.roles; switch (role) { case 'level.mode.fan': case 'socket': case 'light': - let pageItem = findPageItem(id); - if(pageItem.monobutton != undefined && pageItem.monobutton == true){ - triggerButton(id + ".SET"); - } - else { - setIfExists(id + '.SET', action); - } - break; + let pageItem = findPageItem(id); + if (pageItem.monobutton != undefined && pageItem.monobutton == true) { + triggerButton(id + '.SET'); + } else { + setIfExists(id + '.SET', action); + } + break; case 'dimmer': setIfExists(id + '.ON_SET', action) ? true : setIfExists(id + '.ON_ACTUAL', action); break; @@ -6580,21 +7209,20 @@ function HandleButtonEvent(words: any): void { if (Debug) log('NaviToPage: ' + words[2]); GeneratePage(indicatorScreensaverEntity.ScreensaverEntityNaviToPage); } else { - const value = ['event','buttonPress2','screensaver','bExit','2']; + const value = ['event', 'buttonPress2', 'screensaver', 'bExit', '2']; HandleButtonEvent(value); } } if (existsObject(id)) { let action = false; - if (words[4] == '1') - action = true; + if (words[4] == '1') action = true; let o = getObject(id); switch (o.common.role as NSPanel.roles) { case 'lock': case 'button': toggleState(id + '.SET') ? true : toggleState(id + '.ON_SET'); - break; + break; case 'buttonSensor': if (existsObject(id + '.ACTUAL')) { toggleState(id + '.ACTUAL'); @@ -6602,15 +7230,14 @@ function HandleButtonEvent(words: any): void { break; case 'socket': case 'light': - // Change for monobutton - let pageItem = findPageItem(id); - if(pageItem.monobutton != undefined && pageItem.monobutton == true){ - triggerButton(id + ".SET"); - } - else { - toggleState(id + ".SET") ? true : toggleState(id + ".ON_SET"); - } - break; + // Change for monobutton + let pageItem = findPageItem(id); + if (pageItem.monobutton != undefined && pageItem.monobutton == true) { + triggerButton(id + '.SET'); + } else { + toggleState(id + '.SET') ? true : toggleState(id + '.ON_SET'); + } + break; case 'dimmer': toggleState(id + '.ON_SET') ? true : toggleState(id + '.ON_ACTUAL'); break; @@ -6624,20 +7251,19 @@ function HandleButtonEvent(words: any): void { break; case 'media': if (!activePage || activePage.type != 'cardMedia') { - if (activePage) throw new Error(`Found channel role media for card: ${activePage.type} not allowed`) + if (activePage) throw new Error(`Found channel role media for card: ${activePage.type} not allowed`); else throw new Error(`Something went wrong! Active Page is empty!`); } if (tempid[1] == undefined) { if (Debug) log('Logo click', 'info'); GeneratePage(activePage!); } else if (tempid[1] == 'repeat') { - let pageItemRepeat = findPageItem(id); if (isPageMediaItem(pageItemRepeat)) { let adapterInstanceRepeat = pageItemRepeat.adapterPlayerInstance; let adapterRepeat = adapterInstanceRepeat.split('.'); const deviceAdapterRP: NSPanel.PlayerType = adapterRepeat[0] as NSPanel.PlayerType; - + switch (deviceAdapterRP) { case 'spotify-premium': if (Debug) log(getState(id + '.REPEAT').val); @@ -6684,7 +7310,8 @@ function HandleButtonEvent(words: any): void { break; case 'volumio': let urlString: string = `${getState(adapterInstanceRepeat + 'info.host').val}/api/commands/?cmd=repeat`; - axios.get(urlString, {headers: {'User-Agent': 'ioBroker'}}) + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) .then(async function (response) { if (response.status === 200) { if (Debug) { @@ -6707,7 +7334,7 @@ function HandleButtonEvent(words: any): void { GeneratePage(activePage!); break; case 1: - setIfExists(id + '.REPEAT', 2) + setIfExists(id + '.REPEAT', 2); GeneratePage(activePage!); break; case 2: @@ -6738,7 +7365,12 @@ function HandleButtonEvent(words: any): void { checkBlindActive = true; break; case 'positionSlider': - (function () { if (timeoutSlider) { clearTimeout(timeoutSlider); timeoutSlider = null; } })(); + (function () { + if (timeoutSlider) { + clearTimeout(timeoutSlider); + timeoutSlider = null; + } + })(); timeoutSlider = setTimeout(async function () { let pageItem = findPageItem(id); if (pageItem.minValueLevel != undefined && pageItem.maxValueLevel != undefined) { @@ -6761,7 +7393,12 @@ function HandleButtonEvent(words: any): void { setIfExists(id + '.TILT_CLOSE', true); break; case 'tiltSlider': - (function () { if (timeoutSlider) { clearTimeout(timeoutSlider); timeoutSlider = null; } })(); + (function () { + if (timeoutSlider) { + clearTimeout(timeoutSlider); + timeoutSlider = null; + } + })(); timeoutSlider = setTimeout(async function () { let pageItem = findPageItem(id); if (pageItem.minValueTilt != undefined && pageItem.maxValueTilt != undefined) { @@ -6773,7 +7410,12 @@ function HandleButtonEvent(words: any): void { }, 250); break; case 'brightnessSlider': - (function () { if (timeoutSlider) { clearTimeout(timeoutSlider); timeoutSlider = null; } })(); + (function () { + if (timeoutSlider) { + clearTimeout(timeoutSlider); + timeoutSlider = null; + } + })(); timeoutSlider = setTimeout(async function () { if (existsObject(id)) { let o = getObject(id); @@ -6804,12 +7446,17 @@ function HandleButtonEvent(words: any): void { }, 250); break; case 'colorTempSlider': - (function () { if (timeoutSlider) { clearTimeout(timeoutSlider); timeoutSlider = null; } })(); + (function () { + if (timeoutSlider) { + clearTimeout(timeoutSlider); + timeoutSlider = null; + } + })(); timeoutSlider = setTimeout(async function () { let pageItem = findPageItem(id); if (pageItem.minValueColorTemp !== undefined && pageItem.maxValueColorTemp !== undefined) { let colorTempK = Math.trunc(scale(parseInt(words[4]), 100, 0, pageItem.minValueColorTemp, pageItem.maxValueColorTemp)); - setIfExists(id + '.TEMPERATURE', (colorTempK)); + setIfExists(id + '.TEMPERATURE', colorTempK); } else { setIfExists(id + '.TEMPERATURE', parseInt(words[4])); } @@ -6836,16 +7483,15 @@ function HandleButtonEvent(words: any): void { break; case 'rgbSingle': let pageItem = findPageItem(id); - if (pageItem.colormode == "xy") { + if (pageItem.colormode == 'xy') { //For e.g. Deconz XY - setIfExists(id + ".RGB", rgb_to_cie(rgb.red, rgb.green, rgb.blue)); + setIfExists(id + '.RGB', rgb_to_cie(rgb.red, rgb.green, rgb.blue)); if (Debug) { log('HandleButtonEvent colorWeel colorMode=xy -> rgb_to_cie Wert: ' + rgb_to_cie(rgb.red, rgb.green, rgb.blue), 'info'); } - } - else { + } else { //For RGB - setIfExists(id + ".RGB", ConvertRGBtoHex(rgb.red, rgb.green, rgb.blue)); + setIfExists(id + '.RGB', ConvertRGBtoHex(rgb.red, rgb.green, rgb.blue)); } break; } @@ -6855,7 +7501,8 @@ function HandleButtonEvent(words: any): void { break; case 'tempUpdHighLow': let temps = words[4].split('|'); - if (getState(id + '.ACTUAL2').val * 10 != parseInt(temps[1])) { // avoid writing if not needed + if (getState(id + '.ACTUAL2').val * 10 != parseInt(temps[1])) { + // avoid writing if not needed setIfExists(id + '.ACTUAL2', parseInt(temps[1]) / 10); } if (getState(id + '.SET').val * 10 != parseInt(temps[0])) { @@ -6868,7 +7515,7 @@ function HandleButtonEvent(words: any): void { if (tempPage.adapterPlayerInstance.startsWith('bosesoundtouch')) { setIfExists(tempPage.adapterPlayerInstance + 'key', 'PREV_TRACK'); } else { - setIfExists(id + '.PREV', true); + setIfExists(id + '.PREV', true); } GeneratePage(activePage!); } @@ -6880,7 +7527,7 @@ function HandleButtonEvent(words: any): void { let adaInstanceSplit = pageItemTemp.adapterPlayerInstance!.split('.'); if (adaInstanceSplit[0] == 'squeezeboxrpc') { let adapterPlayerInstanceStateSeceltor: string = pageItemTemp.adapterPlayerInstance + 'Players.' + pageItemTemp.mediaDevice + '.state'; - if (Debug) log('HandleButtonEvent media-pause Squeezebox-> adapterPlayerInstanceStateSeceltor: ' + adapterPlayerInstanceStateSeceltor, 'info'); + if (Debug) log('HandleButtonEvent media-pause Squeezebox-> adapterPlayerInstanceStateSeceltor: ' + adapterPlayerInstanceStateSeceltor, 'info'); let stateVal = getState(adapterPlayerInstanceStateSeceltor).val; if (stateVal == 0) { setState(adapterPlayerInstanceStateSeceltor, 1); @@ -6908,7 +7555,7 @@ function HandleButtonEvent(words: any): void { if (tempPage.adapterPlayerInstance.startsWith('bosesoundtouch')) { setIfExists(tempPage.adapterPlayerInstance + 'key', 'NEXT_TRACK'); } else { - setIfExists(id + '.NEXT', true); + setIfExists(id + '.NEXT', true); } GeneratePage(activePage!); } @@ -6917,40 +7564,40 @@ function HandleButtonEvent(words: any): void { case 'media-shuffle': { const tempPage = findPageItem(id); if (isPageMediaItem(tempPage)) { - if (tempPage.adapterPlayerInstance.startsWith("volumio")) { - const item = findPageItem(id) - if (isPageMediaItem(item)) item.playList = []; + if (tempPage.adapterPlayerInstance.startsWith('volumio')) { + const item = findPageItem(id); + if (isPageMediaItem(item)) item.playList = []; break; } //Volumio: empty playlist $uha-20230103 - if ((tempPage.adapterPlayerInstance).startsWith("spotify")) { + if (tempPage.adapterPlayerInstance.startsWith('spotify')) { if (getState(id + '.SHUFFLE').val == 'off') { setIfExists(id + '.SHUFFLE', 'on'); } else { setIfExists(id + '.SHUFFLE', 'off'); } } - if ((tempPage.adapterPlayerInstance).startsWith("alexa")) { + if (tempPage.adapterPlayerInstance.startsWith('alexa')) { if (getState(id + '.SHUFFLE').val == false) { setIfExists(id + '.SHUFFLE', true); } else { setIfExists(id + '.SHUFFLE', false); } } - if ((tempPage.adapterPlayerInstance).startsWith("sonos")) { + if (tempPage.adapterPlayerInstance.startsWith('sonos')) { if (getState(id + '.SHUFFLE').val == false) { setIfExists(id + '.SHUFFLE', true); } else { setIfExists(id + '.SHUFFLE', false); } } - if ((tempPage.adapterPlayerInstance).startsWith("squeezeboxrpc")) { + if (tempPage.adapterPlayerInstance.startsWith('squeezeboxrpc')) { if (getState(tempPage.adapterPlayerInstance + 'Players.' + tempPage.mediaDevice + '.PlaylistShuffle').val == 1) { setIfExists(tempPage.adapterPlayerInstance + 'Players.' + tempPage.mediaDevice + '.PlaylistShuffle', 0); } else { setIfExists(tempPage.adapterPlayerInstance + 'Players.' + tempPage.mediaDevice + '.PlaylistShuffle', 1); } } - if ((tempPage.adapterPlayerInstance).startsWith("bosesoundtouch")) { + if (tempPage.adapterPlayerInstance.startsWith('bosesoundtouch')) { if (Debug) log(tempPage.adapterPlayerInstance + 'nowPlaying.shuffle'); if (getState(tempPage.adapterPlayerInstance + 'nowPlaying.shuffle').val == 'false') { setIfExists(tempPage.adapterPlayerInstance + 'key', 'SHUFFLE_ON'); @@ -6965,9 +7612,9 @@ function HandleButtonEvent(words: any): void { case 'volumeSlider': subscribeMediaSubscriptions(id); useMediaEvents = true; - pageCounter = 1; + pageCounter = 1; let vVolume = scale(parseInt(words[4]), 100, 0, activePage!.items[0]!.minValue ?? 0, activePage!.items[0]!.maxValue ?? 100); - setIfExists(id + '.VOLUME', Math.floor(vVolume)); + setIfExists(id + '.VOLUME', Math.floor(vVolume)); break; case 'mode-speakerlist': let pageItem = findPageItem(id); @@ -6980,13 +7627,13 @@ function HandleButtonEvent(words: any): void { case 'spotify-premium': let strDevicePI = pageItem.speakerList![words[4]]; let strDeviceID = spotifyGetDeviceID(strDevicePI); - setState(adapterInstance + 'devices.' + strDeviceID + ".useForPlayback", true); + setState(adapterInstance + 'devices.' + strDeviceID + '.useForPlayback', true); break; case 'alexa2': let i_list = Array.prototype.slice.apply($('[state.id="' + adapterInstance + 'Echo-Devices.*.Info.name"]')); for (let i_index in i_list) { let i = i_list[i_index]; - if ((getState(i).val) === pageItem.speakerList![words[4]]) { + if (getState(i).val === pageItem.speakerList![words[4]]) { if (Debug) log('HandleButtonEvent mode-Speakerlist Alexa2: ' + getState(i).val + ' - ' + pageItem.speakerList![words[4]], 'info'); let deviceId = i; deviceId = deviceId.split('.'); @@ -7002,9 +7649,9 @@ function HandleButtonEvent(words: any): void { case 'squeezeboxrpc': pageItem.mediaDevice = pageItem.speakerList![words[4]]; break; - case "volumio": + case 'volumio': break; - case "bosesoundtouch": + case 'bosesoundtouch': break; } pageCounter = 0; @@ -7026,12 +7673,18 @@ function HandleButtonEvent(words: any): void { case 'spotify-premium': let strDevicePI = pageItemPL.playList![words[4]]; if (Debug) log('HandleButtonEvent mode-playlist Spotify -> strDevicePI: ' + strDevicePI, 'info'); - let playlistListString = (getState(adapterInstancePL + 'playlists.playlistListString').val).split(';'); - let playlistListIds = (getState(adapterInstancePL + 'playlists.playlistListIds').val).split(';'); + let playlistListString = getState(adapterInstancePL + 'playlists.playlistListString').val.split(';'); + let playlistListIds = getState(adapterInstancePL + 'playlists.playlistListIds').val.split(';'); let playlistIndex = playlistListString.indexOf(strDevicePI); setState(adapterInstancePL + 'playlists.playlistList', playlistListIds[playlistIndex]); setTimeout(async function () { - globalTracklist = (function () { try {return JSON.parse(getState(adapterInstancePL + 'player.playlist.trackListArray').val);} catch(e) {return {};}})(); + globalTracklist = (function () { + try { + return JSON.parse(getState(adapterInstancePL + 'player.playlist.trackListArray').val); + } catch (e) { + return {}; + } + })(); }, 2000); break; case 'alexa2': @@ -7040,13 +7693,14 @@ function HandleButtonEvent(words: any): void { break; case 'sonos': let strDevicePLSonos = pageItemPL.playList![words[4]].split('.'); - if (Debug) log(adapterInstancePL + 'root.' + pageItemPL.mediaDevice + '.playlist_set', 'info') + if (Debug) log(adapterInstancePL + 'root.' + pageItemPL.mediaDevice + '.playlist_set', 'info'); setState(adapterInstancePL + 'root.' + pageItemPL.mediaDevice + '.playlist_set', strDevicePLSonos[0]); - break; + break; case 'volumio': let strDevicePL = pageItemPL.playList![words[4]]; - let urlString: string = `${getState(adapterInstancePL+'info.host').val}/api/commands/?cmd=playplaylist&name=${strDevicePL}`; - axios.get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + let urlString: string = `${getState(adapterInstancePL + 'info.host').val}/api/commands/?cmd=playplaylist&name=${strDevicePL}`; + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) .then(async function (response) { if (response.status === 200) { if (Debug) { @@ -7063,13 +7717,13 @@ function HandleButtonEvent(words: any): void { case 'squeezeboxrpc': setState([adapterInstancePL, 'Players.', pageItemPL.mediaDevice, '.cmdPlayFavorite'].join(''), words[4]); break; - case "bosesoundtouch": + case 'bosesoundtouch': if (Debug) log('bosesoundtouch - playlist ' + pageItemPL.adapterPlayerInstance + ' - ' + words[4]); - if (Debug) log(adapterInstancePL + 'key'); + if (Debug) log(adapterInstancePL + 'key'); if (words[4] < 6) { - setState(adapterInstancePL + 'key', 'PRESET_' + (parseInt(words[4]) + 1)); + setState(adapterInstancePL + 'key', 'PRESET_' + (parseInt(words[4]) + 1)); } else if (words[4] == 6) { - setState(adapterInstancePL + 'key', 'AUX_INPUT'); + setState(adapterInstancePL + 'key', 'AUX_INPUT'); } break; default: @@ -7101,8 +7755,9 @@ function HandleButtonEvent(words: any): void { if (Debug) log('Aktuell hat alexa2 keine Tracklist', 'info'); break; case 'volumio': - let urlString: string = `${getState(adapterInstanceTL+'info.host').val}/api/commands/?cmd=play&N=${words[4]}`; - axios.get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + let urlString: string = `${getState(adapterInstanceTL + 'info.host').val}/api/commands/?cmd=play&N=${words[4]}`; + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) .then(async function (response) { if (response.status === 200) { if (Debug) { @@ -7120,7 +7775,7 @@ function HandleButtonEvent(words: any): void { //@ts-ignore Fehler kommt von findPageItem in vscode setState([adapterInstanceTL, 'Players.', pageItemTL.mediaDevice, '.PlaylistCurrentIndex'].join(''), words[4]); break; - case "bosesoundtouch": + case 'bosesoundtouch': break; default: log('Hello Mr. Developer u miss in mode-tracklist something!', 'warn'); @@ -7154,7 +7809,7 @@ function HandleButtonEvent(words: any): void { let pageItemEQ = findPageItem(id); if (!isPageMediaItem(pageItemEQ)) break; if (Debug) log('HandleButtonEvent mode-equalizer -> id: ' + id, 'info'); - let lastIndex = (id.split('.')).pop(); + let lastIndex = id.split('.').pop(); setState(NSPanel_Path + 'Media.Player.' + lastIndex + '.EQ.activeMode', pageItemEQ.equalizerList![words[4]]); pageCounter = 0; GeneratePage(activePage!); @@ -7175,8 +7830,8 @@ function HandleButtonEvent(words: any): void { break; case 'squeezeboxrpc': const vDuration: number = getState(adapterInstanceSK + 'Players.' + pageItemSeek.mediaDevice + '.Duration').val; - const vSeekPercentage : number = words[4] * 10; - const setSeekSeconds: number = vSeekPercentage * vDuration / 100; + const vSeekPercentage: number = words[4] * 10; + const setSeekSeconds: number = (vSeekPercentage * vDuration) / 100; if (Debug) log(adapterInstanceSK + 'Players.' + pageItemSeek.mediaDevice + '.cmdGoTime' + ': ' + setSeekSeconds + ' sec.'); setState(adapterInstanceSK + 'Players.' + pageItemSeek.mediaDevice + '.cmdGoTime', String(setSeekSeconds.toFixed(0))); break; @@ -7204,9 +7859,9 @@ function HandleButtonEvent(words: any): void { case 'sonos': if (Debug) log('HandleButtonEvent mode-crossfade -> id: ' + id, 'info'); let cfState: boolean = false; - if (parseInt(words[4]) == 0 ) { - cfState = true; - } + if (parseInt(words[4]) == 0) { + cfState = true; + } setState(adapterInstanceCF + 'root.' + pageItemCrossfade.mediaDevice + '.crossfade', cfState); break; } @@ -7250,7 +7905,7 @@ function HandleButtonEvent(words: any): void { setIfExists(id + '.STATE', 0); } } else if (adapterInstance[0] == 'bosesoundtouch') { - setState(pageItemTemp.adapterPlayerInstance + 'key', 'POWER'); + setState(pageItemTemp.adapterPlayerInstance + 'key', 'POWER'); } else { setIfExists(id + '.STOP', true); } @@ -7260,7 +7915,7 @@ function HandleButtonEvent(words: any): void { case 'timer-start': if (words[4] != undefined) { let timer_panel = words[4].split(':'); - setIfExists(id + '.ACTUAL', (parseInt(timer_panel[1]) * 60) + parseInt(timer_panel[2])); + setIfExists(id + '.ACTUAL', parseInt(timer_panel[1]) * 60 + parseInt(timer_panel[2])); } setIfExists(id + '.STATE', 'active'); break; @@ -7277,7 +7932,6 @@ function HandleButtonEvent(words: any): void { break; case 'hvac_action': if (words[4] == 'BOOT' || words[4] == 'PART' || words[4] == 'AUTT' || words[4] == 'MANT' || words[4] == 'VACT') { - switch (words[4]) { case 'BOOT': setIfExists(words[2] + '.' + 'BOOST', !getState(words[2] + '.' + 'BOOST').val); @@ -7297,7 +7951,7 @@ function HandleButtonEvent(words: any): void { } let modes = ['BOOT', 'PART', 'AUTT', 'MANT', 'VACT']; let modesDP = ['BOOST', 'PARTY', 'AUTOMATIC', 'MANUAL', 'VACATION']; - for (let mode=0; mode < 5; mode++) { + for (let mode = 0; mode < 5; mode++) { if (words[4] != modes[mode]) { setIfExists(words[2] + '.' + modesDP[mode], false); } @@ -7307,8 +7961,8 @@ function HandleButtonEvent(words: any): void { let HVACMode = getState(words[2] + '.MODE').val; // Event is bound to its own object - if(existsObject(words[2] + '.' + words[4])) { - switch(words[4]) { + if (existsObject(words[2] + '.' + words[4])) { + switch (words[4]) { case 'SWING': if (getState(words[2] + '.SWING').val == 0) { setIfExists(words[2] + '.SWING', 1); @@ -7324,13 +7978,13 @@ function HandleButtonEvent(words: any): void { // Event is a mode of the list (mode change) let HVACModeList = getObject(words[2] + '.MODE').common.states; - for(const statekey in HVACModeList) { - if(HVACModeList[statekey] == words[4]) { + for (const statekey in HVACModeList) { + if (HVACModeList[statekey] == words[4]) { HVACMode = parseInt(statekey); break; } } - + setIfExists(words[2] + '.' + 'MODE', HVACMode); GeneratePage(activePage!); } @@ -7351,13 +8005,23 @@ function HandleButtonEvent(words: any): void { let nobj = getObject(id); switch (nobj.common.role as NSPanel.roles) { case 'level.mode.fan': - (function () { if (timeoutSlider) { clearTimeout(timeoutSlider); timeoutSlider = null; } })(); + (function () { + if (timeoutSlider) { + clearTimeout(timeoutSlider); + timeoutSlider = null; + } + })(); timeoutSlider = setTimeout(async function () { setIfExists(id + '.SPEED', parseInt(words[4])); }, 250); break; - default: - (function () { if (timeoutSlider) { clearTimeout(timeoutSlider); timeoutSlider = null; } })(); + default: + (function () { + if (timeoutSlider) { + clearTimeout(timeoutSlider); + timeoutSlider = null; + } + })(); timeoutSlider = setTimeout(async function () { setIfExists(id + '.SET', parseInt(words[4])) ? true : setIfExists(id + '.ACTUAL', parseInt(words[4])); }, 250); @@ -7366,7 +8030,7 @@ function HandleButtonEvent(words: any): void { break; case 'mode-preset_modes': setIfExists(id + '.MODE', parseInt(words[4])); - break; + break; case 'A1': // Alarm page - activate alarm 1 if (words[4] != '') { setIfExists(id + '.TYPE', 'A1'); @@ -7374,9 +8038,9 @@ function HandleButtonEvent(words: any): void { setIfExists(id + '.ACTUAL', 'arming'); setIfExists(id + '.PANEL', NSPanel_Path); } - setTimeout(function(){ + setTimeout(function () { GeneratePage(activePage!); - },250); + }, 250); break; case 'A2': // Alarm page - activate alarm 2 if (words[4] != '') { @@ -7385,9 +8049,9 @@ function HandleButtonEvent(words: any): void { setIfExists(id + '.ACTUAL', 'arming'); setIfExists(id + '.PANEL', NSPanel_Path); } - setTimeout(function(){ + setTimeout(function () { GeneratePage(activePage!); - },250); + }, 250); break; case 'A3': // Alarm page - activate alarm 3 if (words[4] != '') { @@ -7396,9 +8060,9 @@ function HandleButtonEvent(words: any): void { setIfExists(id + '.ACTUAL', 'arming'); setIfExists(id + '.PANEL', NSPanel_Path); } - setTimeout(function(){ + setTimeout(function () { GeneratePage(activePage!); - },250); + }, 250); break; case 'A4': // Alarm page - activate alarm 4 if (words[4] != '') { @@ -7407,9 +8071,9 @@ function HandleButtonEvent(words: any): void { setIfExists(id + '.ACTUAL', 'arming'); setIfExists(id + '.PANEL', NSPanel_Path); } - setTimeout(function(){ + setTimeout(function () { GeneratePage(activePage!); - },250); + }, 250); break; case 'D1': // Alarm page - deactivate alarm 4 if (Debug) { @@ -7429,9 +8093,9 @@ function HandleButtonEvent(words: any): void { setIfExists(id + '.ACTUAL', 'triggered'); } setIfExists(id + '.PANEL', NSPanel_Path); - setTimeout(function(){ + setTimeout(function () { GeneratePage(activePage!); - },500); + }, 500); } break; case 'U1': // Unlock-Page @@ -7439,9 +8103,9 @@ function HandleButtonEvent(words: any): void { if (words[4] == getState(id + '.PIN').val) { UnsubscribeWatcher(); GeneratePage(eval(pageItemUnlock.targetPage!)); - setIfExists(id + '.ACTUAL', true) + setIfExists(id + '.ACTUAL', true); } else { - setIfExists(id + '.ACTUAL', false) + setIfExists(id + '.ACTUAL', false); } break; default: @@ -7452,80 +8116,79 @@ function HandleButtonEvent(words: any): void { } } -function setOrCreate(id : string, value : any, forceCreation: boolean = true, common: Partial = { }, callback?: iobJS.SetStateCallback) { +function setOrCreate(id: string, value: any, forceCreation: boolean = true, common: Partial = {}, callback?: iobJS.SetStateCallback) { if (!existsState(id)) { - extendObject(id.split('.').slice(0, -2).join('.'), {type: 'channel', common:{name: 'channel'}, native:{}}); - extendObject(id.split('.').slice(0, -1).join('.'), {type: 'channel', common:{name: 'channel'}, native:{}}); + extendObject(id.split('.').slice(0, -2).join('.'), { type: 'channel', common: { name: 'channel' }, native: {} }); + extendObject(id.split('.').slice(0, -1).join('.'), { type: 'channel', common: { name: 'channel' }, native: {} }); createState(id, value, forceCreation, common, callback); } else { setState(id, value, true); } } - + //Determination of page navigation (CustomSend-Payload) function GetNavigationString(pageId: number): string { try { - if (Debug) { log('GetNavigationString Übergabe pageId: ' + pageId, 'info'); } - var navigationString:string = ""; + var navigationString: string = ''; - if (activePage!.subPage){ + if (activePage!.subPage) { //Left icon - if (activePage!.prev == undefined){ - if (activePage!.parentIcon != undefined){ - navigationString = 'button~bUp~' + Icons.GetIcon(activePage!.parentIcon); - if (activePage!.parentIconColor != undefined){ - navigationString += '~' + rgb_dec565(activePage!.parentIconColor); + if (activePage!.prev == undefined) { + if (activePage!.parentIcon != undefined) { + navigationString = 'button~bUp~' + Icons.GetIcon(activePage!.parentIcon); + if (activePage!.parentIconColor != undefined) { + navigationString += '~' + rgb_dec565(activePage!.parentIconColor); } else { navigationString += '~' + rgb_dec565(White); - } + } } else { navigationString = 'button~bUp~' + Icons.GetIcon('arrow-up-bold') + '~' + rgb_dec565(White); } } else { - if (activePage!.prevIcon != undefined){ - navigationString = 'button~bSubPrev~' + Icons.GetIcon(activePage!.prevIcon); - if (activePage!.prevIconColor != undefined){ - navigationString += '~' + rgb_dec565(activePage!.prevIconColor); + if (activePage!.prevIcon != undefined) { + navigationString = 'button~bSubPrev~' + Icons.GetIcon(activePage!.prevIcon); + if (activePage!.prevIconColor != undefined) { + navigationString += '~' + rgb_dec565(activePage!.prevIconColor); } else { navigationString += '~' + rgb_dec565(White); - } + } } else { navigationString = 'button~bSubPrev~' + Icons.GetIcon('arrow-left-bold') + '~' + rgb_dec565(White); - } + } } //Right icon - if (activePage!.next == undefined){ - if (activePage!.homeIcon != undefined){ - navigationString += '~~~button~bHome~' + Icons.GetIcon(activePage!.homeIcon); - if (activePage!.homeIconColor != undefined){ - navigationString += '~' + rgb_dec565(activePage!.homeIconColor) + '~~';; + if (activePage!.next == undefined) { + if (activePage!.homeIcon != undefined) { + navigationString += '~~~button~bHome~' + Icons.GetIcon(activePage!.homeIcon); + if (activePage!.homeIconColor != undefined) { + navigationString += '~' + rgb_dec565(activePage!.homeIconColor) + '~~'; } else { navigationString += '~' + rgb_dec565(White) + '~~'; - } + } } else { - navigationString += '~~~button~bHome~' + Icons.GetIcon('home') + '~' + rgb_dec565(White) + '~~'; + navigationString += '~~~button~bHome~' + Icons.GetIcon('home') + '~' + rgb_dec565(White) + '~~'; } } else { - if (activePage!.nextIcon != undefined){ - navigationString += '~~~button~bSubNext~' + Icons.GetIcon(activePage!.nextIcon); - if (activePage!.nextIconColor != undefined){ - navigationString += '~' + rgb_dec565(activePage!.nextIconColor) + '~~'; + if (activePage!.nextIcon != undefined) { + navigationString += '~~~button~bSubNext~' + Icons.GetIcon(activePage!.nextIcon); + if (activePage!.nextIconColor != undefined) { + navigationString += '~' + rgb_dec565(activePage!.nextIconColor) + '~~'; } else { navigationString += '~' + rgb_dec565(White) + '~~'; - } + } } else { - navigationString += '~~~button~bSubNext~' + Icons.GetIcon('arrow-right-bold') + '~' + rgb_dec565(White) + '~~'; - } + navigationString += '~~~button~bSubNext~' + Icons.GetIcon('arrow-right-bold') + '~' + rgb_dec565(White) + '~~'; + } } - } + } - if (activePage!.subPage && (navigationString != "")){ - return navigationString + if (activePage!.subPage && navigationString != '') { + return navigationString; } switch (pageId) { @@ -7533,39 +8196,38 @@ function GetNavigationString(pageId: number): string { return 'button~bUp~' + Icons.GetIcon('arrow-up-bold') + '~' + rgb_dec565(White) + ' ~~~delete~~~~~'; case -2: return 'button~bUp~' + Icons.GetIcon('arrow-up-bold') + '~' + rgb_dec565(White) + '~~~delete~~~~~'; - default: - { - if (activePage!.prevIcon != undefined){ - navigationString = 'button~bPrev~' + Icons.GetIcon(activePage!.prevIcon); + default: { + if (activePage!.prevIcon != undefined) { + navigationString = 'button~bPrev~' + Icons.GetIcon(activePage!.prevIcon); } else { navigationString = 'button~bPrev~' + Icons.GetIcon('arrow-left-bold'); - } + } - if (activePage!.prevIconColor != undefined){ - navigationString += '~' + rgb_dec565(activePage!.prevIconColor); + if (activePage!.prevIconColor != undefined) { + navigationString += '~' + rgb_dec565(activePage!.prevIconColor); } else { navigationString += '~' + rgb_dec565(White); - } + } - if (activePage!.nextIcon != undefined){ - navigationString += '~~~button~bNext~' + Icons.GetIcon(activePage!.nextIcon); + if (activePage!.nextIcon != undefined) { + navigationString += '~~~button~bNext~' + Icons.GetIcon(activePage!.nextIcon); } else { navigationString += '~~~button~bNext~' + Icons.GetIcon('arrow-right-bold'); - } - if (activePage!.nextIconColor != undefined){ - navigationString += '~' + rgb_dec565(activePage!.nextIconColor) + '~~'; + } + if (activePage!.nextIconColor != undefined) { + navigationString += '~' + rgb_dec565(activePage!.nextIconColor) + '~~'; } else { navigationString += '~' + rgb_dec565(White) + '~~'; } return navigationString; } } - } catch (err: any) { log('error at function GetNavigationString: ' + err.message, 'warn'); } return ''; } + function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOptional | undefined, pageItem: PageItem, placeId: number | undefined): NSPanel.Payload[] { if (Debug) log('GenerateDetailPage Übergabe Type: ' + type + ' - optional: ' + optional + ' - pageItem.id: ' + pageItem.id, 'info'); try { @@ -7573,411 +8235,481 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti let id = pageItem.id; if (id && existsObject(id)) { - const o = getObject(id); - let val: (boolean | number) = 0; + let val: boolean | number = 0; let icon = Icons.GetIcon('lightbulb'); let iconColor = rgb_dec565(config.defaultColor); const role = o.common.role as NSPanel.roles; if (type == 'popupLight') { - let switchVal = '0'; let brightness = 0; switch (role) { - case 'light': - case 'socket': { - if (existsState(id + '.GET')) { - val = getState(id + '.GET').val; - RegisterDetailEntityWatcher(id + '.GET', pageItem, type, placeId); - } else if (existsState(id + '.SET')) { - if(pageItem.monobutton != undefined && pageItem.monobutton == true){ - val = getState(id + ".STATE").val; - RegisterDetailEntityWatcher(id + ".STATE", pageItem, type, placeId); - } - else { - val = getState(id + '.SET').val; - RegisterDetailEntityWatcher(id + '.SET', pageItem, type, placeId); - } - } - - icon = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : role == 'socket' ? Icons.GetIcon('power-socket-de') : Icons.GetIcon('lightbulb'); - - if (val) { - switchVal = '1'; - iconColor = GetIconColor(pageItem, true, true); - } else { - iconColor = GetIconColor(pageItem, false, true); - } - - let effect_supported = 'disable'; - if (pageItem.modeList != undefined) { - effect_supported = 'enable'; - } - - let tempId = placeId != undefined ? placeId : id; - - out_msgs.push({ - payload: 'entityUpdateDetail' + '~' // entityUpdateDetail - + tempId + '~' - + icon + '~' // iconId - + iconColor + '~' // iconColor - + switchVal + '~' // buttonState - + 'disable' + '~' // sliderBrightnessPos - + 'disable' + '~' // sliderColorTempPos - + 'disable' + '~' // colorMode - + '' + '~' // Color identifier - + findLocale('lights', 'Temperature') + '~' // Temperature identifier - + findLocale('lights', 'Brightness') + '~' // Brightness identifier - + effect_supported - }); - } - break; - // Dimmer - case 'dimmer': { - if (existsState(id + '.ON_ACTUAL')) { - val = getState(id + '.ON_ACTUAL').val; - RegisterDetailEntityWatcher(id + '.ON_ACTUAL', pageItem, type, placeId); - } else if (existsState(id + '.ON_SET')) { - val = getState(id + '.ON_SET').val; - RegisterDetailEntityWatcher(id + '.ON_SET', pageItem, type, placeId); - } - - if (val === true) { - iconColor = GetIconColor(pageItem, val, false); - switchVal = '1' - } - - if (existsState(id + '.ACTUAL')) { - if (pageItem.minValueBrightness != undefined && pageItem.maxValueBrightness != undefined) { - brightness = Math.trunc(scale(getState(id + '.ACTUAL').val, pageItem.minValueBrightness, pageItem.maxValueBrightness, 100, 0)); - } else { - brightness = getState(id + '.ACTUAL').val; - } - } else { - log('function GenerateDetailPage role:dimmer -> Alias-Datenpoint: ' + id + '.ACTUAL could not be read', 'warn'); - } - - if (val === true) { - iconColor = GetIconColor(pageItem, brightness, true); - switchVal = '1'; - } else { - iconColor = GetIconColor(pageItem, false, true); - } - - RegisterDetailEntityWatcher(id + '.ACTUAL', pageItem, type, placeId); - - let effect_supported = 'disable'; - if (pageItem.modeList != undefined) { - effect_supported = 'enable'; - } - - let tempId = placeId != undefined ? placeId : id; - - out_msgs.push({ - payload: 'entityUpdateDetail' + '~' //entityUpdateDetail - + tempId + '~' - + icon + '~' //iconId - + iconColor + '~' //iconColor - + switchVal + '~' //buttonState - + brightness + '~' //sliderBrightnessPos - + 'disable' + '~' //sliderColorTempPos - + 'disable' + '~' //colorMod - + '' + '~' //Color-identifier - + findLocale('lights', 'Temperature') + '~' //Temperature-identifier - + findLocale('lights', 'Brightness') + '~' //Brightness-identifier - + effect_supported - }); - } - break; - // HUE-Licht - case 'hue': { - - if (existsState(id + '.ON_ACTUAL')) { - val = getState(id + '.ON_ACTUAL').val; - RegisterDetailEntityWatcher(id + '.ON_ACTUAL', pageItem, type, placeId); - } - - if (existsState(id + '.DIMMER')) { - if (pageItem.minValueBrightness != undefined && pageItem.maxValueBrightness != undefined) { - brightness = Math.trunc(scale(getState(id + '.DIMMER').val, pageItem.minValueBrightness, pageItem.maxValueBrightness, 100, 0)); - } else { - brightness = getState(id + '.DIMMER').val; - } - RegisterDetailEntityWatcher(id + '.DIMMER', pageItem, type, placeId); - } else { - log('function GenerateDetailPage role:hue -> Alias-Datenpunkt: ' + id + '.DIMMER could not be read', 'warn'); - } - - if (val === true) { - iconColor = GetIconColor(pageItem, brightness, true); - switchVal = '1'; - } else { - iconColor = GetIconColor(pageItem, false, true); - } - - let colorMode = 'disable'; - if (existsState(id + '.HUE')) { - if (getState(id + '.HUE').val != null) { - colorMode = 'enable'; - let huecolor = hsv2rgb(getState(id + '.HUE').val, 1, 1); - let rgb: RGB = { red: Math.round(huecolor[0]), green: Math.round(huecolor[1]), blue: Math.round(huecolor[2]) } - iconColor = rgb_dec565(pageItem.interpolateColor !== undefined ? rgb : config.defaultOnColor); - } - } - let colorTemp: any; - if (existsState(id + '.TEMPERATURE')) { - colorTemp = 0; - if (getState(id + '.TEMPERATURE').val != null) { - if (pageItem.minValueColorTemp !== undefined && pageItem.maxValueColorTemp !== undefined) { - colorTemp = Math.trunc(scale(getState(id + '.TEMPERATURE').val, pageItem.minValueColorTemp, pageItem.maxValueColorTemp, 100, 0)); - } else { - colorTemp = getState(id + '.TEMPERATURE').val; + case 'light': + case 'socket': + { + if (existsState(id + '.GET')) { + val = getState(id + '.GET').val; + RegisterDetailEntityWatcher(id + '.GET', pageItem, type, placeId); + } else if (existsState(id + '.SET')) { + if (pageItem.monobutton != undefined && pageItem.monobutton == true) { + val = getState(id + '.STATE').val; + RegisterDetailEntityWatcher(id + '.STATE', pageItem, type, placeId); + } else { + val = getState(id + '.SET').val; + RegisterDetailEntityWatcher(id + '.SET', pageItem, type, placeId); + } } - } - } else { - colorTemp = 'disable'; - } - let effect_supported = 'disable'; - if (pageItem.modeList != undefined) { - effect_supported = 'enable'; - } + icon = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : role == 'socket' ? Icons.GetIcon('power-socket-de') : Icons.GetIcon('lightbulb'); - let tempId = placeId != undefined ? placeId : id; - - out_msgs.push({ - payload: 'entityUpdateDetail' + '~' //entityUpdateDetail - + tempId + '~' - + icon + '~' //iconId - + iconColor + '~' //iconColor - + switchVal + '~' //buttonState - + brightness + '~' //sliderBrightnessPos - + colorTemp + '~' //sliderColorTempPos - + colorMode + '~' //colorMode (if hue-alias without hue-datapoint, then disable) - + 'Color' + '~' //Color-identifier - + findLocale('lights', 'Temperature') + '~' //Temperature-identifier - + findLocale('lights', 'Brightness') + '~' //Brightness-identifier - + effect_supported - }); - } - break; - // RGB-Licht - case 'rgb': { - - if (existsState(id + '.ON_ACTUAL')) { - val = getState(id + '.ON_ACTUAL').val; - RegisterDetailEntityWatcher(id + '.ON_ACTUAL', pageItem, type, placeId); - } - - if (existsState(id + '.DIMMER')) { - if (pageItem.minValueBrightness != undefined && pageItem.maxValueBrightness != undefined) { - brightness = Math.trunc(scale(getState(id + '.DIMMER').val, pageItem.minValueBrightness, pageItem.maxValueBrightness, 100, 0)); - } else { - brightness = getState(id + '.DIMMER').val; - } - RegisterDetailEntityWatcher(id + '.DIMMER', pageItem, type, placeId); - } else { - log('function GenerateDetailPage role:rgb -> Alias-Datenpunkt: ' + id + '.DIMMER could not be read', 'warn'); - } - - if (val === true) { - iconColor = GetIconColor(pageItem, brightness, true); - switchVal = '1'; - } else { - iconColor = GetIconColor(pageItem, false, true); - } - - let colorMode = 'disable'; - if (existsState(id + '.RED') && existsState(id + '.GREEN') && existsState(id + '.BLUE')) { - if (getState(id + '.RED').val != null && getState(id + '.GREEN').val != null && getState(id + '.BLUE').val != null) { - colorMode = 'enable'; - let rgb: RGB = { red: Math.round(getState(id + '.RED').val), green: Math.round(getState(id + '.GREEN').val), blue: Math.round(getState(id + '.BLUE').val) } - iconColor = rgb_dec565(pageItem.interpolateColor !== undefined ? rgb : config.defaultOnColor); - } - } - let colorTemp: any; - if (existsState(id + '.TEMPERATURE')) { - colorTemp = 0; - if (getState(id + '.TEMPERATURE').val != null) { - if (pageItem.minValueColorTemp !== undefined && pageItem.maxValueColorTemp !== undefined) { - colorTemp = Math.trunc(scale(getState(id + '.TEMPERATURE').val, pageItem.minValueColorTemp, pageItem.maxValueColorTemp!, 100, 0)); + if (val) { + switchVal = '1'; + iconColor = GetIconColor(pageItem, true, true); } else { - colorTemp = getState(id + '.TEMPERATURE').val; + iconColor = GetIconColor(pageItem, false, true); } + + let effect_supported = 'disable'; + if (pageItem.modeList != undefined) { + effect_supported = 'enable'; + } + + let tempId = placeId != undefined ? placeId : id; + + out_msgs.push({ + payload: + 'entityUpdateDetail' + + '~' + // entityUpdateDetail + tempId + + '~' + + icon + + '~' + // iconId + iconColor + + '~' + // iconColor + switchVal + + '~' + // buttonState + 'disable' + + '~' + // sliderBrightnessPos + 'disable' + + '~' + // sliderColorTempPos + 'disable' + + '~' + // colorMode + '' + + '~' + // Color identifier + findLocale('lights', 'Temperature') + + '~' + // Temperature identifier + findLocale('lights', 'Brightness') + + '~' + // Brightness identifier + effect_supported, + }); } - } else { - colorTemp = 'disable'; - } + break; + // Dimmer + case 'dimmer': + { + if (existsState(id + '.ON_ACTUAL')) { + val = getState(id + '.ON_ACTUAL').val; + RegisterDetailEntityWatcher(id + '.ON_ACTUAL', pageItem, type, placeId); + } else if (existsState(id + '.ON_SET')) { + val = getState(id + '.ON_SET').val; + RegisterDetailEntityWatcher(id + '.ON_SET', pageItem, type, placeId); + } - let effect_supported = 'disable'; - if (pageItem.modeList != undefined) { - effect_supported = 'enable'; - } + if (val === true) { + iconColor = GetIconColor(pageItem, val, false); + switchVal = '1'; + } - let tempId = placeId != undefined ? placeId : id; - - out_msgs.push({ - payload: 'entityUpdateDetail' + '~' //entityUpdateDetail - + tempId + '~' - + icon + '~' //iconId - + iconColor + '~' //iconColor - + switchVal + '~' //buttonState - + brightness + '~' //sliderBrightnessPos - + colorTemp + '~' //sliderColorTempPos - + colorMode + '~' //colorMode (if hue-alias without hue-datapoint, then disable) - + 'Color' + '~' //Color-identifier - + findLocale('lights', 'Temperature') + '~' //Temperature-identifier - + findLocale('lights', 'Brightness') + '~' //Brightness-identifier - + effect_supported - }); - } - break; - // RGB-Licht-einzeln (HEX) - case 'rgbSingle': { - - if (existsState(id + '.ON_ACTUAL')) { - val = getState(id + '.ON_ACTUAL').val; - RegisterDetailEntityWatcher(id + '.ON_ACTUAL', pageItem, type, placeId); - } - - if (existsState(id + '.DIMMER')) { - if (pageItem.minValueBrightness != undefined && pageItem.maxValueBrightness != undefined) { - brightness = Math.trunc(scale(getState(id + '.DIMMER').val, pageItem.minValueBrightness, pageItem.maxValueBrightness, 100, 0)); - } else { - brightness = getState(id + '.DIMMER').val; - } - RegisterDetailEntityWatcher(id + '.DIMMER', pageItem, type, placeId); - } else { - log('function GenerateDetailPage role:rgbSingle -> Alias-Datenpunkt: ' + id + '.DIMMER could not be read', 'warn'); - } - - if (val === true) { - iconColor = GetIconColor(pageItem, brightness, true); - switchVal = '1'; - } else { - iconColor = GetIconColor(pageItem, false, true); - } - - let colorMode = 'disable'; - if (existsState(id + '.RGB')) { - if (getState(id + '.RGB').val != null) { - colorMode = 'enable'; - let hex = getState(id + '.RGB').val; - let hexRed = parseInt(hex[1] + hex[2], 16); - let hexGreen = parseInt(hex[3] + hex[4], 16); - let hexBlue = parseInt(hex[5] + hex[6], 16); - let rgb: RGB = { red: Math.round(hexRed), green: Math.round(hexGreen), blue: Math.round(hexBlue) } - iconColor = rgb_dec565(pageItem.interpolateColor !== undefined ? rgb : config.defaultOnColor); - } - } - - let colorTemp:any; - if (existsState(id + '.TEMPERATURE')) { - colorTemp = 0; - if (getState(id + '.TEMPERATURE').val != null) { - if (pageItem.minValueColorTemp !== undefined && pageItem.maxValueColorTemp !== undefined) { - colorTemp = Math.trunc(scale(getState(id + '.TEMPERATURE').val, pageItem.minValueColorTemp, pageItem.maxValueColorTemp, 100, 0)); + if (existsState(id + '.ACTUAL')) { + if (pageItem.minValueBrightness != undefined && pageItem.maxValueBrightness != undefined) { + brightness = Math.trunc(scale(getState(id + '.ACTUAL').val, pageItem.minValueBrightness, pageItem.maxValueBrightness, 100, 0)); + } else { + brightness = getState(id + '.ACTUAL').val; + } } else { - colorTemp = getState(id + '.TEMPERATURE').val; + log('function GenerateDetailPage role:dimmer -> Alias-Datenpoint: ' + id + '.ACTUAL could not be read', 'warn'); } - } - } else { - colorTemp = 'disable'; - } - let effect_supported = 'disable'; - if (pageItem.modeList != undefined) { - effect_supported = 'enable'; - } - - let tempId = placeId != undefined ? placeId : id; - - out_msgs.push({ - payload: 'entityUpdateDetail' + '~' //entityUpdateDetail - + tempId + '~' - + icon + '~' //iconId - + iconColor + '~' //iconColor - + switchVal + '~' //buttonState - + brightness + '~' //sliderBrightnessPos - + colorTemp + '~' //sliderColorTempPos - + colorMode + '~' //colorMode (if hue-alias without hue-datapoint, then disable) - + 'Color' + '~' //Color-identifier - + findLocale('lights', 'Temperature') + '~' //Temperature-identifier - + findLocale('lights', 'Brightness') + '~' //Brightness-identifier - + effect_supported - }); - } - break; - // Farbtemperatur (CT) - case 'ct': { - - if (existsState(id + '.ON')) { - val = getState(id + '.ON').val; - RegisterDetailEntityWatcher(id + '.ON', pageItem, type, placeId); - } - - if (existsState(id + '.DIMMER')) { - if (pageItem.minValueBrightness != undefined && pageItem.maxValueBrightness != undefined) { - brightness = Math.trunc(scale(getState(id + '.DIMMER').val, pageItem.minValueBrightness, pageItem.maxValueBrightness, 100, 0)); - } else { - brightness = getState(id + '.DIMMER').val; - } - RegisterDetailEntityWatcher(id + '.DIMMER', pageItem, type, placeId); - } else { - log('function GenerateDetailPage role:ct -> Alias-Datenpunkt: ' + id + '.DIMMER could not be read', 'warn'); - } - - if (val === true) { - iconColor = GetIconColor(pageItem, brightness, true); - switchVal = '1'; - } else { - iconColor = GetIconColor(pageItem, false, true); - } - - let colorMode = 'disable'; - - let colorTemp = 0; - if (existsState(id + '.TEMPERATURE')) { - if (getState(id + '.TEMPERATURE').val != null) { - if (pageItem.minValueColorTemp !== undefined && pageItem.maxValueColorTemp !== undefined) { - colorTemp = Math.trunc(scale(getState(id + '.TEMPERATURE').val, pageItem.minValueColorTemp, pageItem.maxValueColorTemp, 100, 0)); + if (val === true) { + iconColor = GetIconColor(pageItem, brightness, true); + switchVal = '1'; } else { - colorTemp = getState(id + '.TEMPERATURE').val; + iconColor = GetIconColor(pageItem, false, true); } + + RegisterDetailEntityWatcher(id + '.ACTUAL', pageItem, type, placeId); + + let effect_supported = 'disable'; + if (pageItem.modeList != undefined) { + effect_supported = 'enable'; + } + + let tempId = placeId != undefined ? placeId : id; + + out_msgs.push({ + payload: + 'entityUpdateDetail' + + '~' + //entityUpdateDetail + tempId + + '~' + + icon + + '~' + //iconId + iconColor + + '~' + //iconColor + switchVal + + '~' + //buttonState + brightness + + '~' + //sliderBrightnessPos + 'disable' + + '~' + //sliderColorTempPos + 'disable' + + '~' + //colorMod + '' + + '~' + //Color-identifier + findLocale('lights', 'Temperature') + + '~' + //Temperature-identifier + findLocale('lights', 'Brightness') + + '~' + //Brightness-identifier + effect_supported, + }); } - } else { - log('function GenerateDetailPage role:ct -> Alias-Datenpunkt: ' + id + '.TEMPERATURE could not be read', 'warn'); - } + break; + // HUE-Licht + case 'hue': + { + if (existsState(id + '.ON_ACTUAL')) { + val = getState(id + '.ON_ACTUAL').val; + RegisterDetailEntityWatcher(id + '.ON_ACTUAL', pageItem, type, placeId); + } - let effect_supported = 'disable'; - if (pageItem.modeList != undefined) { - effect_supported = 'enable'; - } + if (existsState(id + '.DIMMER')) { + if (pageItem.minValueBrightness != undefined && pageItem.maxValueBrightness != undefined) { + brightness = Math.trunc(scale(getState(id + '.DIMMER').val, pageItem.minValueBrightness, pageItem.maxValueBrightness, 100, 0)); + } else { + brightness = getState(id + '.DIMMER').val; + } + RegisterDetailEntityWatcher(id + '.DIMMER', pageItem, type, placeId); + } else { + log('function GenerateDetailPage role:hue -> Alias-Datenpunkt: ' + id + '.DIMMER could not be read', 'warn'); + } - let tempId = placeId != undefined ? placeId : id; - - out_msgs.push({ - payload: 'entityUpdateDetail' + '~' //entityUpdateDetail - + tempId + '~' - + icon + '~' //iconId - + iconColor + '~' //iconColor - + switchVal + '~' //buttonState - + brightness + '~' //sliderBrightnessPos - + colorTemp + '~' //sliderColorTempPos - + colorMode + '~' //colorMode (if hue-alias without hue-datapoint, then disable) - + 'Color' + '~' //Color-identifier - + findLocale('lights', 'Temperature') + '~' //Temperature-identifier - + findLocale('lights', 'Brightness') + '~' //Brightness-identifier - + effect_supported - }); - } - break; + if (val === true) { + iconColor = GetIconColor(pageItem, brightness, true); + switchVal = '1'; + } else { + iconColor = GetIconColor(pageItem, false, true); + } + + let colorMode = 'disable'; + if (existsState(id + '.HUE')) { + if (getState(id + '.HUE').val != null) { + colorMode = 'enable'; + let huecolor = hsv2rgb(getState(id + '.HUE').val, 1, 1); + let rgb: RGB = { red: Math.round(huecolor[0]), green: Math.round(huecolor[1]), blue: Math.round(huecolor[2]) }; + iconColor = rgb_dec565(pageItem.interpolateColor !== undefined ? rgb : config.defaultOnColor); + } + } + let colorTemp: any; + if (existsState(id + '.TEMPERATURE')) { + colorTemp = 0; + if (getState(id + '.TEMPERATURE').val != null) { + if (pageItem.minValueColorTemp !== undefined && pageItem.maxValueColorTemp !== undefined) { + colorTemp = Math.trunc(scale(getState(id + '.TEMPERATURE').val, pageItem.minValueColorTemp, pageItem.maxValueColorTemp, 100, 0)); + } else { + colorTemp = getState(id + '.TEMPERATURE').val; + } + } + } else { + colorTemp = 'disable'; + } + + let effect_supported = 'disable'; + if (pageItem.modeList != undefined) { + effect_supported = 'enable'; + } + + let tempId = placeId != undefined ? placeId : id; + + out_msgs.push({ + payload: + 'entityUpdateDetail' + + '~' + //entityUpdateDetail + tempId + + '~' + + icon + + '~' + //iconId + iconColor + + '~' + //iconColor + switchVal + + '~' + //buttonState + brightness + + '~' + //sliderBrightnessPos + colorTemp + + '~' + //sliderColorTempPos + colorMode + + '~' + //colorMode (if hue-alias without hue-datapoint, then disable) + 'Color' + + '~' + //Color-identifier + findLocale('lights', 'Temperature') + + '~' + //Temperature-identifier + findLocale('lights', 'Brightness') + + '~' + //Brightness-identifier + effect_supported, + }); + } + break; + // RGB-Licht + case 'rgb': + { + if (existsState(id + '.ON_ACTUAL')) { + val = getState(id + '.ON_ACTUAL').val; + RegisterDetailEntityWatcher(id + '.ON_ACTUAL', pageItem, type, placeId); + } + + if (existsState(id + '.DIMMER')) { + if (pageItem.minValueBrightness != undefined && pageItem.maxValueBrightness != undefined) { + brightness = Math.trunc(scale(getState(id + '.DIMMER').val, pageItem.minValueBrightness, pageItem.maxValueBrightness, 100, 0)); + } else { + brightness = getState(id + '.DIMMER').val; + } + RegisterDetailEntityWatcher(id + '.DIMMER', pageItem, type, placeId); + } else { + log('function GenerateDetailPage role:rgb -> Alias-Datenpunkt: ' + id + '.DIMMER could not be read', 'warn'); + } + + if (val === true) { + iconColor = GetIconColor(pageItem, brightness, true); + switchVal = '1'; + } else { + iconColor = GetIconColor(pageItem, false, true); + } + + let colorMode = 'disable'; + if (existsState(id + '.RED') && existsState(id + '.GREEN') && existsState(id + '.BLUE')) { + if (getState(id + '.RED').val != null && getState(id + '.GREEN').val != null && getState(id + '.BLUE').val != null) { + colorMode = 'enable'; + let rgb: RGB = { red: Math.round(getState(id + '.RED').val), green: Math.round(getState(id + '.GREEN').val), blue: Math.round(getState(id + '.BLUE').val) }; + iconColor = rgb_dec565(pageItem.interpolateColor !== undefined ? rgb : config.defaultOnColor); + } + } + let colorTemp: any; + if (existsState(id + '.TEMPERATURE')) { + colorTemp = 0; + if (getState(id + '.TEMPERATURE').val != null) { + if (pageItem.minValueColorTemp !== undefined && pageItem.maxValueColorTemp !== undefined) { + colorTemp = Math.trunc(scale(getState(id + '.TEMPERATURE').val, pageItem.minValueColorTemp, pageItem.maxValueColorTemp!, 100, 0)); + } else { + colorTemp = getState(id + '.TEMPERATURE').val; + } + } + } else { + colorTemp = 'disable'; + } + + let effect_supported = 'disable'; + if (pageItem.modeList != undefined) { + effect_supported = 'enable'; + } + + let tempId = placeId != undefined ? placeId : id; + + out_msgs.push({ + payload: + 'entityUpdateDetail' + + '~' + //entityUpdateDetail + tempId + + '~' + + icon + + '~' + //iconId + iconColor + + '~' + //iconColor + switchVal + + '~' + //buttonState + brightness + + '~' + //sliderBrightnessPos + colorTemp + + '~' + //sliderColorTempPos + colorMode + + '~' + //colorMode (if hue-alias without hue-datapoint, then disable) + 'Color' + + '~' + //Color-identifier + findLocale('lights', 'Temperature') + + '~' + //Temperature-identifier + findLocale('lights', 'Brightness') + + '~' + //Brightness-identifier + effect_supported, + }); + } + break; + // RGB-Licht-einzeln (HEX) + case 'rgbSingle': + { + if (existsState(id + '.ON_ACTUAL')) { + val = getState(id + '.ON_ACTUAL').val; + RegisterDetailEntityWatcher(id + '.ON_ACTUAL', pageItem, type, placeId); + } + + if (existsState(id + '.DIMMER')) { + if (pageItem.minValueBrightness != undefined && pageItem.maxValueBrightness != undefined) { + brightness = Math.trunc(scale(getState(id + '.DIMMER').val, pageItem.minValueBrightness, pageItem.maxValueBrightness, 100, 0)); + } else { + brightness = getState(id + '.DIMMER').val; + } + RegisterDetailEntityWatcher(id + '.DIMMER', pageItem, type, placeId); + } else { + log('function GenerateDetailPage role:rgbSingle -> Alias-Datenpunkt: ' + id + '.DIMMER could not be read', 'warn'); + } + + if (val === true) { + iconColor = GetIconColor(pageItem, brightness, true); + switchVal = '1'; + } else { + iconColor = GetIconColor(pageItem, false, true); + } + + let colorMode = 'disable'; + if (existsState(id + '.RGB')) { + if (getState(id + '.RGB').val != null) { + colorMode = 'enable'; + let hex = getState(id + '.RGB').val; + let hexRed = parseInt(hex[1] + hex[2], 16); + let hexGreen = parseInt(hex[3] + hex[4], 16); + let hexBlue = parseInt(hex[5] + hex[6], 16); + let rgb: RGB = { red: Math.round(hexRed), green: Math.round(hexGreen), blue: Math.round(hexBlue) }; + iconColor = rgb_dec565(pageItem.interpolateColor !== undefined ? rgb : config.defaultOnColor); + } + } + + let colorTemp: any; + if (existsState(id + '.TEMPERATURE')) { + colorTemp = 0; + if (getState(id + '.TEMPERATURE').val != null) { + if (pageItem.minValueColorTemp !== undefined && pageItem.maxValueColorTemp !== undefined) { + colorTemp = Math.trunc(scale(getState(id + '.TEMPERATURE').val, pageItem.minValueColorTemp, pageItem.maxValueColorTemp, 100, 0)); + } else { + colorTemp = getState(id + '.TEMPERATURE').val; + } + } + } else { + colorTemp = 'disable'; + } + + let effect_supported = 'disable'; + if (pageItem.modeList != undefined) { + effect_supported = 'enable'; + } + + let tempId = placeId != undefined ? placeId : id; + + out_msgs.push({ + payload: + 'entityUpdateDetail' + + '~' + //entityUpdateDetail + tempId + + '~' + + icon + + '~' + //iconId + iconColor + + '~' + //iconColor + switchVal + + '~' + //buttonState + brightness + + '~' + //sliderBrightnessPos + colorTemp + + '~' + //sliderColorTempPos + colorMode + + '~' + //colorMode (if hue-alias without hue-datapoint, then disable) + 'Color' + + '~' + //Color-identifier + findLocale('lights', 'Temperature') + + '~' + //Temperature-identifier + findLocale('lights', 'Brightness') + + '~' + //Brightness-identifier + effect_supported, + }); + } + break; + // Farbtemperatur (CT) + case 'ct': + { + if (existsState(id + '.ON')) { + val = getState(id + '.ON').val; + RegisterDetailEntityWatcher(id + '.ON', pageItem, type, placeId); + } + + if (existsState(id + '.DIMMER')) { + if (pageItem.minValueBrightness != undefined && pageItem.maxValueBrightness != undefined) { + brightness = Math.trunc(scale(getState(id + '.DIMMER').val, pageItem.minValueBrightness, pageItem.maxValueBrightness, 100, 0)); + } else { + brightness = getState(id + '.DIMMER').val; + } + RegisterDetailEntityWatcher(id + '.DIMMER', pageItem, type, placeId); + } else { + log('function GenerateDetailPage role:ct -> Alias-Datenpunkt: ' + id + '.DIMMER could not be read', 'warn'); + } + + if (val === true) { + iconColor = GetIconColor(pageItem, brightness, true); + switchVal = '1'; + } else { + iconColor = GetIconColor(pageItem, false, true); + } + + let colorMode = 'disable'; + + let colorTemp = 0; + if (existsState(id + '.TEMPERATURE')) { + if (getState(id + '.TEMPERATURE').val != null) { + if (pageItem.minValueColorTemp !== undefined && pageItem.maxValueColorTemp !== undefined) { + colorTemp = Math.trunc(scale(getState(id + '.TEMPERATURE').val, pageItem.minValueColorTemp, pageItem.maxValueColorTemp, 100, 0)); + } else { + colorTemp = getState(id + '.TEMPERATURE').val; + } + } + } else { + log('function GenerateDetailPage role:ct -> Alias-Datenpunkt: ' + id + '.TEMPERATURE could not be read', 'warn'); + } + + let effect_supported = 'disable'; + if (pageItem.modeList != undefined) { + effect_supported = 'enable'; + } + + let tempId = placeId != undefined ? placeId : id; + + out_msgs.push({ + payload: + 'entityUpdateDetail' + + '~' + //entityUpdateDetail + tempId + + '~' + + icon + + '~' + //iconId + iconColor + + '~' + //iconColor + switchVal + + '~' + //buttonState + brightness + + '~' + //sliderBrightnessPos + colorTemp + + '~' + //sliderColorTempPos + colorMode + + '~' + //colorMode (if hue-alias without hue-datapoint, then disable) + 'Color' + + '~' + //Color-identifier + findLocale('lights', 'Temperature') + + '~' + //Temperature-identifier + findLocale('lights', 'Brightness') + + '~' + //Brightness-identifier + effect_supported, + }); + } + break; } } if (type == 'popupShutter') { - icon = pageItem.icon !== undefined ? Icons.GetIcon(pageItem.icon) : Icons.GetIcon('window-open'); if (existsState(id + '.ACTUAL')) { val = getState(id + '.ACTUAL').val; @@ -7986,7 +8718,7 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti val = getState(id + '.SET').val; //RegisterDetailEntityWatcher(id + '.SET', pageItem, type); } - let tilt_position: any = 'disabled' + let tilt_position: any = 'disabled'; if (existsState(id + '.TILT_ACTUAL')) { tilt_position = getState(id + '.TILT_ACTUAL').val; RegisterDetailEntityWatcher(id + '.TILT_ACTUAL', pageItem, type, placeId); @@ -7994,7 +8726,7 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti tilt_position = getState(id + '.TILT_SET').val; //RegisterDetailEntityWatcher(id + '.TILT_SET', pageItem, type); } - + let min_Level: number = 0; let max_Level: number = 100; if (pageItem.minValueLevel !== undefined && pageItem.maxValueLevel !== undefined) { @@ -8002,24 +8734,24 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti max_Level = pageItem.maxValueLevel; val = Math.trunc(scale(getState(id + '.ACTUAL').val, pageItem.minValueLevel, pageItem.maxValueLevel, 100, 0)); } - let min_Tilt: number = 0; - let max_Tilt: number = 100; + let min_Tilt: number = 0; + let max_Tilt: number = 100; if (pageItem.minValueTilt !== undefined && pageItem.maxValueTilt !== undefined) { min_Tilt = pageItem.minValueTilt; max_Tilt = pageItem.maxValueTilt; tilt_position = Math.trunc(scale(getState(id + '.TILT_ACTUAL').val, pageItem.minValueTilt, pageItem.maxValueTilt, 100, 0)); } - if (Debug) log('minLevel '+ min_Level + ' maxLevel ' + max_Level + ' Level ' + val, 'info'); - if (Debug) log('minTilt '+ min_Tilt + ' maxTilt ' + max_Tilt + ' TiltPosition ' + tilt_position, 'info'); + if (Debug) log('minLevel ' + min_Level + ' maxLevel ' + max_Level + ' Level ' + val, 'info'); + if (Debug) log('minTilt ' + min_Tilt + ' maxTilt ' + max_Tilt + ' TiltPosition ' + tilt_position, 'info'); let textSecondRow = ''; let icon_id = icon; let icon_up = Icons.GetIcon('arrow-up'); let icon_stop = Icons.GetIcon('stop'); let icon_down = Icons.GetIcon('arrow-down'); - let tempVal: number = getState(pageItem.id + '.ACTUAL').val - + let tempVal: number = getState(pageItem.id + '.ACTUAL').val; + //Disabled Status while bug in updating origin adapter data points of lift values let icon_up_status = 'enable'; //let icon_up_status = tempVal === min_Level ? 'disable' : 'enable'; @@ -8055,77 +8787,115 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti } let tempId = placeId != undefined ? placeId : id; - + out_msgs.push({ - payload: 'entityUpdateDetail' + '~' //entityUpdateDetail - + tempId + '~' //entity_id - + val + '~' //Shutterposition - + textSecondRow + '~' //pos_status 2.line - + findLocale('blinds', 'Position') + '~' //pos_translation - + icon_id + '~' //{icon_id}~ - + icon_up + '~' //{icon_up}~ - + icon_stop + '~' //{icon_stop}~ - + icon_down + '~' //{icon_down}~ - + icon_up_status + '~' //{icon_up_status}~ - + icon_stop_status + '~' //{icon_stop_status}~ - + icon_down_status + '~' //{icon_down_status}~ - + textTilt + '~' //{textTilt}~ - + iconTiltLeft + '~' //{iconTiltLeft}~ - + iconTiltStop + '~' //{iconTiltStop}~ - + iconTiltRight + '~' //{iconTiltRight}~ - + iconTiltLeftStatus + '~' //{iconTiltLeftStatus}~ - + iconTiltStopStatus + '~' //{iconTiltStopStatus}~ - + iconTiltRightStatus + '~' //{iconTiltRightStatus}~ - + tilt_pos //{tilt_pos}") + payload: + 'entityUpdateDetail' + + '~' + //entityUpdateDetail + tempId + + '~' + //entity_id + val + + '~' + //Shutterposition + textSecondRow + + '~' + //pos_status 2.line + findLocale('blinds', 'Position') + + '~' + //pos_translation + icon_id + + '~' + //{icon_id}~ + icon_up + + '~' + //{icon_up}~ + icon_stop + + '~' + //{icon_stop}~ + icon_down + + '~' + //{icon_down}~ + icon_up_status + + '~' + //{icon_up_status}~ + icon_stop_status + + '~' + //{icon_stop_status}~ + icon_down_status + + '~' + //{icon_down_status}~ + textTilt + + '~' + //{textTilt}~ + iconTiltLeft + + '~' + //{iconTiltLeft}~ + iconTiltStop + + '~' + //{iconTiltStop}~ + iconTiltRight + + '~' + //{iconTiltRight}~ + iconTiltLeftStatus + + '~' + //{iconTiltLeftStatus}~ + iconTiltStopStatus + + '~' + //{iconTiltStopStatus}~ + iconTiltRightStatus + + '~' + //{iconTiltRightStatus}~ + tilt_pos, //{tilt_pos}") }); } if (type == 'popupThermo') { - let vIcon = (pageItem.icon != undefined) ? pageItem.icon : 'fan'; - let mode1 = (isPageThermoItem(pageItem) && pageItem.popupThermoMode1 != undefined) ? pageItem.popupThermoMode1.join('?') : ''; - let mode2 = (isPageThermoItem(pageItem) && pageItem.popupThermoMode2 != undefined) ? pageItem.popupThermoMode2.join('?') : ''; - let mode3 = (isPageThermoItem(pageItem) && pageItem.popupThermoMode3 != undefined) ? pageItem.popupThermoMode3.join('?') : ''; + let vIcon = pageItem.icon != undefined ? pageItem.icon : 'fan'; + let mode1 = isPageThermoItem(pageItem) && pageItem.popupThermoMode1 != undefined ? pageItem.popupThermoMode1.join('?') : ''; + let mode2 = isPageThermoItem(pageItem) && pageItem.popupThermoMode2 != undefined ? pageItem.popupThermoMode2.join('?') : ''; + let mode3 = isPageThermoItem(pageItem) && pageItem.popupThermoMode3 != undefined ? pageItem.popupThermoMode3.join('?') : ''; - let payloadParameters1 = '~~~~' + let payloadParameters1 = '~~~~'; if (isPageThermoItem(pageItem) && pageItem.popupThermoMode1 != undefined) { - RegisterDetailEntityWatcher(pageItem.id + "." + pageItem.setThermoAlias![0], pageItem, type, placeId); - payloadParameters1 = pageItem.popUpThermoName![0] + '~' //{heading}~ Mode 1 - + 'modus1' + '~' //{id}~ Mode 1 - + getState(pageItem.id + "." + pageItem.setThermoAlias![0]).val + '~' //{ACTUAL}~ Mode 1 - + mode1 + '~'; //{possible values} Mode 1 (1-n) + RegisterDetailEntityWatcher(pageItem.id + '.' + pageItem.setThermoAlias![0], pageItem, type, placeId); + payloadParameters1 = + pageItem.popUpThermoName![0] + + '~' + //{heading}~ Mode 1 + 'modus1' + + '~' + //{id}~ Mode 1 + getState(pageItem.id + '.' + pageItem.setThermoAlias![0]).val + + '~' + //{ACTUAL}~ Mode 1 + mode1 + + '~'; //{possible values} Mode 1 (1-n) } - let payloadParameters2 = '~~~~' + let payloadParameters2 = '~~~~'; if (isPageThermoItem(pageItem) && pageItem.popupThermoMode2 != undefined) { - RegisterDetailEntityWatcher(pageItem.id + "." + pageItem.setThermoAlias![1], pageItem, type, placeId); - payloadParameters2 = pageItem.popUpThermoName![1] + '~' //{heading}~ Mode 2 - + 'modus2' + '~' //{id}~ Mode 2 - + getState(pageItem.id + "." + pageItem.setThermoAlias![1]).val + '~' //{ACTUAL}~ Mode 2 - + mode2 + '~'; //{possible values} + RegisterDetailEntityWatcher(pageItem.id + '.' + pageItem.setThermoAlias![1], pageItem, type, placeId); + payloadParameters2 = + pageItem.popUpThermoName![1] + + '~' + //{heading}~ Mode 2 + 'modus2' + + '~' + //{id}~ Mode 2 + getState(pageItem.id + '.' + pageItem.setThermoAlias![1]).val + + '~' + //{ACTUAL}~ Mode 2 + mode2 + + '~'; //{possible values} } - let payloadParameters3 = '~~~~' + let payloadParameters3 = '~~~~'; if (isPageThermoItem(pageItem) && pageItem.popupThermoMode3 != undefined) { - RegisterDetailEntityWatcher(pageItem.id + "." + pageItem.setThermoAlias![2], pageItem, type, placeId); - payloadParameters3 = pageItem.popUpThermoName![2] + '~' //{heading}~ Mode 3 - + 'modus3' + '~' //{id}~ Mode 3 - + getState(pageItem.id + "." + pageItem.setThermoAlias![2]).val + '~' //{ACTUAL}~ Mode 3 - + mode3; //{possible values} Mode 3 (1-n) + RegisterDetailEntityWatcher(pageItem.id + '.' + pageItem.setThermoAlias![2], pageItem, type, placeId); + payloadParameters3 = + pageItem.popUpThermoName![2] + + '~' + //{heading}~ Mode 3 + 'modus3' + + '~' + //{id}~ Mode 3 + getState(pageItem.id + '.' + pageItem.setThermoAlias![2]).val + + '~' + //{ACTUAL}~ Mode 3 + mode3; //{possible values} Mode 3 (1-n) } out_msgs.push({ - payload: 'entityUpdateDetail' + '~' //entityUpdateDetail - + id + '~' //{entity_id} - + Icons.GetIcon(vIcon) + '~' //{icon_id}~ - + 11487 + '~' //{icon_color}~ - + payloadParameters1 - + payloadParameters2 - + payloadParameters3 + payload: + 'entityUpdateDetail' + + '~' + //entityUpdateDetail + id + + '~' + //{entity_id} + Icons.GetIcon(vIcon) + + '~' + //{icon_id}~ + 11487 + + '~' + //{icon_color}~ + payloadParameters1 + + payloadParameters2 + + payloadParameters3, }); } if (type == 'popupTimer') { - let timer_actual: number = 0; if (existsState(id + '.ACTUAL')) { @@ -8194,25 +8964,37 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti let tempId = placeId != undefined ? placeId : id; out_msgs.push({ - payload: 'entityUpdateDetail' + '~' //entityUpdateDetail - + tempId + '~~' //{entity_id} - + rgb_dec565(White) + '~' //{icon_color}~ - + tempId + '~' - + min_remaining + '~' - + sec_remaining + '~' - + editable + '~' - + action1 + '~' - + action2 + '~' - + action3 + '~' - + label1 + '~' - + label2 + '~' - + label3 + payload: + 'entityUpdateDetail' + + '~' + //entityUpdateDetail + tempId + + '~~' + //{entity_id} + rgb_dec565(White) + + '~' + //{icon_color}~ + tempId + + '~' + + min_remaining + + '~' + + sec_remaining + + '~' + + editable + + '~' + + action1 + + '~' + + action2 + + '~' + + action3 + + '~' + + label1 + + '~' + + label2 + + '~' + + label3, }); } - } + } if (type == 'popupFan') { - let switchVal = '0'; if (role == 'level.mode.fan') { if (existsState(id + '.SET')) { @@ -8233,24 +9015,34 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti } let actualSpeed = getState(id + '.SPEED').val; - let maxSpeed = (pageItem.maxValue != undefined) ? pageItem.maxValue : 100; - + let maxSpeed = pageItem.maxValue != undefined ? pageItem.maxValue : 100; + let modeList = pageItem.modeList!.join('?'); let actualMode = pageItem.modeList![getState(id + '.MODE').val]; let tempId = placeId != undefined ? placeId : id; // {tempid | icon | iconColor | switchVal | actualSpeed | maxSpeed: | findLocale | actualMode | modeList} out_msgs.push({ - payload: 'entityUpdateDetail' + '~' // entityUpdateDetail - + tempId + '~' - + icon + '~' // iconId - + iconColor + '~' // iconColor - + switchVal + '~' // buttonState - + actualSpeed + '~' - + maxSpeed + '~' - + findLocale('fan', 'speed') + '~' - + actualMode + '~' - + modeList + payload: + 'entityUpdateDetail' + + '~' + // entityUpdateDetail + tempId + + '~' + + icon + + '~' + // iconId + iconColor + + '~' + // iconColor + switchVal + + '~' + // buttonState + actualSpeed + + '~' + + maxSpeed + + '~' + + findLocale('fan', 'speed') + + '~' + + actualMode + + '~' + + modeList, }); } } @@ -8261,7 +9053,7 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti let optionalString: string = 'Kein Eintrag'; let mode: NSPanel.mediaOptional | '' = ''; if (isPageMediaItem(pageItem)) { - const vTempAdapter = (pageItem.adapterPlayerInstance!).split('.'); + const vTempAdapter = pageItem.adapterPlayerInstance!.split('.'); const vAdapter: NSPanel.PlayerType = vTempAdapter[0] as NSPanel.PlayerType; if (optional == 'seek') { if (vAdapter == 'sonos') { @@ -8277,7 +9069,7 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti if (vAdapter == 'squeezeboxrpc') { const actualStateTime: number = parseInt(getState(pageItem.adapterPlayerInstance + 'Players.' + pageItem.mediaDevice + '.Time').val); const actualStateDuration: number = parseInt(getState(pageItem.adapterPlayerInstance + 'Players.' + pageItem.mediaDevice + '.Duration').val); - const actualStateTemp: number = actualStateTime * 100 / actualStateDuration; + const actualStateTemp: number = (actualStateTime * 100) / actualStateDuration; actualState = Math.round(actualStateTemp / 10) * 10 + '%'; optionalString = '0%?10%?20%?30%?40%?50%?60%?70%?80%?90%?100%'; } @@ -8327,12 +9119,12 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti for (let i = 0; i < pageItem.playList!.length; i++) { tempPlayList[i] = formatInSelText(pageItem.playList![i]); } - optionalString = pageItem.playList != undefined ? tempPlayList.join('?') : '' + optionalString = pageItem.playList != undefined ? tempPlayList.join('?') : ''; } else if (vAdapter == 'alexa2') { //Todo Richtiges Device finden actualState = formatInSelText(getState(pageItem.adapterPlayerInstance + 'Echo-Devices.' + pageItem.mediaDevice + '.Player.currentAlbum').val); - let tPlayList: any = [] + let tPlayList: any = []; for (let i = 0; i < pageItem.playList!.length; i++) { if (Debug) log('function GenerateDetailPage role:media -> Playlist ' + pageItem.playList![i], 'info'); let tempItem = pageItem.playList![i].split('.'); @@ -8343,7 +9135,7 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti for (let i = 0; i < tPlayList.length; i++) { tempPlayList[i] = formatInSelText(tPlayList[i]); } - optionalString = pageItem.playList != undefined ? tempPlayList.join('?') : '' + optionalString = pageItem.playList != undefined ? tempPlayList.join('?') : ''; } else if (vAdapter == 'bosesoundtouch') { if (existsObject(pageItem.adapterPlayerInstance + 'deviceInfo.name')) { actualState = formatInSelText(getState(pageItem.adapterPlayerInstance + 'deviceInfo.name').val); @@ -8351,16 +9143,16 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti let tempPlayList: string[] = []; let vPreset: string = 'No Entry'; for (let i = 1; i < 7; i++) { - if (getState(pageItem.adapterPlayerInstance + 'presets.'+ i +'.source').val !== null) { - vPreset = getState(pageItem.adapterPlayerInstance + 'presets.'+ i + '.source').val; + if (getState(pageItem.adapterPlayerInstance + 'presets.' + i + '.source').val !== null) { + vPreset = getState(pageItem.adapterPlayerInstance + 'presets.' + i + '.source').val; } else { vPreset = 'Preset ' + i.toFixed; } - tempPlayList[i - 1] = formatInSelText(vPreset.replace('_',' ')); - if (Debug) log(formatInSelText(vPreset.replace('_',' '))) + tempPlayList[i - 1] = formatInSelText(vPreset.replace('_', ' ')); + if (Debug) log(formatInSelText(vPreset.replace('_', ' '))); } tempPlayList[6] = 'AUX INPUT'; - optionalString = pageItem.playList != undefined ? tempPlayList.join('?') : '' + optionalString = pageItem.playList != undefined ? tempPlayList.join('?') : ''; } else if (vAdapter == 'sonos') { if (Debug) log(pageItem.adapterPlayerInstance + 'root.' + pageItem.mediaDevice + '.playlist_set', 'info'); if (existsObject(pageItem.adapterPlayerInstance + 'root.' + pageItem.mediaDevice + '.playlist_set')) { @@ -8370,15 +9162,18 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti for (let i = 0; i < pageItem.playList!.length; i++) { tempPlayList[i] = formatInSelText(pageItem.playList![i]); } - optionalString = pageItem.playList != undefined ? tempPlayList.join('?') : '' - } else if (vAdapter == 'volumio') { /* Volumio: limit 900 chars */ + optionalString = pageItem.playList != undefined ? tempPlayList.join('?') : ''; + } else if (vAdapter == 'volumio') { + /* Volumio: limit 900 chars */ actualState = ''; //todo: no actual playlistname saving - let tempPlayList: string[] = []; let tempPll = 0; + let tempPlayList: string[] = []; + let tempPll = 0; for (let i = 0; i < pageItem.playList!.length; i++) { - tempPll += pageItem.playList![i].length; if (tempPll > 900) break; + tempPll += pageItem.playList![i].length; + if (tempPll > 900) break; tempPlayList[i] = formatInSelText(pageItem.playList![i]); } - optionalString = pageItem.playList != undefined ? tempPlayList.join('?') : '' + optionalString = pageItem.playList != undefined ? tempPlayList.join('?') : ''; } else if (vAdapter == 'squeezeboxrpc') { // Playlist browsing not supported by squeezeboxrpc adapter. But Favorites can be used actualState = ''; // Not supported by squeezeboxrpc adapter @@ -8408,8 +9203,8 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti } else { actualState = getState(pageItem.adapterPlayerInstance + 'player.trackName').val; } - actualState = (actualState.replace('?', '')).split(' -'); - actualState = actualState[0].split(" ("); + actualState = actualState.replace('?', '').split(' -'); + actualState = actualState[0].split(' ('); actualState = formatInSelText(actualState[0]); if (Debug) log(actualState, 'info'); if (Debug) log(globalTracklist, 'info'); @@ -8424,16 +9219,15 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti } if (Debug) log('function GenerateDetailPage role:media tracklist -> ' + temp_cut_array, 'info'); if (temp_cut_array != undefined) { - temp_cut_array = (temp_cut_array.replace('?', '')).split(' -'); - temp_cut_array = temp_cut_array[0].split(" ("); + temp_cut_array = temp_cut_array.replace('?', '').split(' -'); + temp_cut_array = temp_cut_array[0].split(' ('); temp_cut_array = temp_cut_array[0]; if (String(temp_cut_array[0]).length >= 22) { temp_array[track_index] = temp_cut_array.substring(0, 20) + '..'; } else { temp_array[track_index] = temp_cut_array.substring(0, 23); } - } - else { + } else { break; } } @@ -8441,19 +9235,21 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti for (let i = 0; i < temp_array.length; i++) { tempTrackList[i] = formatInSelText(temp_array[i]); } - optionalString = pageItem.playList != undefined ? tempTrackList.join('?') : '' + optionalString = pageItem.playList != undefined ? tempTrackList.join('?') : ''; mode = 'tracklist'; } else if (optional == 'equalizer') { if (pageItem.id == undefined) throw new Error('Missing pageItem.id in equalizer!'); - let lastIndex = (pageItem.id.split('.')).pop(); + let lastIndex = pageItem.id.split('.').pop(); - if (existsObject(NSPanel_Path + 'Media.Player.' + lastIndex + '.EQ.activeMode') == false || - existsObject(NSPanel_Path + 'Media.Player.' + lastIndex + '.Speaker') == false) { - createState(NSPanel_Path + 'Media.Player.' + lastIndex + '.EQ.activeMode', {type: 'string', write: false}); - createState(NSPanel_Path + 'Media.Player.' + lastIndex + '.Speaker', {type: 'string', write: false}); + if ( + existsObject(NSPanel_Path + 'Media.Player.' + lastIndex + '.EQ.activeMode') == false || + existsObject(NSPanel_Path + 'Media.Player.' + lastIndex + '.Speaker') == false + ) { + createState(NSPanel_Path + 'Media.Player.' + lastIndex + '.EQ.activeMode', { type: 'string', write: false }); + createState(NSPanel_Path + 'Media.Player.' + lastIndex + '.Speaker', { type: 'string', write: false }); } - actualState = '' + actualState = ''; if (getState(NSPanel_Path + 'Media.Player.' + lastIndex + '.EQ.activeMode').val != null) { actualState = formatInSelText(getState(NSPanel_Path + 'Media.Player.' + lastIndex + '.EQ.activeMode').val); } @@ -8470,7 +9266,7 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti optionalString = pageItem.repeatList!.join('?'); mode = 'repeat'; } else if (optional == 'favorites') { - if (Debug) log(getState(pageItem.adapterPlayerInstance + 'root.' + pageItem.mediaDevice + '.favorites_set').val, 'info') + if (Debug) log(getState(pageItem.adapterPlayerInstance + 'root.' + pageItem.mediaDevice + '.favorites_set').val, 'info'); actualState = formatInSelText(getState(pageItem.adapterPlayerInstance + 'root.' + pageItem.mediaDevice + '.favorites_set').val); let tempFavList: string[] = []; @@ -8485,17 +9281,24 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti let tempId = placeId != undefined ? placeId : id; // {tempid | color | NSPanel.mediaOptional | actualState | optionalString} out_msgs.push({ - payload: 'entityUpdateDetail2' + '~' //entityUpdateDetail - + tempId + '?' + optional + '~~' //{entity_id} - + rgb_dec565(HMIOn) + '~' //{icon_color}~ - + mode + '~' - + actualState + '~' - + optionalString + payload: + 'entityUpdateDetail2' + + '~' + //entityUpdateDetail + tempId + + '?' + + optional + + '~~' + //{entity_id} + rgb_dec565(HMIOn) + + '~' + //{icon_color}~ + mode + + '~' + + actualState + + '~' + + optionalString, }); GeneratePage(activePage!); } } else if (role == 'buttonSensor') { - let actualValue: string = ''; if (pageItem.inSel_ChoiceState || pageItem.inSel_ChoiceState == undefined) { @@ -8504,7 +9307,7 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti RegisterDetailEntityWatcher(id + '.VALUE', pageItem, type, placeId); } } - + let tempModeList: string[] = []; for (let i = 0; i < pageItem.modeList!.length; i++) { tempModeList[i] = formatInSelText(pageItem.modeList![i]); @@ -8514,23 +9317,22 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti let tempId = placeId != undefined ? placeId : id; // {tempid | color | NSPanel.mediaOptional | actualValue | valueList} out_msgs.push({ - payload: 'entityUpdateDetail2' + '~' //entityUpdateDetail2 - + tempId + '~~' //{entity_id} - + rgb_dec565(White) + '~' //{icon_color}~ - + 'insel' + '~' - + actualValue + '~' - + valueList + payload: + 'entityUpdateDetail2' + + '~' + //entityUpdateDetail2 + tempId + + '~~' + //{entity_id} + rgb_dec565(White) + + '~' + //{icon_color}~ + 'insel' + + '~' + + actualValue + + '~' + + valueList, }); - } else if (role == 'light' || - role == 'dimmer' || - role == 'hue' || - role == 'rgb' || - role == 'rgbSingle' || - role == 'ct') { - + } else if (role == 'light' || role == 'dimmer' || role == 'hue' || role == 'rgb' || role == 'rgbSingle' || role == 'ct') { //log(pageItem.id, 'info'); if (pageItem.modeList != undefined) { - let actualValue: string = ''; if (pageItem.inSel_ChoiceState || pageItem.inSel_ChoiceState == undefined) { @@ -8550,20 +9352,25 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti let tempId = placeId != undefined ? placeId : id; // {tempid | color | 'insel' | actualValue | valueList} out_msgs.push({ - payload: 'entityUpdateDetail2' + '~' //entityUpdateDetail2 - + tempId + '~~' //{entity_id} - + rgb_dec565(White) + '~' //{icon_color}~ - + 'insel' + '~' - + actualValue + '~' - + valueList + payload: + 'entityUpdateDetail2' + + '~' + //entityUpdateDetail2 + tempId + + '~~' + //{entity_id} + rgb_dec565(White) + + '~' + //{icon_color}~ + 'insel' + + '~' + + actualValue + + '~' + + valueList, }); } } } } - if (Debug) log('GenerateDetailPage -> payload: ' + JSON.stringify(out_msgs), 'info'); + if (Debug) log('GenerateDetailPage -> payload: ' + JSON.stringify(out_msgs), 'info'); return out_msgs; - } catch (err: any) { log('error at function GenerateDetailPage: ' + err.message, 'warn'); } @@ -8572,11 +9379,11 @@ function GenerateDetailPage(type: NSPanel.PopupType, optional: NSPanel.mediaOpti function scale(number: number, inMin: number, inMax: number, outMin: number, outMax: number): number { try { - return (outMax + outMin) - ((number - inMin) * (outMax - outMin) / (inMax - inMin) + outMin); + return outMax + outMin - (((number - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin); } catch (err: any) { log('error at function scale: ' + err.message, 'warn'); } - return 0 + return 0; } function UnsubscribeWatcher(): void { @@ -8611,9 +9418,7 @@ function HandleScreensaver(): void { function HandleScreensaverUpdate(): void { try { - if (screensaverEnabled) { - UnsubscribeWatcher(); let payloadString: string = ''; @@ -8623,18 +9428,18 @@ function HandleScreensaverUpdate(): void { //Create Weather MainIcon if (screensaverEnabled && config.weatherEntity != null && existsObject(config.weatherEntity)) { let icon = getState(config.weatherEntity + '.ICON').val; - RegisterScreensaverEntityWatcher(config.weatherEntity + '.ICON') + RegisterScreensaverEntityWatcher(config.weatherEntity + '.ICON'); let temperature = '0'; if (existsState(config.weatherEntity + '.ACTUAL')) { - temperature= getState(config.weatherEntity + '.ACTUAL').val; - RegisterScreensaverEntityWatcher(config.weatherEntity + '.ACTUAL') + temperature = getState(config.weatherEntity + '.ACTUAL').val; + RegisterScreensaverEntityWatcher(config.weatherEntity + '.ACTUAL'); } else { if (existsState(config.weatherEntity + '.TEMP')) { temperature = getState(config.weatherEntity + '.TEMP').val; } else { - 'null'; + ('null'); } - } + } let optionalValue = temperature + ' ' + temperatureUnit; let entityIcon = ''; let entityIconCol = 0; @@ -8646,26 +9451,21 @@ function HandleScreensaverUpdate(): void { entityIconCol = GetAccuWeatherIconColor(parseInt(icon)); } - payloadString += '~' + - '~' + - entityIcon + '~' + - entityIconCol + '~' + - '~' + - optionalValue + '~'; + payloadString += '~' + '~' + entityIcon + '~' + entityIconCol + '~' + '~' + optionalValue + '~'; } - // 3 leftScreensaverEntities + // 3 leftScreensaverEntities if (screensaverAdvanced) { let checkpoint = true; let i = 0; if (config.leftScreensaverEntity && Array.isArray(config.leftScreensaverEntity)) { for (i = 0; i < 3 && i < config.leftScreensaverEntity.length; i++) { - const leftScreensaverEntity = config.leftScreensaverEntity[i] + const leftScreensaverEntity = config.leftScreensaverEntity[i]; if (leftScreensaverEntity === null || leftScreensaverEntity === undefined) { checkpoint = false; - break;; + break; } - RegisterScreensaverEntityWatcher(leftScreensaverEntity.ScreensaverEntity) + RegisterScreensaverEntityWatcher(leftScreensaverEntity.ScreensaverEntity); let val = getState(leftScreensaverEntity.ScreensaverEntity).val; let iconColor = rgb_dec565(White); @@ -8677,21 +9477,22 @@ function HandleScreensaverUpdate(): void { icon = Icons.GetIcon(leftScreensaverEntity.ScreensaverEntityIconOn); } - if (parseFloat(val + "") == val) { + if (parseFloat(val + '') == val) { val = parseFloat(val); } - if (typeof (val) == 'number') { - val = (val * (leftScreensaverEntity.ScreensaverEntityFactor ? leftScreensaverEntity.ScreensaverEntityFactor! : 0)).toFixed(leftScreensaverEntity.ScreensaverEntityDecimalPlaces) + leftScreensaverEntity.ScreensaverEntityUnitText; + if (typeof val == 'number') { + val = + (val * (leftScreensaverEntity.ScreensaverEntityFactor ? leftScreensaverEntity.ScreensaverEntityFactor! : 0)).toFixed( + leftScreensaverEntity.ScreensaverEntityDecimalPlaces + ) + leftScreensaverEntity.ScreensaverEntityUnitText; iconColor = GetScreenSaverEntityColor(leftScreensaverEntity); - } - else if (typeof (val) == 'boolean') { + } else if (typeof val == 'boolean') { iconColor = GetScreenSaverEntityColor(leftScreensaverEntity); if (!val && leftScreensaverEntity.ScreensaverEntityIconOff != null) { - icon = Icons.GetIcon(leftScreensaverEntity.ScreensaverEntityIconOff) + icon = Icons.GetIcon(leftScreensaverEntity.ScreensaverEntityIconOff); } - } - else if (typeof (val) == 'string') { + } else if (typeof val == 'string') { iconColor = GetScreenSaverEntityColor(leftScreensaverEntity); let pformat = parseFormat(val); if (Debug) log('moments.js --> Datum ' + val + ' valid?: ' + moment(val, pformat, true).isValid(), 'info'); @@ -8709,18 +9510,13 @@ function HandleScreensaverUpdate(): void { iconColor = getState(temp).val; } - payloadString += '~' + - '~' + - icon + '~' + - iconColor + '~' + - leftScreensaverEntity.ScreensaverEntityText + '~' + - val + '~'; + payloadString += '~' + '~' + icon + '~' + iconColor + '~' + leftScreensaverEntity.ScreensaverEntityText + '~' + val + '~'; } } if (checkpoint == false) { for (let j = i; j < 3; j++) { payloadString += '~~~~~~'; - } + } } } @@ -8729,16 +9525,15 @@ function HandleScreensaverUpdate(): void { if (screensaverAdvanced == false) { maxEntities = 5; if (getState(NSPanel_Path + 'Config.Screensaver.alternativeScreensaverLayout').val) { - maxEntities = 6; + maxEntities = 6; } } if (weatherForecast) { - if (getState(NSPanel_Path + 'Config.Screensaver.alternativeScreensaverLayout').val) { - maxEntities = 5; + maxEntities = 5; } - + for (let i = 1; i < maxEntities; i++) { let TempMin = 0; let TempMax = 0; @@ -8749,7 +9544,7 @@ function HandleScreensaverUpdate(): void { if (weatherAdapterInstance == 'daswetter.' + weatherAdapterInstanceNumber + '.') { TempMin = getState('daswetter.' + weatherAdapterInstanceNumber + '.NextDays.Location_1.Day_' + i + '.Minimale_Temperatur_value').val; TempMax = getState('daswetter.' + weatherAdapterInstanceNumber + '.NextDays.Location_1.Day_' + i + '.Maximale_Temperatur_value').val; - DayOfWeek = (getState('daswetter.' + weatherAdapterInstanceNumber + '.NextDays.Location_1.Day_' + i + '.Tag_value').val).substring(0,2); + DayOfWeek = getState('daswetter.' + weatherAdapterInstanceNumber + '.NextDays.Location_1.Day_' + i + '.Tag_value').val.substring(0, 2); WeatherIcon = GetDasWetterIcon(getState('daswetter.' + weatherAdapterInstanceNumber + '.NextDays.Location_1.Day_' + i + '.Wetter_Symbol_id').val); WheatherColor = GetDasWetterIconColor(getState('daswetter.' + weatherAdapterInstanceNumber + '.NextDays.Location_1.Day_' + i + '.Wetter_Symbol_id').val); @@ -8760,11 +9555,21 @@ function HandleScreensaverUpdate(): void { } else if (weatherAdapterInstance == 'accuweather.' + weatherAdapterInstanceNumber + '.') { if (i < 6) { //Maximal 5 Tage bei accuweather - TempMin = (existsObject('accuweather.' + weatherAdapterInstanceNumber + '.Summary.TempMin_d' + i)) ? getState('accuweather.' + weatherAdapterInstanceNumber + '.Summary.TempMin_d' + i).val : 0; - TempMax = (existsObject('accuweather.' + weatherAdapterInstanceNumber + '.Summary.TempMax_d' + i)) ? getState('accuweather.' + weatherAdapterInstanceNumber + '.Summary.TempMax_d' + i).val : 0; - DayOfWeek = (existsObject('accuweather.' + weatherAdapterInstanceNumber + '.Summary.DayOfWeek_d' + i)) ? getState('accuweather.' + weatherAdapterInstanceNumber + '.Summary.DayOfWeek_d' + i).val : 0; - WeatherIcon = (existsObject('accuweather.' + weatherAdapterInstanceNumber + '.Summary.WeatherIcon_d' + i)) ? GetAccuWeatherIcon(getState('accuweather.' + weatherAdapterInstanceNumber + '.Summary.WeatherIcon_d' + i).val) : ''; - WheatherColor = (existsObject('accuweather.' + weatherAdapterInstanceNumber + '.Summary.WeatherIcon_d' + i)) ? GetAccuWeatherIconColor(getState('accuweather.' + weatherAdapterInstanceNumber + '.Summary.WeatherIcon_d' + i).val) : 0; + TempMin = existsObject('accuweather.' + weatherAdapterInstanceNumber + '.Summary.TempMin_d' + i) + ? getState('accuweather.' + weatherAdapterInstanceNumber + '.Summary.TempMin_d' + i).val + : 0; + TempMax = existsObject('accuweather.' + weatherAdapterInstanceNumber + '.Summary.TempMax_d' + i) + ? getState('accuweather.' + weatherAdapterInstanceNumber + '.Summary.TempMax_d' + i).val + : 0; + DayOfWeek = existsObject('accuweather.' + weatherAdapterInstanceNumber + '.Summary.DayOfWeek_d' + i) + ? getState('accuweather.' + weatherAdapterInstanceNumber + '.Summary.DayOfWeek_d' + i).val + : 0; + WeatherIcon = existsObject('accuweather.' + weatherAdapterInstanceNumber + '.Summary.WeatherIcon_d' + i) + ? GetAccuWeatherIcon(getState('accuweather.' + weatherAdapterInstanceNumber + '.Summary.WeatherIcon_d' + i).val) + : ''; + WheatherColor = existsObject('accuweather.' + weatherAdapterInstanceNumber + '.Summary.WeatherIcon_d' + i) + ? GetAccuWeatherIconColor(getState('accuweather.' + weatherAdapterInstanceNumber + '.Summary.WeatherIcon_d' + i).val) + : 0; RegisterScreensaverEntityWatcher('accuweather.' + weatherAdapterInstanceNumber + '.Summary.TempMin_d' + i); RegisterScreensaverEntityWatcher('accuweather.' + weatherAdapterInstanceNumber + '.Summary.TempMax_d' + i); @@ -8782,16 +9587,15 @@ function HandleScreensaverUpdate(): void { tempMinMaxString = Math.round(TempMin) + '° ' + Math.round(TempMax) + '°'; } - if (weatherAdapterInstance == 'accuweather.' + weatherAdapterInstanceNumber + '.' && i == 6) { - - let nextSunEvent = 0 + if (weatherAdapterInstance == 'accuweather.' + weatherAdapterInstanceNumber + '.' && i == 6) { + let nextSunEvent = 0; let valDateNow = new Date().getTime(); let arraySunEvent: number[] = []; arraySunEvent[0] = getDateObject(getState('accuweather.' + weatherAdapterInstanceNumber + '.Daily.Day1.Sunrise').val).getTime(); arraySunEvent[1] = getDateObject(getState('accuweather.' + weatherAdapterInstanceNumber + '.Daily.Day1.Sunset').val).getTime(); arraySunEvent[2] = getDateObject(getState('accuweather.' + weatherAdapterInstanceNumber + '.Daily.Day2.Sunrise').val).getTime(); - + let j = 0; for (j = 0; j < 3; j++) { if (arraySunEvent[j] > valDateNow) { @@ -8806,182 +9610,167 @@ function HandleScreensaverUpdate(): void { sun = 'weather-sunset-up'; } - payloadString += '~' + - '~' + - Icons.GetIcon(sun) + '~' + - rgb_dec565(MSYellow) + '~' + - 'Sonne' + '~' + - formatDate(getDateObject(arraySunEvent[nextSunEvent]), 'hh:mm') + '~'; + payloadString += '~' + '~' + Icons.GetIcon(sun) + '~' + rgb_dec565(MSYellow) + '~' + 'Sonne' + '~' + formatDate(getDateObject(arraySunEvent[nextSunEvent]), 'hh:mm') + '~'; } else { - payloadString += '~' + - '~' + - Icons.GetIcon(WeatherIcon) + '~' + - WheatherColor + '~' + - DayOfWeek + '~' + - tempMinMaxString + '~'; + payloadString += '~' + '~' + Icons.GetIcon(WeatherIcon) + '~' + WheatherColor + '~' + DayOfWeek + '~' + tempMinMaxString + '~'; } } //Alternativ Layout bekommt zusätzlichen Status if (config.bottomScreensaverEntity[4] && getState(NSPanel_Path + 'Config.Screensaver.alternativeScreensaverLayout').val) { let val = getState(config.bottomScreensaverEntity[4].ScreensaverEntity).val; - if (parseFloat(val+"") == val) { + if (parseFloat(val + '') == val) { val = parseFloat(val); } let iconColor = rgb_dec565(White); - if (typeof(val) == 'number') { - val = (val * (config.bottomScreensaverEntity[4].ScreensaverEntityFactor ? config.bottomScreensaverEntity[4].ScreensaverEntityFactor : 0)).toFixed(config.bottomScreensaverEntity[4].ScreensaverEntityDecimalPlaces) + config.bottomScreensaverEntity[4].ScreensaverEntityUnitText; + if (typeof val == 'number') { + val = + (val * (config.bottomScreensaverEntity[4].ScreensaverEntityFactor ? config.bottomScreensaverEntity[4].ScreensaverEntityFactor : 0)).toFixed( + config.bottomScreensaverEntity[4].ScreensaverEntityDecimalPlaces + ) + config.bottomScreensaverEntity[4].ScreensaverEntityUnitText; iconColor = GetScreenSaverEntityColor(config.bottomScreensaverEntity[4]); - } - else if (typeof(val) == 'boolean') { + } else if (typeof val == 'boolean') { iconColor = GetScreenSaverEntityColor(config.bottomScreensaverEntity[4]); - } - else if (typeof(val) == 'string') { + } else if (typeof val == 'string') { iconColor = GetScreenSaverEntityColor(config.bottomScreensaverEntity[4]); let pformat = parseFormat(val); if (Debug) log('moments.js --> Datum ' + val + ' valid?: ' + moment(val, pformat, true).isValid(), 'info'); - if (moment(val, pformat, true).isValid()) { + if (moment(val, pformat, true).isValid()) { let DatumZeit = moment(val, pformat).unix(); // Conversion to Unix time stamp if (config.bottomScreensaverEntity[4].ScreensaverEntityDateFormat !== undefined) { val = new Date(DatumZeit * 1000).toLocaleString(getState(NSPanel_Path + 'Config.locale').val, config.bottomScreensaverEntity[4].ScreensaverEntityDateFormat); } else { val = new Date(DatumZeit * 1000).toLocaleString(getState(NSPanel_Path + 'Config.locale').val); } - } - + } } - const temp = config.bottomScreensaverEntity[4].ScreensaverEntityIconColor + const temp = config.bottomScreensaverEntity[4].ScreensaverEntityIconColor; if (temp && typeof temp == 'string' && existsObject(temp)) { iconColor = getState(temp).val; - } - payloadString += '~' + - '~' + - Icons.GetIcon(config.bottomScreensaverEntity[4].ScreensaverEntityIconOn) + '~' + - iconColor + '~' + - config.bottomScreensaverEntity[4].ScreensaverEntityText + '~' + - val + } + payloadString += + '~' + + '~' + + Icons.GetIcon(config.bottomScreensaverEntity[4].ScreensaverEntityIconOn) + + '~' + + iconColor + + '~' + + config.bottomScreensaverEntity[4].ScreensaverEntityText + + '~' + + val; } // Ende zusätzlichen Status Alternativ Layout - } else { - // USER definierte Bottom Entities + // USER definierte Bottom Entities let checkpoint = true; let i = 0; for (i = 0; i < maxEntities - 1 && i < config.bottomScreensaverEntity.length; i++) { if (config.bottomScreensaverEntity[i] == null || config.bottomScreensaverEntity[i] === undefined) { checkpoint = false; break; - } - RegisterScreensaverEntityWatcher(config.bottomScreensaverEntity[i].ScreensaverEntity) - + } + RegisterScreensaverEntityWatcher(config.bottomScreensaverEntity[i].ScreensaverEntity); + let val = getState(config.bottomScreensaverEntity[i].ScreensaverEntity).val; - if (parseFloat(val+"") == val) { + if (parseFloat(val + '') == val) { val = parseFloat(val); } let iconColor = rgb_dec565(White); - let icon; + let icon; if (config.bottomScreensaverEntity[i].ScreensaverEntityIconOn && existsObject(config.bottomScreensaverEntity[i].ScreensaverEntityIconOn!)) { let iconName = getState(config.bottomScreensaverEntity[i].ScreensaverEntityIconOn!).val; icon = Icons.GetIcon(iconName); } else { icon = Icons.GetIcon(config.bottomScreensaverEntity[i].ScreensaverEntityIconOn); - } - - if (typeof(val) == 'number') { - val = (val * (config.bottomScreensaverEntity[i].ScreensaverEntityFactor ? config.bottomScreensaverEntity[i].ScreensaverEntityFactor! : 0)).toFixed(config.bottomScreensaverEntity[i].ScreensaverEntityDecimalPlaces) + config.bottomScreensaverEntity[i].ScreensaverEntityUnitText; - iconColor = GetScreenSaverEntityColor(config.bottomScreensaverEntity[i]); } - else if (typeof(val) == 'boolean') { + + if (typeof val == 'number') { + val = + (val * (config.bottomScreensaverEntity[i].ScreensaverEntityFactor ? config.bottomScreensaverEntity[i].ScreensaverEntityFactor! : 0)).toFixed( + config.bottomScreensaverEntity[i].ScreensaverEntityDecimalPlaces + ) + config.bottomScreensaverEntity[i].ScreensaverEntityUnitText; + iconColor = GetScreenSaverEntityColor(config.bottomScreensaverEntity[i]); + } else if (typeof val == 'boolean') { iconColor = GetScreenSaverEntityColor(config.bottomScreensaverEntity[i]); if (!val && config.bottomScreensaverEntity[i].ScreensaverEntityIconOff != null) { - icon = Icons.GetIcon(config.bottomScreensaverEntity[i].ScreensaverEntityIconOff) + icon = Icons.GetIcon(config.bottomScreensaverEntity[i].ScreensaverEntityIconOff); } - if (val && config.bottomScreensaverEntity[i].ScreensaverEntityOnText !=undefined) { + if (val && config.bottomScreensaverEntity[i].ScreensaverEntityOnText != undefined) { val = config.bottomScreensaverEntity[i].ScreensaverEntityOnText; } - if (!val && config.bottomScreensaverEntity[i].ScreensaverEntityOffText !=undefined) { + if (!val && config.bottomScreensaverEntity[i].ScreensaverEntityOffText != undefined) { val = config.bottomScreensaverEntity[i].ScreensaverEntityOffText; } - - } - else if (typeof(val) == 'string') { + } else if (typeof val == 'string') { iconColor = GetScreenSaverEntityColor(config.bottomScreensaverEntity[i]); let pformat = parseFormat(val); if (Debug) log('moments.js --> Datum ' + val + ' valid?: ' + moment(val, pformat, true).isValid(), 'info'); - if (moment(val, pformat, true).isValid()) { + if (moment(val, pformat, true).isValid()) { let DatumZeit = moment(val, pformat).unix(); // Conversion to Unix time stamp if (config.bottomScreensaverEntity[i].ScreensaverEntityDateFormat !== undefined) { val = new Date(DatumZeit * 1000).toLocaleString(getState(NSPanel_Path + 'Config.locale').val, config.bottomScreensaverEntity[i].ScreensaverEntityDateFormat); } else { val = new Date(DatumZeit * 1000).toLocaleString(getState(NSPanel_Path + 'Config.locale').val); } - } + } } - const temp = config.bottomScreensaverEntity[i].ScreensaverEntityIconColor + const temp = config.bottomScreensaverEntity[i].ScreensaverEntityIconColor; if (temp && typeof temp == 'string' && existsObject(temp)) { iconColor = getState(temp).val; } if (i < maxEntities - 1) { val = val + '~'; } - payloadString += '~' + - '~' + - icon + '~' + - iconColor + '~' + - config.bottomScreensaverEntity[i].ScreensaverEntityText + '~' + - val + payloadString += '~' + '~' + icon + '~' + iconColor + '~' + config.bottomScreensaverEntity[i].ScreensaverEntityText + '~' + val; } if (checkpoint == false) { for (let j = i; j < maxEntities - 1; j++) { payloadString += '~~~~~~'; - } + } } } if (screensaverAdvanced) { - // 5 indicatorScreensaverEntities + // 5 indicatorScreensaverEntities for (let i = 0; i < 5 && i < config.indicatorScreensaverEntity.length; i++) { - const indicatorScreensaverEntity:NSPanel.ScreenSaverElementWithUndefined = config.indicatorScreensaverEntity[i]; + const indicatorScreensaverEntity: NSPanel.ScreenSaverElementWithUndefined = config.indicatorScreensaverEntity[i]; if (indicatorScreensaverEntity === null || indicatorScreensaverEntity === undefined) { break; } - RegisterScreensaverEntityWatcher(indicatorScreensaverEntity.ScreensaverEntity) + RegisterScreensaverEntityWatcher(indicatorScreensaverEntity.ScreensaverEntity); let val = getState(indicatorScreensaverEntity.ScreensaverEntity).val; - if (parseFloat(val+"") == val) { + if (parseFloat(val + '') == val) { val = parseFloat(val); } let iconColor = rgb_dec565(White); - + let icon; if (indicatorScreensaverEntity.ScreensaverEntityIconOn && existsObject(indicatorScreensaverEntity.ScreensaverEntityIconOn!)) { let iconName = getState(indicatorScreensaverEntity.ScreensaverEntityIconOn!).val; icon = Icons.GetIcon(iconName); } else { icon = Icons.GetIcon(indicatorScreensaverEntity.ScreensaverEntityIconOn); - } - - if (typeof(val) == 'number') { - val = (val * (indicatorScreensaverEntity.ScreensaverEntityFactor ? indicatorScreensaverEntity.ScreensaverEntityFactor! : 0)).toFixed(indicatorScreensaverEntity.ScreensaverEntityDecimalPlaces) + indicatorScreensaverEntity.ScreensaverEntityUnitText; - iconColor = GetScreenSaverEntityColor(indicatorScreensaverEntity); } - else if (typeof(val) == 'boolean') { + + if (typeof val == 'number') { + val = + (val * (indicatorScreensaverEntity.ScreensaverEntityFactor ? indicatorScreensaverEntity.ScreensaverEntityFactor! : 0)).toFixed( + indicatorScreensaverEntity.ScreensaverEntityDecimalPlaces + ) + indicatorScreensaverEntity.ScreensaverEntityUnitText; + iconColor = GetScreenSaverEntityColor(indicatorScreensaverEntity); + } else if (typeof val == 'boolean') { iconColor = GetScreenSaverEntityColor(indicatorScreensaverEntity); if (!val && indicatorScreensaverEntity.ScreensaverEntityIconOff != null) { - icon = Icons.GetIcon(indicatorScreensaverEntity.ScreensaverEntityIconOff) + icon = Icons.GetIcon(indicatorScreensaverEntity.ScreensaverEntityIconOff); } } - const temp = indicatorScreensaverEntity.ScreensaverEntityIconColor + const temp = indicatorScreensaverEntity.ScreensaverEntityIconColor; if (temp && typeof temp == 'string' && existsObject(temp)) { iconColor = getState(temp).val; } - payloadString += '~' + - 'f'+ (i+1) + 'Icon~' + - icon + '~' + - iconColor + '~' + - indicatorScreensaverEntity.ScreensaverEntityText + '~' + - val + '~'; + payloadString += '~' + 'f' + (i + 1) + 'Icon~' + icon + '~' + iconColor + '~' + indicatorScreensaverEntity.ScreensaverEntityText + '~' + val + '~'; } } if (Debug) log('HandleScreensaverUpdate payload: weatherUpdate~' + payloadString, 'info'); @@ -8990,9 +9779,8 @@ function HandleScreensaverUpdate(): void { HandleScreensaverStatusIcons(); - HandleScreensaverColors(); + HandleScreensaverColors(); } - } catch (err: any) { log('error at function HandleScreensaverUpdate: ' + err.message, 'warn'); } @@ -9004,82 +9792,68 @@ function RegisterScreensaverEntityWatcher(id: string): void { return; } - subscriptions[id] = (on({ id: id, change: 'any' }, () => { + subscriptions[id] = on({ id: id, change: 'any' }, () => { HandleScreensaverUpdate(); - })); + }); } catch (err: any) { log('function RegisterEntityWatcher: ' + err.message, 'warn'); } } -function HandleScreensaverStatusIcons() : void { +function HandleScreensaverStatusIcons(): void { try { let payloadString = ''; const iconData: Record<'mrIcon1' | 'mrIcon2', NSPanel.ScreenSaverMRDataElement> = { mrIcon1: { - ScreensaverEntity: config.mrIcon1ScreensaverEntity.ScreensaverEntity != null - && existsState(config.mrIcon1ScreensaverEntity.ScreensaverEntity) - ? getState(config.mrIcon1ScreensaverEntity.ScreensaverEntity).val - : null, - ScreensaverEntityIconOn: config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOn - ? Icons.GetIcon(config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOn) - : '', - ScreensaverEntityIconOff: config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOff - ? Icons.GetIcon(config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOff) - : '', + ScreensaverEntity: + config.mrIcon1ScreensaverEntity.ScreensaverEntity != null && existsState(config.mrIcon1ScreensaverEntity.ScreensaverEntity) + ? getState(config.mrIcon1ScreensaverEntity.ScreensaverEntity).val + : null, + ScreensaverEntityIconOn: config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOn ? Icons.GetIcon(config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOn) : '', + ScreensaverEntityIconOff: config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOff ? Icons.GetIcon(config.mrIcon1ScreensaverEntity.ScreensaverEntityIconOff) : '', ScreensaverEntityOnColor: config.mrIcon1ScreensaverEntity.ScreensaverEntityOnColor, ScreensaverEntityOffColor: config.mrIcon1ScreensaverEntity.ScreensaverEntityOffColor, - ScreensaverEntityValue: config.mrIcon1ScreensaverEntity.ScreensaverEntityValue === null - ? null - : getState(config.mrIcon1ScreensaverEntity.ScreensaverEntityValue).val, + ScreensaverEntityValue: config.mrIcon1ScreensaverEntity.ScreensaverEntityValue === null ? null : getState(config.mrIcon1ScreensaverEntity.ScreensaverEntityValue).val, ScreensaverEntityValueDecimalPlace: config.mrIcon1ScreensaverEntity.ScreensaverEntityValueDecimalPlace, ScreensaverEntityValueUnit: config.mrIcon1ScreensaverEntity.ScreensaverEntityValueUnit, - ScreensaverEntityIconSelect: config.mrIcon1ScreensaverEntity.ScreensaverEntityIconSelect - && typeof config.mrIcon1ScreensaverEntity.ScreensaverEntityIconSelect === 'object' - ? config.mrIcon1ScreensaverEntity.ScreensaverEntityIconSelect - : null, - - + ScreensaverEntityIconSelect: + config.mrIcon1ScreensaverEntity.ScreensaverEntityIconSelect && typeof config.mrIcon1ScreensaverEntity.ScreensaverEntityIconSelect === 'object' + ? config.mrIcon1ScreensaverEntity.ScreensaverEntityIconSelect + : null, }, mrIcon2: { - ScreensaverEntity: config.mrIcon2ScreensaverEntity.ScreensaverEntity != null - && existsState(config.mrIcon2ScreensaverEntity.ScreensaverEntity) - ? getState(config.mrIcon2ScreensaverEntity.ScreensaverEntity).val - : null, - ScreensaverEntityIconOn: config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn - ? Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn) - : '', - ScreensaverEntityIconOff: config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOff - ? Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOff) - : '', + ScreensaverEntity: + config.mrIcon2ScreensaverEntity.ScreensaverEntity != null && existsState(config.mrIcon2ScreensaverEntity.ScreensaverEntity) + ? getState(config.mrIcon2ScreensaverEntity.ScreensaverEntity).val + : null, + ScreensaverEntityIconOn: config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn ? Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOn) : '', + ScreensaverEntityIconOff: config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOff ? Icons.GetIcon(config.mrIcon2ScreensaverEntity.ScreensaverEntityIconOff) : '', ScreensaverEntityOnColor: config.mrIcon2ScreensaverEntity.ScreensaverEntityOnColor, ScreensaverEntityOffColor: config.mrIcon2ScreensaverEntity.ScreensaverEntityOffColor, - ScreensaverEntityValue: config.mrIcon2ScreensaverEntity.ScreensaverEntityValue === null - ? null - : getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val, + ScreensaverEntityValue: config.mrIcon2ScreensaverEntity.ScreensaverEntityValue === null ? null : getState(config.mrIcon2ScreensaverEntity.ScreensaverEntityValue).val, ScreensaverEntityValueDecimalPlace: config.mrIcon2ScreensaverEntity.ScreensaverEntityValueDecimalPlace, ScreensaverEntityValueUnit: config.mrIcon2ScreensaverEntity.ScreensaverEntityValueUnit, - ScreensaverEntityIconSelect: config.mrIcon2ScreensaverEntity.ScreensaverEntityIconSelect - && typeof config.mrIcon2ScreensaverEntity.ScreensaverEntityIconSelect === 'object' - ? config.mrIcon2ScreensaverEntity.ScreensaverEntityIconSelect - : null, - } - } + ScreensaverEntityIconSelect: + config.mrIcon2ScreensaverEntity.ScreensaverEntityIconSelect && typeof config.mrIcon2ScreensaverEntity.ScreensaverEntityIconSelect === 'object' + ? config.mrIcon2ScreensaverEntity.ScreensaverEntityIconSelect + : null, + }, + }; for (const a in iconData) { if (iconData[a].ScreensaverEntityValue !== null) { switch (typeof iconData[a].ScreensaverEntityValue) { - case "string": + case 'string': if (iconData[a].ScreensaverEntityValue === '' || isNaN(iconData[a].ScreensaverEntityValue)) break; - case "number": - case "bigint": + case 'number': + case 'bigint': iconData[a].ScreensaverEntityValue = Number(iconData[a].ScreensaverEntityValue).toFixed(iconData[a].ScreensaverEntityValueDecimalPlace); break; - case "boolean": + case 'boolean': break; - case "symbol": - case "undefined": - case "object": - case "function": + case 'symbol': + case 'undefined': + case 'object': + case 'function': iconData[a].ScreensaverEntityValue = null; } } @@ -9087,23 +9861,23 @@ function HandleScreensaverStatusIcons() : void { if (iconData[a].ScreensaverEntity != null || iconData[a].ScreensaverEntityValue != null) { // Prüfung ob ScreensaverEntity vom Typ String ist if (iconData[a].ScreensaverEntity != null) { - if (typeof (iconData[a].ScreensaverEntity) == 'string') { - if (Debug) log('Entity ist String', 'info') - switch (String(iconData[a].ScreensaverEntity).toUpperCase()) { - case 'ON': - case 'OK': - case 'AN': - case 'YES': - case 'TRUE': - case 'ONLINE': + if (typeof iconData[a].ScreensaverEntity == 'string') { + if (Debug) log('Entity ist String', 'info'); + switch (String(iconData[a].ScreensaverEntity).toUpperCase()) { + case 'ON': + case 'OK': + case 'AN': + case 'YES': + case 'TRUE': + case 'ONLINE': hwBtn1Col = iconData[a].ScreensaverEntityOnColor; break; default: } - if (Debug) log('Value: ' + iconData[a].ScreensaverEntity + ' Color: ' + JSON.stringify(hwBtn1Col), 'info') + if (Debug) log('Value: ' + iconData[a].ScreensaverEntity + ' Color: ' + JSON.stringify(hwBtn1Col), 'info'); // Alles was kein String ist in Boolean umwandeln } else { - if (Debug) log('Entity ist kein String', 'info') + if (Debug) log('Entity ist kein String', 'info'); if (!!iconData[a].ScreensaverEntity) { hwBtn1Col = iconData[a].ScreensaverEntityOnColor; } @@ -9115,35 +9889,35 @@ function HandleScreensaverStatusIcons() : void { const icon = iconData[a].ScreensaverEntityIconSelect[iconData[a].ScreensaverEntity]; if (icon !== undefined) { payloadString += Icons.GetIcon(icon); - if (Debug) log('SelectIcon: '+payloadString, 'info') + if (Debug) log('SelectIcon: ' + payloadString, 'info'); } } else if (iconData[a].ScreensaverEntity) { payloadString += iconData[a].ScreensaverEntityIconOn; - if (Debug) log('Icon if true '+payloadString, 'info') + if (Debug) log('Icon if true ' + payloadString, 'info'); } else { if (iconData[a].ScreensaverEntityIconOff) { payloadString += iconData[a].ScreensaverEntityIconOff; - if (Debug) log('Icon1 else true '+payloadString, 'info') + if (Debug) log('Icon1 else true ' + payloadString, 'info'); } else { payloadString += iconData[a].ScreensaverEntityIconOn; - if (Debug) log('Icon1 else false '+payloadString, 'info') + if (Debug) log('Icon1 else false ' + payloadString, 'info'); } - } - - if (iconData[a].ScreensaverEntityValue != null) { + } + + if (iconData[a].ScreensaverEntityValue != null) { payloadString += iconData[a].ScreensaverEntityValue; - payloadString += (iconData[a].ScreensaverEntityValueUnit == null) ? '' : iconData[a].ScreensaverEntityValueUnit; - } - + payloadString += iconData[a].ScreensaverEntityValueUnit == null ? '' : iconData[a].ScreensaverEntityValueUnit; + } + payloadString += '~' + rgb_dec565(hwBtn1Col) + '~'; } else { hwBtn1Col = Black; payloadString += '~~'; } } - - let alternateScreensaverMFRIcon1Size = getState(NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.1').val - let alternateScreensaverMFRIcon2Size = getState(NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.2').val + + let alternateScreensaverMFRIcon1Size = getState(NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.1').val; + let alternateScreensaverMFRIcon2Size = getState(NSPanel_Path + 'Config.MRIcons.alternateMRIconSize.2').val; //Alternate MRIcon Size if (alternateScreensaverMFRIcon1Size) { payloadString += '1~'; @@ -9157,7 +9931,6 @@ function HandleScreensaverStatusIcons() : void { } // statusUpdate~icon1~icon1Color~icon1font~icon2~icon2color~icon2font~icon2font SendToPanel({ payload: 'statusUpdate~' + payloadString }); - } catch (err: any) { log('error at function HandleScreensaverStatusIcons: ' + err.message, 'warn'); } @@ -9217,7 +9990,7 @@ function HandleScreensaverColors(): void { } } - let scrSvrBGCol: any; + let scrSvrBGCol: any; if (bgColorScrSaver == 0) { scrSvrBGCol = rgb_dec565(scbackground); @@ -9228,34 +10001,34 @@ function HandleScreensaverColors(): void { } else if (bgColorScrSaver == 3) { scrSvrBGCol = rgb_dec565(scbackgroundInd3); } else if (bgColorScrSaver == 4) { - scrSvrBGCol = rgb_dec565({red:255, green:16, blue:240}); + scrSvrBGCol = rgb_dec565({ red: 255, green: 16, blue: 240 }); } else if (bgColorScrSaver == 5) { scrSvrBGCol = rgb_dec565({ red: 100, green: 0, blue: 0 }); } - + let payloadString = buildNSPanelString( - 'color' , - scrSvrBGCol , //background - rgb_dec565(sctime) , //time - rgb_dec565(sctimeAMPM) , //timeAMPM~ - rgb_dec565(scdate) , //date~ - rgb_dec565(sctMainText) , //tMainText~ - rgb_dec565(sctForecast1) , //tForecast1~ - rgb_dec565(sctForecast2) , //tForecast2~ - rgb_dec565(sctForecast3) , //tForecast3~ - rgb_dec565(sctForecast4) , //tForecast4~ - rgb_dec565(sctForecast1Val) , //tForecast1Val~ - rgb_dec565(sctForecast2Val) , //tForecast2Val~ - rgb_dec565(sctForecast3Val) , //tForecast3Val~ - rgb_dec565(sctForecast4Val) , //tForecast4Val~ - rgb_dec565(scbar) , //bar~ - rgb_dec565(sctMainTextAlt) , //tMainTextAlt - rgb_dec565(sctTimeAdd) //tTimeAdd + 'color', + scrSvrBGCol, //background + rgb_dec565(sctime), //time + rgb_dec565(sctimeAMPM), //timeAMPM~ + rgb_dec565(scdate), //date~ + rgb_dec565(sctMainText), //tMainText~ + rgb_dec565(sctForecast1), //tForecast1~ + rgb_dec565(sctForecast2), //tForecast2~ + rgb_dec565(sctForecast3), //tForecast3~ + rgb_dec565(sctForecast4), //tForecast4~ + rgb_dec565(sctForecast1Val), //tForecast1Val~ + rgb_dec565(sctForecast2Val), //tForecast2Val~ + rgb_dec565(sctForecast3Val), //tForecast3Val~ + rgb_dec565(sctForecast4Val), //tForecast4Val~ + rgb_dec565(scbar), //bar~ + rgb_dec565(sctMainTextAlt), //tMainTextAlt + rgb_dec565(sctTimeAdd) //tTimeAdd ); SendToPanel({ payload: payloadString }); } catch (err: any) { - log('error at function HandleScreensaverColors: '+ err.message, 'warn'); + log('error at function HandleScreensaverColors: ' + err.message, 'warn'); } } @@ -9265,33 +10038,33 @@ function GetScreenSaverEntityColor(configElement: NSPanel.ScreenSaverElement | n if (configElement && configElement.ScreensaverEntityIconColor != undefined) { const ScreensaverEntityIconColor = configElement.ScreensaverEntityIconColor as NSPanel.IconScaleElement; if (typeof getState(configElement.ScreensaverEntity).val == 'boolean') { - let iconvalbest = (typeof ScreensaverEntityIconColor == 'object' && ScreensaverEntityIconColor.val_best !== undefined ) ? ScreensaverEntityIconColor.val_best : false ; - colorReturn = (getState(configElement.ScreensaverEntity).val == iconvalbest) ? rgb_dec565(colorScale0) : rgb_dec565(colorScale10); + let iconvalbest = typeof ScreensaverEntityIconColor == 'object' && ScreensaverEntityIconColor.val_best !== undefined ? ScreensaverEntityIconColor.val_best : false; + colorReturn = getState(configElement.ScreensaverEntity).val == iconvalbest ? rgb_dec565(colorScale0) : rgb_dec565(colorScale10); } else if (typeof ScreensaverEntityIconColor == 'object') { - const iconvalmin: number = ScreensaverEntityIconColor.val_min != undefined ? ScreensaverEntityIconColor.val_min : 0 ; - const iconvalmax: number = ScreensaverEntityIconColor.val_max != undefined ? ScreensaverEntityIconColor.val_max : 100 ; - const iconvalbest: number = ScreensaverEntityIconColor.val_best != undefined ? ScreensaverEntityIconColor.val_best : iconvalmin ; + const iconvalmin: number = ScreensaverEntityIconColor.val_min != undefined ? ScreensaverEntityIconColor.val_min : 0; + const iconvalmax: number = ScreensaverEntityIconColor.val_max != undefined ? ScreensaverEntityIconColor.val_max : 100; + const iconvalbest: number = ScreensaverEntityIconColor.val_best != undefined ? ScreensaverEntityIconColor.val_best : iconvalmin; let valueScale = getState(configElement.ScreensaverEntity).val * configElement.ScreensaverEntityFactor!; if (iconvalmin == 0 && iconvalmax == 1) { - colorReturn = (getState(configElement.ScreensaverEntity).val == 1) ? rgb_dec565(colorScale0) : rgb_dec565(colorScale10); + colorReturn = getState(configElement.ScreensaverEntity).val == 1 ? rgb_dec565(colorScale0) : rgb_dec565(colorScale10); } else { if (iconvalbest == iconvalmin) { - valueScale = scale(valueScale,iconvalmin, iconvalmax, 10, 0); + valueScale = scale(valueScale, iconvalmin, iconvalmax, 10, 0); } else { if (valueScale < iconvalbest) { - valueScale = scale(valueScale,iconvalmin, iconvalbest, 0, 10); + valueScale = scale(valueScale, iconvalmin, iconvalbest, 0, 10); } else if (valueScale > iconvalbest || iconvalbest != iconvalmin) { - valueScale = scale(valueScale,iconvalbest, iconvalmax, 10, 0); + valueScale = scale(valueScale, iconvalbest, iconvalmax, 10, 0); } else { - valueScale = scale(valueScale,iconvalmin, iconvalmax, 10, 0); + valueScale = scale(valueScale, iconvalmin, iconvalmax, 10, 0); } } //limit if valueScale is smaller/larger than 0-10 if (valueScale > 10) valueScale = 10; if (valueScale < 0) valueScale = 0; - let valueScaletemp = (Math.round(valueScale)).toFixed(); + let valueScaletemp = Math.round(valueScale).toFixed(); colorReturn = HandleColorScale(valueScaletemp); } if (ScreensaverEntityIconColor.val_min == undefined) { @@ -9322,7 +10095,7 @@ function GetScreenSaverEntityColor(configElement: NSPanel.ScreenSaverElement | n } return colorReturn; } catch (err: any) { - log('error at function GetScreenSaverEntityColor: '+ err.message, 'warn'); + log('error at function GetScreenSaverEntityColor: ' + err.message, 'warn'); } return rgb_dec565(White); } @@ -9330,161 +10103,161 @@ function GetScreenSaverEntityColor(configElement: NSPanel.ScreenSaverElement | n function GetAccuWeatherIcon(icon: number): string { try { switch (icon) { - case 30: // Hot + case 30: // Hot return 'weather-sunny-alert'; // exceptional - case 24: // Ice - case 31: // Cold - return 'snowflake-alert'; // exceptional + case 24: // Ice + case 31: // Cold + return 'snowflake-alert'; // exceptional - case 7: // Cloudy - case 8: // Dreary (Overcast) - case 38: // Mostly Cloudy - return 'weather-cloudy'; // cloudy + case 7: // Cloudy + case 8: // Dreary (Overcast) + case 38: // Mostly Cloudy + return 'weather-cloudy'; // cloudy - case 11: // fog - return 'weather-fog'; // fog + case 11: // fog + return 'weather-fog'; // fog - case 25: // Sleet - return 'weather-hail'; // Hail + case 25: // Sleet + return 'weather-hail'; // Hail - case 15: // T-Storms - return 'weather-lightning'; // lightning + case 15: // T-Storms + return 'weather-lightning'; // lightning - case 16: // Mostly Cloudy w/ T-Storms - case 17: // Partly Sunny w/ T-Storms - case 41: // Partly Cloudy w/ T-Storms - case 42: // Mostly Cloudy w/ T-Storms - return 'weather-lightning-rainy'; // lightning-rainy + case 16: // Mostly Cloudy w/ T-Storms + case 17: // Partly Sunny w/ T-Storms + case 41: // Partly Cloudy w/ T-Storms + case 42: // Mostly Cloudy w/ T-Storms + return 'weather-lightning-rainy'; // lightning-rainy - case 33: // Clear - case 34: // Mostly Clear - case 37: // Hazy Moonlight + case 33: // Clear + case 34: // Mostly Clear + case 37: // Hazy Moonlight return 'weather-night'; - case 3: // Partly Sunny - case 4: // Intermittent Clouds - case 6: // Mostly Cloudy - case 35: // Partly Cloudy - case 36: // Intermittent Clouds - return 'weather-partly-cloudy'; // partlycloudy + case 3: // Partly Sunny + case 4: // Intermittent Clouds + case 6: // Mostly Cloudy + case 35: // Partly Cloudy + case 36: // Intermittent Clouds + return 'weather-partly-cloudy'; // partlycloudy - case 18: // pouring - return 'weather-pouring'; // pouring + case 18: // pouring + return 'weather-pouring'; // pouring - case 12: // Showers - case 13: // Mostly Cloudy w/ Showers - case 14: // Partly Sunny w/ Showers - case 26: // Freezing Rain - case 39: // Partly Cloudy w/ Showers - case 40: // Mostly Cloudy w/ Showers - return 'weather-rainy'; // rainy + case 12: // Showers + case 13: // Mostly Cloudy w/ Showers + case 14: // Partly Sunny w/ Showers + case 26: // Freezing Rain + case 39: // Partly Cloudy w/ Showers + case 40: // Mostly Cloudy w/ Showers + return 'weather-rainy'; // rainy - case 19: // Flurries - case 20: // Mostly Cloudy w/ Flurries - case 21: // Partly Sunny w/ Flurries - case 22: // Snow - case 23: // Mostly Cloudy w/ Snow - case 43: // Mostly Cloudy w/ Flurries - case 44: // Mostly Cloudy w/ Snow - return 'weather-snowy'; // snowy + case 19: // Flurries + case 20: // Mostly Cloudy w/ Flurries + case 21: // Partly Sunny w/ Flurries + case 22: // Snow + case 23: // Mostly Cloudy w/ Snow + case 43: // Mostly Cloudy w/ Flurries + case 44: // Mostly Cloudy w/ Snow + return 'weather-snowy'; // snowy - case 29: // Rain and Snow - return 'weather-snowy-rainy'; // snowy-rainy + case 29: // Rain and Snow + return 'weather-snowy-rainy'; // snowy-rainy - case 1: // Sunny - case 2: // Mostly Sunny - case 5: // Hazy Sunshine - return 'weather-sunny'; // sunny + case 1: // Sunny + case 2: // Mostly Sunny + case 5: // Hazy Sunshine + return 'weather-sunny'; // sunny - case 32: // windy - return 'weather-windy'; // windy + case 32: // windy + return 'weather-windy'; // windy default: return 'alert-circle-outline'; } } catch (err: any) { - log('error at function GetAccuWeatherIcon: '+ err.message, 'warn'); + log('error at function GetAccuWeatherIcon: ' + err.message, 'warn'); } return ''; } function GetAccuWeatherIconColor(icon: number): number { - try{ + try { switch (icon) { - case 24: // Ice - case 30: // Hot - case 31: // Cold - return rgb_dec565(swExceptional); // exceptional + case 24: // Ice + case 30: // Hot + case 31: // Cold + return rgb_dec565(swExceptional); // exceptional - case 7: // Cloudy - case 8: // Dreary (Overcast) - case 38: // Mostly Cloudy - return rgb_dec565(swCloudy); // cloudy + case 7: // Cloudy + case 8: // Dreary (Overcast) + case 38: // Mostly Cloudy + return rgb_dec565(swCloudy); // cloudy - case 11: // fog - return rgb_dec565(swFog); // fog + case 11: // fog + return rgb_dec565(swFog); // fog - case 25: // Sleet - return rgb_dec565(swHail); // Hail + case 25: // Sleet + return rgb_dec565(swHail); // Hail - case 15: // T-Storms - return rgb_dec565(swLightning); // lightning + case 15: // T-Storms + return rgb_dec565(swLightning); // lightning - case 16: // Mostly Cloudy w/ T-Storms - case 17: // Partly Sunny w/ T-Storms - case 41: // Partly Cloudy w/ T-Storms - case 42: // Mostly Cloudy w/ T-Storms - return rgb_dec565(swLightningRainy); // lightning-rainy + case 16: // Mostly Cloudy w/ T-Storms + case 17: // Partly Sunny w/ T-Storms + case 41: // Partly Cloudy w/ T-Storms + case 42: // Mostly Cloudy w/ T-Storms + return rgb_dec565(swLightningRainy); // lightning-rainy - case 33: // Clear - case 34: // Mostly Clear - case 37: // Hazy Moonlight + case 33: // Clear + case 34: // Mostly Clear + case 37: // Hazy Moonlight return rgb_dec565(swClearNight); - case 3: // Partly Sunny - case 4: // Intermittent Clouds - case 6: // Mostly Cloudy - case 35: // Partly Cloudy - case 36: // Intermittent Clouds - return rgb_dec565(swPartlycloudy); // partlycloudy + case 3: // Partly Sunny + case 4: // Intermittent Clouds + case 6: // Mostly Cloudy + case 35: // Partly Cloudy + case 36: // Intermittent Clouds + return rgb_dec565(swPartlycloudy); // partlycloudy - case 18: // pouring - return rgb_dec565(swPouring); // pouring + case 18: // pouring + return rgb_dec565(swPouring); // pouring - case 12: // Showers - case 13: // Mostly Cloudy w/ Showers - case 14: // Partly Sunny w/ Showers - case 26: // Freezing Rain - case 39: // Partly Cloudy w/ Showers - case 40: // Mostly Cloudy w/ Showers - return rgb_dec565(swRainy); // rainy + case 12: // Showers + case 13: // Mostly Cloudy w/ Showers + case 14: // Partly Sunny w/ Showers + case 26: // Freezing Rain + case 39: // Partly Cloudy w/ Showers + case 40: // Mostly Cloudy w/ Showers + return rgb_dec565(swRainy); // rainy - case 19: // Flurries - case 20: // Mostly Cloudy w/ Flurries - case 21: // Partly Sunny w/ Flurries - case 22: // Snow - case 23: // Mostly Cloudy w/ Snow - case 43: // Mostly Cloudy w/ Flurries - case 44: // Mostly Cloudy w/ Snow - return rgb_dec565(swSnowy); // snowy + case 19: // Flurries + case 20: // Mostly Cloudy w/ Flurries + case 21: // Partly Sunny w/ Flurries + case 22: // Snow + case 23: // Mostly Cloudy w/ Snow + case 43: // Mostly Cloudy w/ Flurries + case 44: // Mostly Cloudy w/ Snow + return rgb_dec565(swSnowy); // snowy - case 29: // Rain and Snow - return rgb_dec565(swSnowyRainy); // snowy-rainy + case 29: // Rain and Snow + return rgb_dec565(swSnowyRainy); // snowy-rainy - case 1: // Sunny - case 2: // Mostly Sunny - case 5: // Hazy Sunshine - return rgb_dec565(swSunny); // sunny + case 1: // Sunny + case 2: // Mostly Sunny + case 5: // Hazy Sunshine + return rgb_dec565(swSunny); // sunny - case 32: // windy - return rgb_dec565(swWindy); // windy + case 32: // windy + return rgb_dec565(swWindy); // windy default: return rgb_dec565(White); } } catch (err: any) { - log('error at function GetAccuWeatherIconColor: '+ err.message, 'warn'); + log('error at function GetAccuWeatherIconColor: ' + err.message, 'warn'); } return 0; } @@ -9492,119 +10265,119 @@ function GetAccuWeatherIconColor(icon: number): number { function GetDasWetterIcon(icon: number): string { try { switch (icon) { - case 1: // Sonnig - return 'weather-sunny'; // sunny - - case 2: // Teils bewölkt - case 3: // Bewölkt - return 'weather-partly-cloudy'; // partlycloudy - - case 4: // Bedeckt - return 'weather-cloudy'; // cloudy - - case 5: // Teils bewölkt mit leichtem Regen - case 6: // Bewölkt mit leichtem Regen - case 8: // Teils bewölkt mit mäßigem Regen - case 9: // Bewölkt mit mäßigem Regen - return 'weather-partly-rainy'; // partly-rainy - - case 7: // Bedeckt mit leichtem Regen - return 'weather-rainy'; // rainy - - case 10: // Bedeckt mit mäßigem Regen - return 'weather-pouring'; // pouring - - case 11: // Teils bewölkt mit starken Regenschauern - case 12: // Bewölkt mit stürmischen Regenschauern - return 'weather-partly-lightning'; // partlylightning - - case 13: // Bedeckt mit stürmischen Regenschauern - return 'weather-lightning'; // lightning - - case 14: // Teils bewölkt mit stürmischen Regenschauern und Hagel - case 15: // Bewölkt mit stürmischen Regenschauern und Hagel - case 16: // Bedeckt mit stürmischen Regenschauern und Hagel - return 'weather-hail'; // Hail - - case 17: // Teils bewölkt mit Schnee - case 18: // Bewölkt mit Schnee - return 'weather-partly-snowy'; // partlysnowy - - case 19: // Bedeckt mit Schneeschauern - return 'weather-snowy'; // snowy - - case 20: // Teils bewölkt mit Schneeregen - case 21: // Bewölkt mit Schneeregen + case 1: // Sonnig + return 'weather-sunny'; // sunny + + case 2: // Teils bewölkt + case 3: // Bewölkt + return 'weather-partly-cloudy'; // partlycloudy + + case 4: // Bedeckt + return 'weather-cloudy'; // cloudy + + case 5: // Teils bewölkt mit leichtem Regen + case 6: // Bewölkt mit leichtem Regen + case 8: // Teils bewölkt mit mäßigem Regen + case 9: // Bewölkt mit mäßigem Regen + return 'weather-partly-rainy'; // partly-rainy + + case 7: // Bedeckt mit leichtem Regen + return 'weather-rainy'; // rainy + + case 10: // Bedeckt mit mäßigem Regen + return 'weather-pouring'; // pouring + + case 11: // Teils bewölkt mit starken Regenschauern + case 12: // Bewölkt mit stürmischen Regenschauern + return 'weather-partly-lightning'; // partlylightning + + case 13: // Bedeckt mit stürmischen Regenschauern + return 'weather-lightning'; // lightning + + case 14: // Teils bewölkt mit stürmischen Regenschauern und Hagel + case 15: // Bewölkt mit stürmischen Regenschauern und Hagel + case 16: // Bedeckt mit stürmischen Regenschauern und Hagel + return 'weather-hail'; // Hail + + case 17: // Teils bewölkt mit Schnee + case 18: // Bewölkt mit Schnee + return 'weather-partly-snowy'; // partlysnowy + + case 19: // Bedeckt mit Schneeschauern + return 'weather-snowy'; // snowy + + case 20: // Teils bewölkt mit Schneeregen + case 21: // Bewölkt mit Schneeregen return 'weather-partly-snowy-rainy'; - - case 22: // Bedeckt mit Schneeregen - return 'weather-snowy-rainy'; // snowy-rainy - + + case 22: // Bedeckt mit Schneeregen + return 'weather-snowy-rainy'; // snowy-rainy + default: return 'alert-circle-outline'; } } catch (err: any) { - log('error at function GetDasWetterIcon: '+ err.message, 'warn'); + log('error at function GetDasWetterIcon: ' + err.message, 'warn'); } return ''; } - + function GetDasWetterIconColor(icon: number): number { - try{ + try { switch (icon) { - case 1: // Sonnig + case 1: // Sonnig return rgb_dec565(swSunny); - - case 2: // Teils bewölkt - case 3: // Bewölkt + + case 2: // Teils bewölkt + case 3: // Bewölkt return rgb_dec565(swPartlycloudy); - - case 4: // Bedeckt + + case 4: // Bedeckt return rgb_dec565(swCloudy); - - case 5: // Teils bewölkt mit leichtem Regen - case 6: // Bewölkt mit leichtem Regen - case 8: // Teils bewölkt mit mäßigem Regen - case 9: // Bewölkt mit mäßigem Regen + + case 5: // Teils bewölkt mit leichtem Regen + case 6: // Bewölkt mit leichtem Regen + case 8: // Teils bewölkt mit mäßigem Regen + case 9: // Bewölkt mit mäßigem Regen return rgb_dec565(swRainy); - - case 7: // Bedeckt mit leichtem Regen + + case 7: // Bedeckt mit leichtem Regen return rgb_dec565(swRainy); - - case 10: // Bedeckt mit mäßigem Regen + + case 10: // Bedeckt mit mäßigem Regen return rgb_dec565(swPouring); - - case 11: // Teils bewölkt mit starken Regenschauern - case 12: // Bewölkt mit stürmischen Regenschauern + + case 11: // Teils bewölkt mit starken Regenschauern + case 12: // Bewölkt mit stürmischen Regenschauern return rgb_dec565(swLightningRainy); - - case 13: // Bedeckt mit stürmischen Regenschauern + + case 13: // Bedeckt mit stürmischen Regenschauern return rgb_dec565(swLightning); - - case 14: // Teils bewölkt mit stürmischen Regenschauern und Hagel - case 15: // Bewölkt mit stürmischen Regenschauern und Hagel - case 16: // Bedeckt mit stürmischen Regenschauern und Hagel + + case 14: // Teils bewölkt mit stürmischen Regenschauern und Hagel + case 15: // Bewölkt mit stürmischen Regenschauern und Hagel + case 16: // Bedeckt mit stürmischen Regenschauern und Hagel return rgb_dec565(swHail); - - case 17: // Teils bewölkt mit Schnee - case 18: // Bewölkt mit Schnee + + case 17: // Teils bewölkt mit Schnee + case 18: // Bewölkt mit Schnee return rgb_dec565(swSnowy); - - case 19: // Bedeckt mit Schneeschauern + + case 19: // Bedeckt mit Schneeschauern return rgb_dec565(swSnowy); - - case 20: // Teils bewölkt mit Schneeregen - case 21: // Bewölkt mit Schneeregen - return rgb_dec565(swSnowyRainy); // snowy-rainy - - case 22: // Bedeckt mit Schneeregen + + case 20: // Teils bewölkt mit Schneeregen + case 21: // Bewölkt mit Schneeregen + return rgb_dec565(swSnowyRainy); // snowy-rainy + + case 22: // Bedeckt mit Schneeregen return rgb_dec565(swSnowyRainy); - + default: return rgb_dec565(White); } } catch (err: any) { - log('error at function GetDasWetterIconColor: '+ err.message, 'warn'); + log('error at function GetDasWetterIconColor: ' + err.message, 'warn'); } return 0; } @@ -9617,44 +10390,44 @@ on({ id: config.panelRecvTopic.substring(0, config.panelRecvTopic.length - 'RESU await createStateAsync(NSPanel_Path + 'Sensor.Time', { type: 'string', write: false }); await createStateAsync(NSPanel_Path + 'Sensor.TempUnit', { type: 'string', write: false }); - await createStateAsync(NSPanel_Path + 'Sensor.ANALOG.Temperature', { type: 'number', 'unit': '°C', write: false }); - await createStateAsync(NSPanel_Path + 'Sensor.ESP32.Temperature', { type: 'number', 'unit': '°C', write: false }); + await createStateAsync(NSPanel_Path + 'Sensor.ANALOG.Temperature', { type: 'number', unit: '°C', write: false }); + await createStateAsync(NSPanel_Path + 'Sensor.ESP32.Temperature', { type: 'number', unit: '°C', write: false }); let dateTime: string = Tasmota_Sensor.Time.split('T'); - await setStateAsync(NSPanel_Path + 'Sensor.Time', { val: dateTime[0] + '\r\n' + dateTime[1] , ack: true }); + await setStateAsync(NSPanel_Path + 'Sensor.Time', { val: dateTime[0] + '\r\n' + dateTime[1], ack: true }); await setStateAsync(NSPanel_Path + 'Sensor.TempUnit', { val: '°' + Tasmota_Sensor.TempUnit, ack: true }); - + /* Some messages do not include temperature values, so catch ecxeption for them separately */ try { await setStateAsync(NSPanel_Path + 'Sensor.ANALOG.Temperature', { val: parseFloat(Tasmota_Sensor.ANALOG.Temperature1), ack: true }); await setStateAsync(NSPanel_Path + 'Sensor.ESP32.Temperature', { val: parseFloat(Tasmota_Sensor.ESP32.Temperature), ack: true }); - } catch (e){ + } catch (e) { /* Nothing to do */ } - + if (autoCreateAlias) { - setObject(AliasPath + 'Sensor.ANALOG.Temperature', {type: 'channel', common: {role: 'info', name: ''}, native: {}}); - setObject(AliasPath + 'Sensor.ESP32.Temperature', {type: 'channel', common: {role: 'info', name:''}, native: {}}); - setObject(AliasPath + 'Sensor.Time', {type: 'channel', common: {role: 'info', name:''}, native: {}}); - setObject(AliasPath + 'Sensor.TempUnit', {type: 'channel', common: {role: 'info', name:''}, native: {}}); - await createAliasAsync(AliasPath + 'Sensor.ANALOG.Temperature.ACTUAL', NSPanel_Path + 'Sensor.ANALOG.Temperature', true, { type: 'number', 'unit': '°C' }); - await createAliasAsync(AliasPath + 'Sensor.ESP32.Temperature.ACTUAL', NSPanel_Path + 'Sensor.ESP32.Temperature', true, { type: 'number', 'unit': '°C' }); + setObject(AliasPath + 'Sensor.ANALOG.Temperature', { type: 'channel', common: { role: 'info', name: '' }, native: {} }); + setObject(AliasPath + 'Sensor.ESP32.Temperature', { type: 'channel', common: { role: 'info', name: '' }, native: {} }); + setObject(AliasPath + 'Sensor.Time', { type: 'channel', common: { role: 'info', name: '' }, native: {} }); + setObject(AliasPath + 'Sensor.TempUnit', { type: 'channel', common: { role: 'info', name: '' }, native: {} }); + await createAliasAsync(AliasPath + 'Sensor.ANALOG.Temperature.ACTUAL', NSPanel_Path + 'Sensor.ANALOG.Temperature', true, { type: 'number', unit: '°C' }); + await createAliasAsync(AliasPath + 'Sensor.ESP32.Temperature.ACTUAL', NSPanel_Path + 'Sensor.ESP32.Temperature', true, { type: 'number', unit: '°C' }); await createAliasAsync(AliasPath + 'Sensor.Time.ACTUAL', NSPanel_Path + 'Sensor.Time', true, { type: 'string' }); await createAliasAsync(AliasPath + 'Sensor.TempUnit.ACTUAL', NSPanel_Path + 'Sensor.TempUnit', true, { type: 'string' }); } } catch (err: any) { - log('error Trigger reading senor-data: '+ err.message, 'warn'); + log('error Trigger reading senor-data: ' + err.message, 'warn'); } }); //------------------End Read Internal Sensor Data -function formatInSelText(Text: string ): string { +function formatInSelText(Text: string): string { let splitText = Text.split(' '); let lengthLineOne = 0; let arrayLineOne: string[] = []; for (let i = 0; i < splitText.length; i++) { lengthLineOne = lengthLineOne + splitText[i].length + 1; if (lengthLineOne > 12) { - break; + break; } else { arrayLineOne[i] = splitText[i]; } @@ -9662,11 +10435,11 @@ function formatInSelText(Text: string ): string { let textLineOne = arrayLineOne.join(' '); let arrayLineTwo: string[] = []; for (let i = arrayLineOne.length; i < splitText.length; i++) { - arrayLineTwo[i] = splitText[i]; + arrayLineTwo[i] = splitText[i]; } let textLineTwo = arrayLineTwo.join(' '); if (textLineTwo.length > 12) { - textLineTwo = textLineTwo.substring(0,9) + '...'; + textLineTwo = textLineTwo.substring(0, 9) + '...'; } if (textLineOne.length != 0) { return textLineOne + '\r\n' + textLineTwo.trim(); @@ -9696,7 +10469,7 @@ function InterpolateNum(d1: number, d2: number, fraction: number): number { function rgb_dec565(rgb: RGB): number { //return ((Math.floor(rgb.red / 255 * 31) << 11) | (Math.floor(rgb.green / 255 * 63) << 5) | (Math.floor(rgb.blue / 255 * 31))); - return ((rgb.red >> 3) << 11) | ((rgb.green >> 2)) << 5 | ((rgb.blue) >> 3); + return ((rgb.red >> 3) << 11) | ((rgb.green >> 2) << 5) | (rgb.blue >> 3); } /** @@ -9705,7 +10478,7 @@ function rgb_dec565(rgb: RGB): number { * @returns {number} degrees equivalent of rad */ function rad2deg(rad): number { - return (360 + 180 * rad / Math.PI) % 360; + return (360 + (180 * rad) / Math.PI) % 360; } function ColorToHex(color): string { @@ -9728,18 +10501,12 @@ function hsv2rgb(hue: number, saturation: number, value: number): [number, numbe hue /= 60; let chroma = value * saturation; let x = chroma * (1 - Math.abs((hue % 2) - 1)); - let rgb: [number, number, number] = hue <= 1 ? [chroma, x, 0] : - hue <= 2 ? [x, chroma, 0] : - hue <= 3 ? [0, chroma, x] : - hue <= 4 ? [0, x, chroma] : - hue <= 5 ? [x, 0, chroma] : - [chroma, 0, x]; + let rgb: [number, number, number] = hue <= 1 ? [chroma, x, 0] : hue <= 2 ? [x, chroma, 0] : hue <= 3 ? [0, chroma, x] : hue <= 4 ? [0, x, chroma] : hue <= 5 ? [x, 0, chroma] : [chroma, 0, x]; - return rgb.map(v => (v + value - chroma) * 255) as [number, number, number]; + return rgb.map((v) => (v + value - chroma) * 255) as [number, number, number]; } function getHue(red: number, green: number, blue: number): number { - let min = Math.min(Math.min(red, green), blue); let max = Math.max(Math.max(red, green), blue); @@ -9750,10 +10517,8 @@ function getHue(red: number, green: number, blue: number): number { let hue = 0; if (max == red) { hue = (green - blue) / (max - min); - } else if (max == green) { hue = 2 + (blue - red) / (max - min); - } else { hue = 4 + (red - green) / (max - min); } @@ -9766,11 +10531,11 @@ function getHue(red: number, green: number, blue: number): number { function pos_to_color(x: number, y: number): RGB { let r = 160 / 2; - x = Math.round((x - r) / r * 100) / 100; - y = Math.round((r - y) / r * 100) / 100; + x = Math.round(((x - r) / r) * 100) / 100; + y = Math.round(((r - y) / r) * 100) / 100; r = Math.sqrt(x * x + y * y); - let sat = 0 + let sat = 0; if (r > 1) { sat = 0; } else { @@ -9784,42 +10549,41 @@ function pos_to_color(x: number, y: number): RGB { } /** - * - * @param red - * @param green - * @param blue - * @returns + * + * @param red + * @param green + * @param blue + * @returns */ -function rgb_to_cie(red: number, green: number, blue: number): string -{ - //Apply a gamma correction to the RGB values, which makes the color more vivid and more the like the color displayed on the screen of your device - let vred = (red > 0.04045) ? Math.pow((red + 0.055) / (1.0 + 0.055), 2.4) : (red / 12.92); - let vgreen = (green > 0.04045) ? Math.pow((green + 0.055) / (1.0 + 0.055), 2.4) : (green / 12.92); - let vblue = (blue > 0.04045) ? Math.pow((blue + 0.055) / (1.0 + 0.055), 2.4) : (blue / 12.92); +function rgb_to_cie(red: number, green: number, blue: number): string { + //Apply a gamma correction to the RGB values, which makes the color more vivid and more the like the color displayed on the screen of your device + let vred = red > 0.04045 ? Math.pow((red + 0.055) / (1.0 + 0.055), 2.4) : red / 12.92; + let vgreen = green > 0.04045 ? Math.pow((green + 0.055) / (1.0 + 0.055), 2.4) : green / 12.92; + let vblue = blue > 0.04045 ? Math.pow((blue + 0.055) / (1.0 + 0.055), 2.4) : blue / 12.92; - //RGB values to XYZ using the Wide RGB D65 conversion formula - let X = vred * 0.664511 + vgreen * 0.154324 + vblue * 0.162028; - let Y = vred * 0.283881 + vgreen * 0.668433 + vblue * 0.047685; - let Z = vred * 0.000088 + vgreen * 0.072310 + vblue * 0.986039; + //RGB values to XYZ using the Wide RGB D65 conversion formula + let X = vred * 0.664511 + vgreen * 0.154324 + vblue * 0.162028; + let Y = vred * 0.283881 + vgreen * 0.668433 + vblue * 0.047685; + let Z = vred * 0.000088 + vgreen * 0.07231 + vblue * 0.986039; - //Calculate the xy values from the XYZ values - let ciex = (X / (X + Y + Z)).toFixed(4); - let ciey = (Y / (X + Y + Z)).toFixed(4); - let cie = "[" + ciex + "," + ciey + "]" + //Calculate the xy values from the XYZ values + let ciex = (X / (X + Y + Z)).toFixed(4); + let ciey = (Y / (X + Y + Z)).toFixed(4); + let cie = '[' + ciex + ',' + ciey + ']'; - return cie; + return cie; } /** * - * @param vDeviceString - * @returns + * @param vDeviceString + * @returns */ function spotifyGetDeviceID(vDeviceString: string): string { - const availableDeviceIDs: string = getState("spotify-premium.0.devices.availableDeviceListIds").val; - const availableDeviceNames: string = getState("spotify-premium.0.devices.availableDeviceListString").val; - let arrayDeviceListIds: string[] = availableDeviceIDs.split(";"); - let arrayDeviceListSting: string[] = availableDeviceNames.split(";"); + const availableDeviceIDs: string = getState('spotify-premium.0.devices.availableDeviceListIds').val; + const availableDeviceNames: string = getState('spotify-premium.0.devices.availableDeviceListString').val; + let arrayDeviceListIds: string[] = availableDeviceIDs.split(';'); + let arrayDeviceListSting: string[] = availableDeviceNames.split(';'); let indexPos: number = arrayDeviceListSting.indexOf(vDeviceString); let strDevID = arrayDeviceListIds[indexPos]; return strDevID; @@ -9827,9 +10591,9 @@ function spotifyGetDeviceID(vDeviceString: string): string { /** * Join arguments with ~ and return the string; * @param tokens unlimited numbers of strings - * @returns + * @returns */ -function buildNSPanelString(...tokens: (string|number)[]): string { +function buildNSPanelString(...tokens: (string | number)[]): string { return tokens.join('~'); } @@ -9848,27 +10612,25 @@ type PageThermo = NSPanel.PageThermo; type PageUnlock = NSPanel.PageUnlock; type PageAlarm = NSPanel.PageAlarm; - - /** - * + * * @param time object { hour: number, minutes: number } | number: Time as number in ms * @param repeatTime in seconds * @param callback what todo - * @returns + * @returns */ -function adapterSchedule(time: {hour?: number, minute?: number} | undefined | number, repeatTime: number, callback: () => void): number|null { - if (typeof callback !== 'function') return null +function adapterSchedule(time: { hour?: number; minute?: number } | undefined | number, repeatTime: number, callback: () => void): number | null { + if (typeof callback !== 'function') return null; const ref = Math.random() + 1; - scheduleList[ref] = setTimeout(_schedule, 1, time, ref, repeatTime, callback), true; + (scheduleList[ref] = setTimeout(_schedule, 1, time, ref, repeatTime, callback)), true; return ref; } -function _schedule(time: {hour?: number, minute?: number} | undefined | number, ref: number, repeatTime: number, callback, init: boolean = false) { +function _schedule(time: { hour?: number; minute?: number } | undefined | number, ref: number, repeatTime: number, callback, init: boolean = false) { if (!scheduleList[ref]) return; if (!init) callback(); let targetTime: number; - if ( time === undefined) { + if (time === undefined) { targetTime = new Date().setMilliseconds(0) + repeatTime * 1000; time = targetTime; } else if (typeof time === 'number') { @@ -9890,11 +10652,11 @@ function _clearSchedule(ref: number): null { if (scheduleList[ref]) clearTimeout(scheduleList[ref]); delete scheduleList[ref]; return null; -} -const ArrayPlayerTypeWithMediaDevice = ['alexa2', 'sonos', 'squeezeboxrpc'] as const -const ArrayPlayerTypeWithOutMediaDevice = ['spotify-premium', 'volumio', 'bosesoundtouch'] as const +} +const ArrayPlayerTypeWithMediaDevice = ['alexa2', 'sonos', 'squeezeboxrpc'] as const; +const ArrayPlayerTypeWithOutMediaDevice = ['spotify-premium', 'volumio', 'bosesoundtouch'] as const; -function isPlayerWithMediaDevice (F: string | NSPanel._PlayerTypeWithMediaDevice): F is NSPanel._PlayerTypeWithMediaDevice { +function isPlayerWithMediaDevice(F: string | NSPanel._PlayerTypeWithMediaDevice): F is NSPanel._PlayerTypeWithMediaDevice { return ArrayPlayerTypeWithMediaDevice.indexOf(F as NSPanel._PlayerTypeWithMediaDevice) != -1; } /** check if NSPanel.adapterPlayerInstanceType has all Playertypes */ @@ -9903,30 +10665,30 @@ function checkSortedPlayerType(F: NSPanel.notSortedPlayerType) { } function isMediaOptional(F: string | NSPanel.mediaOptional): F is NSPanel.mediaOptional { - switch(F as NSPanel.mediaOptional) { - case "seek": - case "crossfade": - case "speakerlist": - case "playlist": - case "tracklist": - case "equalizer": - case "repeat": - case "favorites": + switch (F as NSPanel.mediaOptional) { + case 'seek': + case 'crossfade': + case 'speakerlist': + case 'playlist': + case 'tracklist': + case 'equalizer': + case 'repeat': + case 'favorites': return true; default: - return false + return false; } } function isEventMethod(F: string | NSPanel.EventMethod): F is NSPanel.EventMethod { - switch(F as NSPanel.EventMethod) { - case "startup": - case "sleepReached": - case "pageOpenDetail": - case "buttonPress2": - case "renderCurrentPage": - case "button1": - case "button2": + switch (F as NSPanel.EventMethod) { + case 'startup': + case 'sleepReached': + case 'pageOpenDetail': + case 'buttonPress2': + case 'renderCurrentPage': + case 'button1': + case 'button2': return true; default: // Have to talk about this. @@ -9936,15 +10698,15 @@ function isEventMethod(F: string | NSPanel.EventMethod): F is NSPanel.EventMetho } function isPopupType(F: NSPanel.PopupType | string): F is NSPanel.PopupType { - switch(F as NSPanel.PopupType) { - case "popupFan": - case "popupInSel": - case "popupLight": - case "popupLightNew": - case "popupNotify": - case "popupShutter": - case "popupThermo": - case "popupTimer": + switch (F as NSPanel.PopupType) { + case 'popupFan': + case 'popupInSel': + case 'popupLight': + case 'popupLightNew': + case 'popupNotify': + case 'popupShutter': + case 'popupThermo': + case 'popupTimer': return true; default: log(`Please report to developer: Unknown NSPanel.PopupType: ${F} `, 'warn'); @@ -9955,52 +10717,135 @@ function isPopupType(F: NSPanel.PopupType | string): F is NSPanel.PopupType { function checkPageType(F: NSPanel.PagetypeType, A: NSPanel.PageType) { A.type = F; } -function isPageMediaItem(F: NSPanel.PageItem | NSPanel.PageMediaItem):F is NSPanel.PageMediaItem { - return 'adapterPlayerInstance' in F +function isPageMediaItem(F: NSPanel.PageItem | NSPanel.PageMediaItem): F is NSPanel.PageMediaItem { + return 'adapterPlayerInstance' in F; } -function isPageThermoItem(F: PageItem | NSPanel.PageThermoItem):F is NSPanel.PageThermoItem { - return 'popupThermoMode1' in F; +function isPageThermoItem(F: PageItem | NSPanel.PageThermoItem): F is NSPanel.PageThermoItem { + return 'popupThermoMode1' in F; } -function isPageMedia(F: NSPanel.PageType | NSPanel.PageMedia):F is NSPanel.PageMedia { +function isPageMedia(F: NSPanel.PageType | NSPanel.PageMedia): F is NSPanel.PageMedia { return F.type == 'cardMedia'; } -function isPagePower(F: NSPanel.PageType | NSPanel.PagePower):F is NSPanel.PagePower { +function isPagePower(F: NSPanel.PageType | NSPanel.PagePower): F is NSPanel.PagePower { return F.type == 'cardPower'; } namespace NSPanel { - export type PopupType = 'popupFan' | 'popupInSel' | 'popupLight' | 'popupLightNew' | 'popupNotify' | 'popupShutter' | 'popupThermo' | 'popupTimer' + export type PopupType = 'popupFan' | 'popupInSel' | 'popupLight' | 'popupLightNew' | 'popupNotify' | 'popupShutter' | 'popupThermo' | 'popupTimer'; - - - export type EventMethod = 'startup' | 'sleepReached' | 'pageOpenDetail' | 'buttonPress2' | 'renderCurrentPage' | 'button1' | 'button2' + export type EventMethod = 'startup' | 'sleepReached' | 'pageOpenDetail' | 'buttonPress2' | 'renderCurrentPage' | 'button1' | 'button2'; export type panelRecvType = { event: 'event'; - method: EventMethod - } + method: EventMethod; + }; + export type SerialType = 'button' | 'light' | 'shutter' | 'text' | 'input_sel' | 'timer' | 'number' | 'fan'; - export type SerialType = 'button' | 'light' | 'shutter' | 'text' | 'input_sel' | 'timer' | 'number' | 'fan' - - export type roles = 'light' |'socket'|'dimmer'| 'hue' | 'rgb' | 'rgbSingle' | 'ct' | 'blind' | 'door' | 'window' | 'volumeGroup' | 'volume' - | 'info' | 'humidity' | 'temperature' | 'value.temperature' | 'value.humidity' | 'sensor.door' | 'sensor.window' | 'thermostat' | 'warning' - | 'cie' | 'gate' | 'motion' | 'buttonSensor' | 'button' | 'value.time' | 'level.timer' | 'value.alarmtime' | 'level.mode.fan' | 'lock' | 'slider' - | 'switch.mode.wlan' | 'media' | 'timeTable' | 'airCondition' - - export type ButtonActionType = 'bExit' | 'bUp' | 'bNext' | 'bSubNext' | 'bPrev' | 'bSubPrev' | 'bHome' | 'notifyAction' | 'OnOff' | 'button' | 'up' | 'stop' | 'down' - | 'positionSlider' | 'tiltOpen' | 'tiltStop' | 'tiltSlider' | 'tiltClose' | 'brightnessSlider' | 'colorTempSlider' | 'colorWheel' | 'tempUpd' | 'tempUpdHighLow' | 'media-back' - | 'media-pause' | 'media-next' | 'media-shuffle' | 'volumeSlider' | 'mode-speakerlist' | 'mode-playlist' | 'mode-tracklist' | 'mode-repeat' | 'mode-equalizer' | 'mode-seek' | 'mode-crossfade' - | 'mode-favorites' | 'mode-insel' | 'media-OnOff' | 'timer-start' | 'timer-pause' | 'timer-cancle' | 'timer-finish' | 'hvac_action' | 'mode-modus1' | 'mode-modus2' | 'mode-modus3' | 'number-set' - | 'mode-preset_modes' | 'A1' | 'A2' | 'A3' | 'A4' | 'D1' | 'U1' | 'f1Icon' | 'f2Icon' | 'f3Icon' | 'f4Icon' | 'f5Icon' - + export type roles = + | 'light' + | 'socket' + | 'dimmer' + | 'hue' + | 'rgb' + | 'rgbSingle' + | 'ct' + | 'blind' + | 'door' + | 'window' + | 'volumeGroup' + | 'volume' + | 'info' + | 'humidity' + | 'temperature' + | 'value.temperature' + | 'value.humidity' + | 'sensor.door' + | 'sensor.window' + | 'thermostat' + | 'warning' + | 'cie' + | 'gate' + | 'motion' + | 'buttonSensor' + | 'button' + | 'value.time' + | 'level.timer' + | 'value.alarmtime' + | 'level.mode.fan' + | 'lock' + | 'slider' + | 'switch.mode.wlan' + | 'media' + | 'timeTable' + | 'airCondition'; + export type ButtonActionType = + | 'bExit' + | 'bUp' + | 'bNext' + | 'bSubNext' + | 'bPrev' + | 'bSubPrev' + | 'bHome' + | 'notifyAction' + | 'OnOff' + | 'button' + | 'up' + | 'stop' + | 'down' + | 'positionSlider' + | 'tiltOpen' + | 'tiltStop' + | 'tiltSlider' + | 'tiltClose' + | 'brightnessSlider' + | 'colorTempSlider' + | 'colorWheel' + | 'tempUpd' + | 'tempUpdHighLow' + | 'media-back' + | 'media-pause' + | 'media-next' + | 'media-shuffle' + | 'volumeSlider' + | 'mode-speakerlist' + | 'mode-playlist' + | 'mode-tracklist' + | 'mode-repeat' + | 'mode-equalizer' + | 'mode-seek' + | 'mode-crossfade' + | 'mode-favorites' + | 'mode-insel' + | 'media-OnOff' + | 'timer-start' + | 'timer-pause' + | 'timer-cancle' + | 'timer-finish' + | 'hvac_action' + | 'mode-modus1' + | 'mode-modus2' + | 'mode-modus3' + | 'number-set' + | 'mode-preset_modes' + | 'A1' + | 'A2' + | 'A3' + | 'A4' + | 'D1' + | 'U1' + | 'f1Icon' + | 'f2Icon' + | 'f3Icon' + | 'f4Icon' + | 'f5Icon'; export type RGB = { - red: number, - green: number, - blue: number + red: number; + green: number; + blue: number; }; export type Payload = { @@ -10008,262 +10853,327 @@ namespace NSPanel { }; export type PageBaseType = { - type: PagetypeType, - uniqueName?: string, - heading: string, - items: PageItem[], - useColor: boolean, - subPage?: boolean, - parent?: PageType, - parentIcon?: string, - parentIconColor?: RGB, - prev?: string, - prevIcon?: string, - prevIconColor?: RGB, - next?: string, - nextIcon?: string, - nextIconColor?: RGB, - home?: string, - homeIcon?: string, - homeIconColor?: RGB + type: PagetypeType; + uniqueName?: string; + heading: string; + items: PageItem[]; + useColor: boolean; + subPage?: boolean; + parent?: PageType; + parentIcon?: string; + parentIconColor?: RGB; + prev?: string; + prevIcon?: string; + prevIconColor?: RGB; + next?: string; + nextIcon?: string; + nextIconColor?: RGB; + home?: string; + homeIcon?: string; + homeIconColor?: RGB; + hiddenByTrigger?: boolean; }; + export type PagetypeType = 'cardChart' | 'cardLChart' | 'cardEntities' | 'cardGrid' | 'cardGrid2' | 'cardThermo' | 'cardMedia' | 'cardUnlock' | 'cardQR' | 'cardAlarm' | 'cardPower'; //| 'cardBurnRec' - export type PagetypeType = 'cardChart' | 'cardLChart' | 'cardEntities' |'cardGrid'|'cardGrid2'|'cardThermo'|'cardMedia'|'cardUnlock'|'cardQR'|'cardAlarm'|'cardPower' //| 'cardBurnRec' - - export type PageType = PageChart | PageEntities | PageGrid | PageGrid2 | PageThermo | PageMedia | PageUnlock | PageQR | PageAlarm | PagePower + export type PageType = PageChart | PageEntities | PageGrid | PageGrid2 | PageThermo | PageMedia | PageUnlock | PageQR | PageAlarm | PagePower; export type PageEntities = { - type: 'cardEntities', - items: [PageItem?, PageItem?, PageItem?, PageItem?, PageItem?], - } & PageBaseType + type: 'cardEntities'; + items: [PageItem?, PageItem?, PageItem?, PageItem?, PageItem?]; + } & PageBaseType; export type PageGrid = { - type: 'cardGrid', - items: [PageItem?, PageItem?, PageItem?, PageItem?, PageItem?, PageItem?], - } & PageBaseType + type: 'cardGrid'; + items: [PageItem?, PageItem?, PageItem?, PageItem?, PageItem?, PageItem?]; + } & PageBaseType; export type PageGrid2 = { - type: 'cardGrid2', - items: [PageItem?, PageItem?, PageItem?, PageItem?, PageItem?, PageItem?, PageItem?, PageItem?, PageItem?], - } & PageBaseType + type: 'cardGrid2'; + items: [PageItem?, PageItem?, PageItem?, PageItem?, PageItem?, PageItem?, PageItem?, PageItem?, PageItem?]; + } & PageBaseType; export type PageThermo = { - type: 'cardThermo', - items: [PageThermoItem], - - } & Omit + type: 'cardThermo'; + items: [PageThermoItem]; + } & Omit; export type PageMedia = { - type: 'cardMedia', - items: [PageMediaItem], - } & Omit + type: 'cardMedia'; + items: [PageMediaItem]; + } & Omit; - export type PageAlarm = { - type: 'cardAlarm', - items: [PageItem], - } & Omit + type: 'cardAlarm'; + items: [PageItem]; + } & Omit; export type PageUnlock = { - type: 'cardUnlock', - items: [PageItem], - } & Omit & Partial> + type: 'cardUnlock'; + items: [PageItem]; + } & Omit & + Partial>; export type PageQR = { - type: 'cardQR', - items: [PageItem], - } & Omit + type: 'cardQR'; + items: [PageItem]; + } & Omit; export type PagePower = { - type: 'cardPower', - items: [PageItem], - } & Omit + type: 'cardPower'; + items: [PageItem]; + } & Omit; export type PageChart = { - type: 'cardChart' | 'cardLChart', - items: PageItem[], - } & Omit + type: 'cardChart' | 'cardLChart'; + items: PageItem[]; + } & Omit; - export type PageItem = PageBaseItem | PageMediaItem | PageThermoItem + export type PageItem = PageBaseItem | PageMediaItem | PageThermoItem; export type PageMediaItem = { - adapterPlayerInstance: adapterPlayerInstanceType, - mediaDevice?: string, - colorMediaIcon?: RGB, - colorMediaArtist?: RGB, - colorMediaTitle?: RGB, - speakerList?: string[], - playList?: string[], - equalizerList?: string[], - repeatList?: string[], - globalTracklist?: string[], - crossfade?: boolean, - } & PageBaseItem + adapterPlayerInstance: adapterPlayerInstanceType; + mediaDevice?: string; + colorMediaIcon?: RGB; + colorMediaArtist?: RGB; + colorMediaTitle?: RGB; + speakerList?: string[]; + playList?: string[]; + equalizerList?: string[]; + repeatList?: string[]; + globalTracklist?: string[]; + crossfade?: boolean; + } & PageBaseItem; - export type PageThermoItem = { - popupThermoMode1?: string[], - popupThermoMode2?: string[], - popupThermoMode3?: string[], - popUpThermoName?: string[], - setThermoAlias?: string[], - setThermoDestTemp2?: string, - } & PageBaseItem | - { - popupThermoMode1?: string[], - popupThermoMode2?: string[], - popupThermoMode3?: string[], - popUpThermoName?: string[], - setThermoAlias?: string[], - setThermoDestTemp2?: string, - } & PageBaseItem + export type PageThermoItem = + | ({ + popupThermoMode1?: string[]; + popupThermoMode2?: string[]; + popupThermoMode3?: string[]; + popUpThermoName?: string[]; + setThermoAlias?: string[]; + setThermoDestTemp2?: string; + } & PageBaseItem) + | ({ + popupThermoMode1?: string[]; + popupThermoMode2?: string[]; + popupThermoMode3?: string[]; + popUpThermoName?: string[]; + setThermoAlias?: string[]; + setThermoDestTemp2?: string; + } & PageBaseItem); // mean string start with getState(' and end with ').val type getStateID = string; export type PageBaseItem = { - uniqueName?: string, - role?: string, - id?: string | null, - icon?: string, - icon2?: string, - onColor?: RGB, - offColor?: RGB, - useColor?: boolean, - interpolateColor?: boolean, - minValueBrightness?: number, - maxValueBrightness?: number, - minValueColorTemp?: number, - maxValueColorTemp?: number, - minValueLevel?: number, - maxValueLevel?: number, - minValueTilt?: number, - maxValueTilt?: number, - minValue?: number, - maxValue?: number, - stepValue?: number, - prefixName?: string, - suffixName?: string, - name?: string | getStateID, - secondRow?: string, - buttonText?: string, - unit?: string, - navigate?: boolean, - colormode?: string, - colorScale?: IconScaleElement, - targetPage?: string, - modeList?: string[], - hidePassword?: boolean, - autoCreateALias?: boolean - yAxis?: string, - yAxisTicks?: number[] | string, - xAxisDecorationId?: string, - useValue?: boolean, - monobutton?: boolean, - inSel_ChoiceState?: boolean, - iconArray?: string[], - fontSize?: number, - actionStringArray?: string[], - alwaysOnDisplay?: boolean, - } + uniqueName?: string; + role?: string; + id?: string | null; + icon?: string; + icon2?: string; + onColor?: RGB; + offColor?: RGB; + useColor?: boolean; + interpolateColor?: boolean; + minValueBrightness?: number; + maxValueBrightness?: number; + minValueColorTemp?: number; + maxValueColorTemp?: number; + minValueLevel?: number; + maxValueLevel?: number; + minValueTilt?: number; + maxValueTilt?: number; + minValue?: number; + maxValue?: number; + stepValue?: number; + prefixName?: string; + suffixName?: string; + name?: string | getStateID; + secondRow?: string; + buttonText?: string; + unit?: string; + navigate?: boolean; + colormode?: string; + colorScale?: IconScaleElement; + targetPage?: string; + modeList?: string[]; + hidePassword?: boolean; + autoCreateALias?: boolean; + yAxis?: string; + yAxisTicks?: number[] | string; + xAxisDecorationId?: string; + useValue?: boolean; + monobutton?: boolean; + inSel_ChoiceState?: boolean; + iconArray?: string[]; + fontSize?: number; + actionStringArray?: string[]; + alwaysOnDisplay?: boolean; + }; export type DimMode = { - dimmodeOn: (boolean | undefined), - brightnessDay: (number | undefined), - brightnessNight: (number | undefined), - timeDay: (string | undefined), - timeNight: (string | undefined) - } + dimmodeOn: boolean | undefined; + brightnessDay: number | undefined; + brightnessNight: number | undefined; + timeDay: string | undefined; + timeNight: string | undefined; + }; export type ConfigButtonFunction = { - mode: 'page' | 'toggle' | 'set' | null, - page: (PageThermo | PageMedia | PageAlarm | PageQR | PageEntities | PageGrid | PageGrid2 | PagePower | PageChart | PageUnlock | null), - entity: string | null, - setValue: string | number | boolean | null - setOn?: {dp:string, val:iobJS.StateValue} - setOff?: {dp:string, val:iobJS.StateValue}; - } + mode: 'page' | 'toggle' | 'set' | null; + page: PageThermo | PageMedia | PageAlarm | PageQR | PageEntities | PageGrid | PageGrid2 | PagePower | PageChart | PageUnlock | null; + entity: string | null; + setValue: string | number | boolean | null; + setOn?: { dp: string; val: iobJS.StateValue }; + setOff?: { dp: string; val: iobJS.StateValue }; + }; export type Config = { - panelRecvTopic: string, - panelSendTopic: string, - weatherEntity: string, - leftScreensaverEntity: leftScreensaverEntityType - bottomScreensaverEntity: ScreenSaverElement[], - indicatorScreensaverEntity: indicatorScreensaverEntityType - mrIcon1ScreensaverEntity: ScreenSaverMRElement, - mrIcon2ScreensaverEntity: ScreenSaverMRElement, - defaultColor: RGB, - defaultOnColor: RGB, - defaultOffColor: RGB, - defaultBackgroundColor: RGB, - pages: PageType[], - subPages: PageType[], - button1: ConfigButtonFunction, - button2: ConfigButtonFunction - } + panelRecvTopic: string; + panelSendTopic: string; + weatherEntity: string; + leftScreensaverEntity: leftScreensaverEntityType; + bottomScreensaverEntity: ScreenSaverElement[]; + indicatorScreensaverEntity: indicatorScreensaverEntityType; + mrIcon1ScreensaverEntity: ScreenSaverMRElement; + mrIcon2ScreensaverEntity: ScreenSaverMRElement; + defaultColor: RGB; + defaultOnColor: RGB; + defaultOffColor: RGB; + defaultBackgroundColor: RGB; + pages: PageType[]; + subPages: PageType[]; + button1: ConfigButtonFunction; + button2: ConfigButtonFunction; + }; export type leftScreensaverEntityType = [ScreenSaverElementWithUndefined, ScreenSaverElementWithUndefined, ScreenSaverElementWithUndefined] | []; - export type indicatorScreensaverEntityType = [ScreenSaverElementWithUndefined?, ScreenSaverElementWithUndefined?, ScreenSaverElementWithUndefined?, ScreenSaverElementWithUndefined?, ScreenSaverElementWithUndefined?] | []; - export type ScreenSaverElementWithUndefined = null | undefined | ScreenSaverElement + export type indicatorScreensaverEntityType = + | [ScreenSaverElementWithUndefined?, ScreenSaverElementWithUndefined?, ScreenSaverElementWithUndefined?, ScreenSaverElementWithUndefined?, ScreenSaverElementWithUndefined?] + | []; + export type ScreenSaverElementWithUndefined = null | undefined | ScreenSaverElement; export type ScreenSaverElement = { - ScreensaverEntity: string, - ScreensaverEntityText: string, - ScreensaverEntityFactor?: number, - ScreensaverEntityDecimalPlaces?: number, - ScreensaverEntityDateFormat?: Intl.DateTimeFormatOptions, - ScreensaverEntityIconOn?: string | null, - ScreensaverEntityIconOff?: string | null, - ScreensaverEntityUnitText?: string, - ScreensaverEntityIconColor?: RGB | IconScaleElement | string - ScreensaverEntityOnColor?: RGB - ScreensaverEntityOffColor?: RGB - ScreensaverEntityOnText?: string | null, - ScreensaverEntityOffText?: string | null, - ScreensaverEntityNaviToPage?: PageType - } + ScreensaverEntity: string; + ScreensaverEntityText: string; + ScreensaverEntityFactor?: number; + ScreensaverEntityDecimalPlaces?: number; + ScreensaverEntityDateFormat?: Intl.DateTimeFormatOptions; + ScreensaverEntityIconOn?: string | null; + ScreensaverEntityIconOff?: string | null; + ScreensaverEntityUnitText?: string; + ScreensaverEntityIconColor?: RGB | IconScaleElement | string; + ScreensaverEntityOnColor?: RGB; + ScreensaverEntityOffColor?: RGB; + ScreensaverEntityOnText?: string | null; + ScreensaverEntityOffText?: string | null; + ScreensaverEntityNaviToPage?: PageType; + }; export type ScreenSaverMRElement = { - ScreensaverEntity: string | null, - ScreensaverEntityIconOn: string | null, - ScreensaverEntityIconSelect?: {[key: string]: string} | null | undefined, - ScreensaverEntityIconOff: string | null, - ScreensaverEntityValue: string | null, - ScreensaverEntityValueDecimalPlace: number | null, - ScreensaverEntityValueUnit: string | null, - ScreensaverEntityOnColor: RGB, - ScreensaverEntityOffColor: RGB - } + ScreensaverEntity: string | null; + ScreensaverEntityIconOn: string | null; + ScreensaverEntityIconSelect?: { [key: string]: string } | null | undefined; + ScreensaverEntityIconOff: string | null; + ScreensaverEntityValue: string | null; + ScreensaverEntityValueDecimalPlace: number | null; + ScreensaverEntityValueUnit: string | null; + ScreensaverEntityOnColor: RGB; + ScreensaverEntityOffColor: RGB; + }; export type ScreenSaverMRDataElement = { - ScreensaverEntity: string | number | boolean | null, - ScreensaverEntityIconOn: string | null, - ScreensaverEntityIconOff: string | null, - ScreensaverEntityValue: string | number | boolean | null, - ScreensaverEntityValueDecimalPlace: number | null, - ScreensaverEntityValueUnit: string | null, - ScreensaverEntityOnColor: RGB, - ScreensaverEntityOffColor: RGB - ScreensaverEntityIconSelect: {[key: string]: string} | null, - } + ScreensaverEntity: string | number | boolean | null; + ScreensaverEntityIconOn: string | null; + ScreensaverEntityIconOff: string | null; + ScreensaverEntityValue: string | number | boolean | null; + ScreensaverEntityValueDecimalPlace: number | null; + ScreensaverEntityValueUnit: string | null; + ScreensaverEntityOnColor: RGB; + ScreensaverEntityOffColor: RGB; + ScreensaverEntityIconSelect: { [key: string]: string } | null; + }; - export type IconScaleElement = { - val_min:number, - val_max:number, - val_best?: number - } + export type IconScaleElement = { + val_min: number; + val_max: number; + val_best?: number; + }; /** we need this to have a nice order when using switch() */ export type adapterPlayerInstanceType = - 'alexa2.0.' | 'alexa2.1.'| 'alexa2.2.' | 'alexa2.3.' | 'alexa2.4.' | 'alexa2.5.' | 'alexa2.6.' | 'alexa2.7.' | 'alexa2.8.' | 'alexa2.9.' - | 'sonos.0.' | 'sonos.1.' | 'sonos.2.' | 'sonos.3.' | 'sonos.4.' | 'sonos.5.' | 'sonos.6.' | 'sonos.7.' | 'sonos.8.' | 'sonos.9.' - | 'spotify-premium.0.' | 'spotify-premium.1.' | 'spotify-premium.2.' | 'spotify-premium.3.' | 'spotify-premium.4.' | 'spotify-premium.5.' | 'spotify-premium.6.' | 'spotify-premium.7.' | 'spotify-premium.8.' | 'spotify-premium.9.' - | 'volumio.0.' | 'volumio.1.' | 'volumio.2.' | 'volumio.3.' |'volumio.4.' | 'volumio.5.' | 'volumio.6.' | 'volumio.7.' | 'volumio.8.' | 'volumio.9.' - | 'squeezeboxrpc.0.' | 'squeezeboxrpc.1.' | 'squeezeboxrpc.2.' | 'squeezeboxrpc.3.' | 'squeezeboxrpc.4.' | 'squeezeboxrpc.5.' | 'squeezeboxrpc.6.' | 'squeezeboxrpc.7.' | 'squeezeboxrpc.8.' | 'squeezeboxrpc.9.' - | 'bosesoundtouch.0.' | 'bosesoundtouch.1.' | 'bosesoundtouch.2.' | 'bosesoundtouch.3.' |'bosesoundtouch.4.' | 'bosesoundtouch.5.' | 'bosesoundtouch.6.' | 'bosesoundtouch.7.' | 'bosesoundtouch.8.' | 'bosesoundtouch.9.' + | 'alexa2.0.' + | 'alexa2.1.' + | 'alexa2.2.' + | 'alexa2.3.' + | 'alexa2.4.' + | 'alexa2.5.' + | 'alexa2.6.' + | 'alexa2.7.' + | 'alexa2.8.' + | 'alexa2.9.' + | 'sonos.0.' + | 'sonos.1.' + | 'sonos.2.' + | 'sonos.3.' + | 'sonos.4.' + | 'sonos.5.' + | 'sonos.6.' + | 'sonos.7.' + | 'sonos.8.' + | 'sonos.9.' + | 'spotify-premium.0.' + | 'spotify-premium.1.' + | 'spotify-premium.2.' + | 'spotify-premium.3.' + | 'spotify-premium.4.' + | 'spotify-premium.5.' + | 'spotify-premium.6.' + | 'spotify-premium.7.' + | 'spotify-premium.8.' + | 'spotify-premium.9.' + | 'volumio.0.' + | 'volumio.1.' + | 'volumio.2.' + | 'volumio.3.' + | 'volumio.4.' + | 'volumio.5.' + | 'volumio.6.' + | 'volumio.7.' + | 'volumio.8.' + | 'volumio.9.' + | 'squeezeboxrpc.0.' + | 'squeezeboxrpc.1.' + | 'squeezeboxrpc.2.' + | 'squeezeboxrpc.3.' + | 'squeezeboxrpc.4.' + | 'squeezeboxrpc.5.' + | 'squeezeboxrpc.6.' + | 'squeezeboxrpc.7.' + | 'squeezeboxrpc.8.' + | 'squeezeboxrpc.9.' + | 'bosesoundtouch.0.' + | 'bosesoundtouch.1.' + | 'bosesoundtouch.2.' + | 'bosesoundtouch.3.' + | 'bosesoundtouch.4.' + | 'bosesoundtouch.5.' + | 'bosesoundtouch.6.' + | 'bosesoundtouch.7.' + | 'bosesoundtouch.8.' + | 'bosesoundtouch.9.'; export type PlayerType = _PlayerTypeWithMediaDevice | _PlayerTypeWithOutMediaDevice; - export type _PlayerTypeWithOutMediaDevice = typeof ArrayPlayerTypeWithOutMediaDevice[number] - export type _PlayerTypeWithMediaDevice = typeof ArrayPlayerTypeWithMediaDevice[number] + export type _PlayerTypeWithOutMediaDevice = (typeof ArrayPlayerTypeWithOutMediaDevice)[number]; + export type _PlayerTypeWithMediaDevice = (typeof ArrayPlayerTypeWithMediaDevice)[number]; - export type notSortedPlayerType = `${PlayerType}.0.` | `${PlayerType}.1.` | `${PlayerType}.2.` | `${PlayerType}.3.` | `${PlayerType}.4.` | `${PlayerType}.5.` | `${PlayerType}.6.` | `${PlayerType}.7.` | `${PlayerType}.8.` | `${PlayerType}.9.` - - export type mediaOptional = 'seek' | 'crossfade' | 'speakerlist' | 'playlist' | 'tracklist' | 'equalizer' | 'repeat' | 'favorites' + export type notSortedPlayerType = + | `${PlayerType}.0.` + | `${PlayerType}.1.` + | `${PlayerType}.2.` + | `${PlayerType}.3.` + | `${PlayerType}.4.` + | `${PlayerType}.5.` + | `${PlayerType}.6.` + | `${PlayerType}.7.` + | `${PlayerType}.8.` + | `${PlayerType}.9.`; + export type mediaOptional = 'seek' | 'crossfade' | 'speakerlist' | 'playlist' | 'tracklist' | 'equalizer' | 'repeat' | 'favorites'; }