From 236ecf18426f4576f307df872b463ebe0917b898 Mon Sep 17 00:00:00 2001 From: simatec Date: Mon, 9 Dec 2024 15:08:21 +0100 Subject: [PATCH] (simatec) Fix eslint error --- eslint.config.mjs | 21 +- lib/buttonAction.js | 37 ++-- lib/sunProtect.js | 465 ++++++++++++++++++++----------------------- lib/tools.js | 5 + lib/triggerChange.js | 40 ++-- main.js | 205 +++++++++---------- tsconfig.json | 38 ---- tslint.json | 27 --- 8 files changed, 378 insertions(+), 460 deletions(-) delete mode 100644 tsconfig.json delete mode 100644 tslint.json diff --git a/eslint.config.mjs b/eslint.config.mjs index 1221f346..a1bb76c6 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -14,6 +14,7 @@ export default [ 'test/**/*.js', '*.config.mjs', 'build', + 'admin/**/*.js', 'admin/build', 'admin/words.js', 'admin/admin.d.ts', @@ -25,7 +26,25 @@ export default [ // you may disable some 'jsdoc' warnings - but using jsdoc is highly recommended // as this improves maintainability. jsdoc warnings will not block buiuld process. rules: { - // 'jsdoc/require-jsdoc': 'off', + 'jsdoc/require-jsdoc': 'off', + 'no-async-promise-executor': 'off', + 'prettier/prettier': 'off', + '@typescript-eslint/no-unused-vars': 'off', + 'curly': 'off', + 'jsdoc/require-returns-description': 'off', + 'no-else-return': 'off', + '@typescript-eslint/ban-ts-comment': 'off', + 'jsdoc/require-param-description': 'off', + 'no-constant-binary-expression': 'off', + 'valid-typeof': 'off', + 'no-irregular-whitespace': 'off', + //'no-prototype-builtins': 'off', + //'no-case-declarations': 'off', + //'no-useless-escape': 'off', + //'jsdoc/require-param': 'off', + //'@typescript-eslint/no-require-imports': 'off', + 'jsdoc/no-types': 'off', + //'jsdoc/tag-lines': 'off', }, }, diff --git a/lib/buttonAction.js b/lib/buttonAction.js index a379914d..b5f3ea0a 100644 --- a/lib/buttonAction.js +++ b/lib/buttonAction.js @@ -23,47 +23,47 @@ async function buttonAction(adapter, buttonState, shutterSettings) { if (shutterSettings) { switch (buttonState) { case 'openLiving': - resLiving = shutterSettings.filter((/** @type {{ typeUp: string; }} */ d) => d.typeUp == 'living' || d.typeUp == 'living-auto'); + resLiving = shutterSettings.filter((d) => d.typeUp == 'living' || d.typeUp == 'living-auto'); break; case 'closeLiving': - resLiving = shutterSettings.filter((/** @type {{ typeDown: string; typeUp: string; }} */ d) => d.typeDown == 'living' || d.typeUp == 'living-auto'); + resLiving = shutterSettings.filter((d) => d.typeDown == 'living' || d.typeUp == 'living-auto'); break; case 'openSleep': - resLiving = shutterSettings.filter((/** @type {{ typeUp: string; }} */ d) => d.typeUp == 'sleep' || d.typeUp == 'sleep-auto'); + resLiving = shutterSettings.filter((d) => d.typeUp == 'sleep' || d.typeUp == 'sleep-auto'); break; case 'closeSleep': - resLiving = shutterSettings.filter((/** @type {{ typeDown: string; typeUp: string; }} */ d) => d.typeDown == 'sleep' || d.typeUp == 'sleep-auto'); + resLiving = shutterSettings.filter((d) => d.typeDown == 'sleep' || d.typeUp == 'sleep-auto'); break; case 'openChildren': - resLiving = shutterSettings.filter((/** @type {{ typeUp: string; }} */ d) => d.typeUp == 'children' || d.typeUp == 'children-auto'); + resLiving = shutterSettings.filter((d) => d.typeUp == 'children' || d.typeUp == 'children-auto'); break; case 'closeChildren': - resLiving = shutterSettings.filter((/** @type {{ typeDown: string; typeUp: string; }} */ d) => d.typeDown == 'children' || d.typeUp == 'children-auto'); + resLiving = shutterSettings.filter((d) => d.typeDown == 'children' || d.typeUp == 'children-auto'); break; case 'openAll': - resLiving = shutterSettings.filter((/** @type {{ typeUp: string; }} */ d) => d.typeUp != 'manual-only'); + resLiving = shutterSettings.filter((d) => d.typeUp != 'manual-only'); break; case 'closeAll': - resLiving = shutterSettings.filter((/** @type {{ typeDown: string; }} */ d) => d.typeDown != 'manual-only'); + resLiving = shutterSettings.filter((d) => d.typeDown != 'manual-only'); break; case 'sunProtect': - resLiving = shutterSettings.filter((/** @type {{ typeDown: string; }} */ d) => d.typeDown != 'manual-only'); + resLiving = shutterSettings.filter((d) => d.typeDown != 'manual-only'); break; case 'sunProtectSleep': - resLiving = shutterSettings.filter((/** @type {{ typeDown: string; typeUp: string; }} */ d) => d.typeDown == 'sleep' || d.typeUp == 'sleep-auto'); + resLiving = shutterSettings.filter((d) => d.typeDown == 'sleep' || d.typeUp == 'sleep-auto'); break; case 'sunProtectChildren': - resLiving = shutterSettings.filter((/** @type {{ typeDown: string; typeUp: string; }} */ d) => d.typeDown == 'children' || d.typeUp == 'children-auto'); + resLiving = shutterSettings.filter((d) => d.typeDown == 'children' || d.typeUp == 'children-auto'); break; case 'sunProtectLiving': - resLiving = shutterSettings.filter((/** @type {{ typeDown: string; typeUp: string; }} */ d) => d.typeDown == 'living' || d.typeUp == 'living-auto'); + resLiving = shutterSettings.filter((d) => d.typeDown == 'living' || d.typeUp == 'living-auto'); break; case 'autoAll': - resLiving = shutterSettings.filter((/** @type {{ typeUp: string; }} */ d) => d.typeUp != 'manual-only'); + resLiving = shutterSettings.filter((d) => d.typeUp != 'manual-only'); break; } - const result = resLiving.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); // Filter enabled + const result = resLiving.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled for (const i in result) { for (const s in shutterSettings) { @@ -105,8 +105,7 @@ async function buttonAction(adapter, buttonState, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], targetLevel2Set, nameDevice, `Button ${buttonState}`); adapter.log.debug(`shutterDownButton ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${targetLevel2Set}%`); - } - else if (_shutterState?.val !== null && _shutterState?.val !== undefined && + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == targetLevel2Set) { shutterSettings[s].currentHeight = targetLevel2Set; @@ -138,8 +137,7 @@ async function buttonAction(adapter, buttonState, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].heightUp), nameDevice, `Button ${buttonState}`); adapter.log.debug(`shutterUpButton ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${shutterSettings[s].heightUp}%`); - } - else if (_shutterState?.val !== null && _shutterState?.val !== undefined && + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterSettings[s].heightUp) { shutterSettings[s].currentHeight = shutterSettings[s].heightUp; @@ -173,8 +171,7 @@ async function buttonAction(adapter, buttonState, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].heightDownSun), nameDevice, `Button ${buttonState}`); adapter.log.debug(`shutterUpButton ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${shutterSettings[s].heightUp}%`); - } - else if (_shutterState?.val !== null && _shutterState?.val !== undefined && + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterSettings[s].heightDownSun) { shutterSettings[s].currentHeight = shutterSettings[s].heightDownSun; diff --git a/lib/sunProtect.js b/lib/sunProtect.js index 5de71238..87370630 100644 --- a/lib/sunProtect.js +++ b/lib/sunProtect.js @@ -19,7 +19,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { await sleep(2000); if (shutterSettings) { - const result = shutterSettings.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); // Filter enabled + const result = shutterSettings.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled if (elevation > adapter.config.sunProtEndElevation) { for (const i in result) { @@ -54,9 +54,9 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { case 'in- & outside temperature': // in- & outside temperature _triggerState = shutterSettings[s].triggerID != '' ? await adapter.getForeignStateAsync(shutterSettings[s].triggerID).catch((e) => adapter.log.warn(e)) : null; - mustValue = ('' + shutterSettings[s].triggerState); - mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? ('' + shutterSettings[s].triggerState) : ('' + shutterSettings[s].triggerStateTilted); - currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? ('' + _triggerState.val) : ''; + mustValue = (`${shutterSettings[s].triggerState}`); + mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? (`${shutterSettings[s].triggerState}`) : (`${shutterSettings[s].triggerStateTilted}`); + currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? (`${_triggerState.val}`) : ''; if ((currentValue === mustValue || currentValue === mustValueTilted) && @@ -125,7 +125,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); if (_shutterState?.val !== null && _shutterState?.val !== undefined) { - adapter.log.debug(shutterSettings[s].shutterName + ': Check basis for sunprotect. Height:' + Math.round(_shutterState.val / vRound) * vRound + ' > HeightDownSun: ' + heightDownSun + ' AND Height:' + Math.round(_shutterState.val / vRound) * vRound + ' == currentHeight:' + shutterSettings[s].currentHeight + ' AND currentHeight:' + shutterSettings[s].currentHeight + ' == heightUp:' + shutterSettings[s].heightUp); + adapter.log.debug(`${shutterSettings[s].shutterName}: Check basis for sunprotect. Height:${Math.round(_shutterState.val / vRound) * vRound} > HeightDownSun: ${heightDownSun} AND Height:${Math.round(_shutterState.val / vRound) * vRound} == currentHeight:${shutterSettings[s].currentHeight} AND currentHeight:${shutterSettings[s].currentHeight} == heightUp:${shutterSettings[s].heightUp}`); if (((Math.round(parseFloat(_shutterState.val) / vRound) * vRound > parseFloat(heightDownSun) && convertShutter == false) || @@ -142,44 +142,40 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(heightDownSun), nameDevice, 'Sunprotect #410'); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is active'); - adapter.log.debug('Temperature inside: ' + insideTemp + ' > ' + shutterSettings[s].tempInside + ' AND ( Temperatur outside: ' + outsideTemp + ' > ' + shutterSettings[s].tempOutside + ' AND Light: ' + sunLight + ' > ' + shutterSettings[s].valueLight + ' )'); + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is active`); + adapter.log.debug(`Temperature inside: ${insideTemp} > ${shutterSettings[s].tempInside} AND ( Temperatur outside: ${outsideTemp} > ${shutterSettings[s].tempOutside} AND Light: ${sunLight} > ${shutterSettings[s].valueLight} )`); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - adapter.log.debug('Sunprotect ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + heightDownSun + '%'); - } - // Shutter closed. Set currentAction = sunProtect when sunProtect starts => - // If shutter is opened automatically it can be opened in height heightDownSun directly - else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].heightDown) && + adapter.log.debug(`Sunprotect ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${heightDownSun}%`); + } else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].heightDown) && Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].currentHeight) && shutterSettings[s].currentHeight != shutterSettings[s].heightUp && shutterSettings[s].currentAction != 'down' && shutterSettings[s].currentAction != 'middle' && shutterSettings[s].currentAction != 'Xmas' && shutterSettings[s].firstCompleteUp == true) { //check currentAction!=down here. If shutter is already closed sunProtect must not be set. Otherwise shutter will be opened again when sunProtect ends! - + // Shutter closed. Set currentAction = sunProtect when sunProtect starts => + // If shutter is opened automatically it can be opened in height heightDownSun directly shutterSettings[s].currentAction = 'OpenInSunProtect'; await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }).catch((e) => adapter.log.warn(e)); - adapter.log.debug('Set sunprotect mode for ' + shutterSettings[s].shutterName + '. Currently closed. Set to sunprotect if shutter will be opened automatically'); - } - //Shutter is in position = sunProtect. Maybe restart of adapter. sunProtect not set -> - // set sunProtect again - else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(heightDownSun) && + adapter.log.debug(`Set sunprotect mode for ${shutterSettings[s].shutterName}. Currently closed. Set to sunprotect if shutter will be opened automatically`); + } else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(heightDownSun) && Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].currentHeight) && shutterSettings[s].currentHeight != shutterSettings[s].heightUp && shutterSettings[s].currentHeight != shutterSettings[s].heightDown && shutterSettings[s].currentAction == '') { - + //Shutter is in position = sunProtect. Maybe restart of adapter. sunProtect not set -> + // set sunProtect again shutterSettings[s].currentAction = 'sunProtect'; await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }).catch((e) => adapter.log.warn(e)); - adapter.log.debug(shutterSettings[s].shutterName + ': Shutter is in position sunProtect. Reset mode sunProtect to cancel sunProtect automatically. Height:' + Math.round(_shutterState.val / vRound) * vRound + ' HeightDownSun:' + heightDownSun); + adapter.log.debug(`${shutterSettings[s].shutterName}: Shutter is in position sunProtect. Reset mode sunProtect to cancel sunProtect automatically. Height:${Math.round(_shutterState.val / vRound) * vRound} HeightDownSun:${heightDownSun}`); } } } else { - adapter.log.info('SunProtect not moving down now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%'); + adapter.log.info(`SunProtect not moving down now due to active alarm: ${shutterSettings[s].shutterName} value: ${heightDownSun}%`); shutterSettings[s].alarmTriggerLevel = parseFloat(heightDownSun); shutterSettings[s].alarmTriggerAction = 'sunProtect'; } @@ -203,7 +199,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); if (_shutterState?.val !== null && _shutterState?.val !== undefined) { - adapter.log.debug(shutterSettings[s].shutterName + ': Check basis for sunprotect. Height:' + Math.round(_shutterState.val / vRound) * vRound + ' > HeightDownSun: ' + heightDownSun + ' AND Height:' + Math.round(_shutterState.val / vRound) * vRound + ' == currentHeight:' + shutterSettings[s].currentHeight + ' AND currentHeight:' + shutterSettings[s].currentHeight + ' == heightUp:' + shutterSettings[s].heightUp + ' AND triggerAction:' + shutterSettings[s].triggerAction + ' != down '); + adapter.log.debug(`${shutterSettings[s].shutterName}: Check basis for sunprotect. Height:${Math.round(_shutterState.val / vRound) * vRound} > HeightDownSun: ${heightDownSun} AND Height:${Math.round(_shutterState.val / vRound) * vRound} == currentHeight:${shutterSettings[s].currentHeight} AND currentHeight:${shutterSettings[s].currentHeight} == heightUp:${shutterSettings[s].heightUp} AND triggerAction:${shutterSettings[s].triggerAction} != down `); if (((Math.round(parseFloat(_shutterState.val) / vRound) * vRound > parseFloat(heightDownSun) && convertShutter == false) || @@ -218,14 +214,14 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].triggerHeight = parseFloat(heightDownSun); shutterSettings[s].triggerAction = 'sunProtect'; - adapter.log.info(' Will sunprotect ID: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%' + ' after the window has been closed '); - adapter.log.debug('save new trigger height: ' + heightDownSun + '%'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); + adapter.log.info(` Will sunprotect ID: ${shutterSettings[s].shutterName} value: ${heightDownSun}%` + ` after the window has been closed `); + adapter.log.debug(`save new trigger height: ${heightDownSun}%`); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); } } } else { - adapter.log.info('SunProtect not moving down now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%'); + adapter.log.info(`SunProtect not moving down now due to active alarm: ${shutterSettings[s].shutterName} value: ${heightDownSun}%`); shutterSettings[s].alarmTriggerLevel = parseFloat(heightDownSun); shutterSettings[s].alarmTriggerAction = 'sunProtect'; } @@ -282,22 +278,21 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].heightUp), nameDevice, 'Sunprotect #411'); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is not active'); - adapter.log.debug('Temperature inside: ' + insideTemp + ' < ' + hysteresisInside + ' OR ( Temperature outside: ' + outsideTemp + ' < ' + hysteresisOutside + ' OR Light: ' + sunLight + ' < ' + hysteresisLight + ' )'); + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is not active`); + adapter.log.debug(`Temperature inside: ${insideTemp} < ${hysteresisInside} OR ( Temperature outside: ${outsideTemp} < ${hysteresisOutside} OR Light: ${sunLight} < ${hysteresisLight} )`); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - adapter.log.debug('Sunprotect ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + heightDownSun + '%') - } - else if (shutterSettings[s].currentAction == 'OpenInSunProtect') { + adapter.log.debug(`Sunprotect ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${heightDownSun}%`) + } else if (shutterSettings[s].currentAction == 'OpenInSunProtect') { shutterSettings[s].sunProtectEndtimerid = '' shutterSettings[s].currentAction = 'none'; await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }).catch((e) => adapter.log.warn(e)); - adapter.log.debug('OpenInSunProtect for ' + shutterSettings[s].shutterName + ' is not longer active'); + adapter.log.debug(`OpenInSunProtect for ${shutterSettings[s].shutterName} is not longer active`); } } } else if (shutterSettings[s].alarmTriggerAction == 'sunProtect') { - adapter.log.info('SunProtect not moving up now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + shutterSettings[s].heightUp + '%'); + adapter.log.info(`SunProtect not moving up now due to active alarm: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].heightUp}%`); shutterSettings[s].sunProtectEndtimerid = ''; shutterSettings[s].alarmTriggerLevel = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].alarmTriggerAction = 'up'; @@ -346,12 +341,12 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].triggerHeight = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].triggerAction = 'up'; - adapter.log.info(' Will end sunprotect ID: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%' + ' after the window has been closed '); + adapter.log.info(` Will end sunprotect ID: ${shutterSettings[s].shutterName} value: ${heightDownSun}%` + ` after the window has been closed `); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is not active anymore'); - adapter.log.debug('Temperature inside: ' + insideTemp + ' < ' + hysteresisInside + ' OR ( Temperature outside: ' + outsideTemp + ' < ' + hysteresisOutside + ' OR Light: ' + sunLight + ' < ' + hysteresisLight + ' )'); - adapter.log.debug('save new trigger height: ' + shutterSettings[s].triggerHeight + '%'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is not active anymore`); + adapter.log.debug(`Temperature inside: ${insideTemp} < ${hysteresisInside} OR ( Temperature outside: ${outsideTemp} < ${hysteresisOutside} OR Light: ${sunLight} < ${hysteresisLight} )`); + adapter.log.debug(`save new trigger height: ${shutterSettings[s].triggerHeight}%`); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); } else if (shutterSettings[s].triggerAction == 'sunProtect' && shutterSettings[s].KeepSunProtect === false && @@ -368,11 +363,11 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { } else if (shutterSettings[s].currentAction == 'OpenInSunProtect') { shutterSettings[s].sunProtectEndtimerid = '' shutterSettings[s].triggerAction = 'none'; - adapter.log.debug('OpenInSunProtect for ' + shutterSettings[s].shutterName + ' is not longer active'); + adapter.log.debug(`OpenInSunProtect for ${shutterSettings[s].shutterName} is not longer active`); } } } else if (shutterSettings[s].alarmTriggerAction == 'sunProtect') { - adapter.log.info('SunProtect not moving up now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + shutterSettings[s].heightUp + '%'); + adapter.log.info(`SunProtect not moving up now due to active alarm: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].heightUp}%`); shutterSettings[s].sunProtectEndtimerid = ''; shutterSettings[s].alarmTriggerLevel = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].alarmTriggerAction = 'up'; @@ -392,9 +387,9 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { resultDirectionRangePlus = parseInt(shutterSettings[s].direction) + parseInt(shutterSettings[s].directionRange); _triggerState = shutterSettings[s].triggerID != '' ? await adapter.getForeignStateAsync(shutterSettings[s].triggerID).catch((e) => adapter.log.warn(e)) : null; - mustValue = ('' + shutterSettings[s].triggerState); - mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? ('' + shutterSettings[s].triggerState) : ('' + shutterSettings[s].triggerStateTilted); - currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? ('' + _triggerState.val) : ''; + mustValue = (`${shutterSettings[s].triggerState}`); + mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? (`${shutterSettings[s].triggerState}`) : (`${shutterSettings[s].triggerStateTilted}`); + currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? (`${_triggerState.val}`) : ''; if ((currentValue === mustValue || currentValue === mustValueTilted) && @@ -437,7 +432,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].lightSensor != '' && shutterSettings[s].valueLight < sunLight) { - adapter.log.debug('Stopping sunprotect delay for ' + shutterSettings[s].shutterName); + adapter.log.debug(`Stopping sunprotect delay for ${shutterSettings[s].shutterName}`); clearTimeout(shutterSettings[s].sunProtectEndtimerid); shutterSettings[s].sunProtectEndtimerid = ''; } @@ -467,7 +462,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { if (_shutterState?.val !== null && _shutterState?.val !== undefined) { - adapter.log.debug(shutterSettings[s].shutterName + ': Check basis for sunprotect. Height:' + Math.round(_shutterState.val / vRound) * vRound + ' > HeightDownSun: ' + heightDownSun + ' AND Height:' + Math.round(_shutterState.val / vRound) * vRound + ' == currentHeight:' + shutterSettings[s].currentHeight + ' AND currentHeight:' + shutterSettings[s].currentHeight + ' == heightUp:' + shutterSettings[s].heightUp); + adapter.log.debug(`${shutterSettings[s].shutterName}: Check basis for sunprotect. Height:${Math.round(_shutterState.val / vRound) * vRound} > HeightDownSun: ${heightDownSun} AND Height:${Math.round(_shutterState.val / vRound) * vRound} == currentHeight:${shutterSettings[s].currentHeight} AND currentHeight:${shutterSettings[s].currentHeight} == heightUp:${shutterSettings[s].heightUp}`); if (((Math.round(parseFloat(_shutterState.val) / vRound) * vRound > parseFloat(heightDownSun) && convertShutter == false) || @@ -484,42 +479,38 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(heightDownSun), nameDevice, 'Sunprotect #412'); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is active'); - adapter.log.debug('Temperature inside: ' + insideTemp + ' > ' + shutterSettings[s].tempInside + ' AND ( Temperatur outside: ' + outsideTemp + ' > ' + shutterSettings[s].tempOutside + ' AND Light: ' + sunLight + ' > ' + shutterSettings[s].valueLight + ' )'); - adapter.log.debug('Sunprotect ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + heightDownSun + '%'); + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is active`); + adapter.log.debug(`Temperature inside: ${insideTemp} > ${shutterSettings[s].tempInside} AND ( Temperatur outside: ${outsideTemp} > ${shutterSettings[s].tempOutside} AND Light: ${sunLight} > ${shutterSettings[s].valueLight} )`); + adapter.log.debug(`Sunprotect ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${heightDownSun}%`); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - adapter.log.debug('Sunprotect ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + heightDownSun + '%') - } - // Shutter closed. Set currentAction = sunProtect when sunProtect starts => - // If shutter is opened automatically it can be opened in height heightDownSun directly - else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].heightDown) && + adapter.log.debug(`Sunprotect ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${heightDownSun}%`) + } else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].heightDown) && Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].currentHeight) && shutterSettings[s].currentHeight != shutterSettings[s].heightUp && shutterSettings[s].currentAction != 'down' && shutterSettings[s].currentAction != 'middle' && shutterSettings[s].currentAction != 'Xmas' && shutterSettings[s].firstCompleteUp == true) { //check currentAction!=down here. If shutter is already closed sunProtect must not be set. Otherwise shutter will be opened again when sunProtect ends! - + // Shutter closed. Set currentAction = sunProtect when sunProtect starts => + // If shutter is opened automatically it can be opened in height heightDownSun directly shutterSettings[s].currentAction = 'OpenInSunProtect'; - adapter.log.debug('Set sunprotect mode for ' + shutterSettings[s].shutterName + '. Currently closed. Set to sunprotect if shutter will be opened automatically'); - } - // Shutter is in position = sunProtect. Maybe restart of adapter. sunProtect not set -> - // set sunProtect again - else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(heightDownSun) && + adapter.log.debug(`Set sunprotect mode for ${shutterSettings[s].shutterName}. Currently closed. Set to sunprotect if shutter will be opened automatically`); + } else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(heightDownSun) && Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].currentHeight) && shutterSettings[s].currentHeight != shutterSettings[s].heightUp && shutterSettings[s].currentHeight != shutterSettings[s].heightDown && shutterSettings[s].currentAction == '') { - + // Shutter is in position = sunProtect. Maybe restart of adapter. sunProtect not set -> + // set sunProtect again shutterSettings[s].currentAction = 'sunProtect'; await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }).catch((e) => adapter.log.warn(e)); - adapter.log.debug(shutterSettings[s].shutterName + ': Shutter is in position sunProtect. Reset mode sunProtect to cancel sunProtect automatically. Height:' + Math.round(_shutterState.val / vRound) * vRound + ' HeightDownSun:' + heightDownSun); + adapter.log.debug(`${shutterSettings[s].shutterName}: Shutter is in position sunProtect. Reset mode sunProtect to cancel sunProtect automatically. Height:${Math.round(_shutterState.val / vRound) * vRound} HeightDownSun:${heightDownSun}`); } } } else { - adapter.log.info('SunProtect not moving down now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%'); + adapter.log.info(`SunProtect not moving down now due to active alarm: ${shutterSettings[s].shutterName} value: ${heightDownSun}%`); shutterSettings[s].alarmTriggerLevel = parseFloat(heightDownSun); shutterSettings[s].alarmTriggerAction = 'sunProtect'; } @@ -546,7 +537,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); if (_shutterState?.val !== null && _shutterState?.val !== undefined) { - adapter.log.debug(shutterSettings[s].shutterName + ': Check basis for sunprotect. Height:' + Math.round(_shutterState.val / vRound) * vRound + ' > HeightDownSun: ' + heightDownSun + ' AND Height:' + Math.round(_shutterState.val / vRound) * vRound + ' == currentHeight:' + shutterSettings[s].currentHeight + ' AND currentHeight:' + shutterSettings[s].currentHeight + ' == heightUp:' + shutterSettings[s].heightUp + ' AND triggerAction:' + shutterSettings[s].triggerAction + ' != down '); + adapter.log.debug(`${shutterSettings[s].shutterName}: Check basis for sunprotect. Height:${Math.round(_shutterState.val / vRound) * vRound} > HeightDownSun: ${heightDownSun} AND Height:${Math.round(_shutterState.val / vRound) * vRound} == currentHeight:${shutterSettings[s].currentHeight} AND currentHeight:${shutterSettings[s].currentHeight} == heightUp:${shutterSettings[s].heightUp} AND triggerAction:${shutterSettings[s].triggerAction} != down `); if (((Math.round(parseFloat(_shutterState.val) / vRound) * vRound > parseFloat(heightDownSun) && convertShutter == false) || @@ -561,17 +552,17 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].triggerHeight = parseFloat(heightDownSun); shutterSettings[s].triggerAction = 'sunProtect'; - adapter.log.info(' Will sunprotect ID: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%' + ' after the window has been closed'); + adapter.log.info(` Will sunprotect ID: ${shutterSettings[s].shutterName} value: ${heightDownSun}%` + ` after the window has been closed`); - adapter.log.debug('save new trigger height: ' + heightDownSun + '%'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); + adapter.log.debug(`save new trigger height: ${heightDownSun}%`); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); } } } else { shutterSettings[s].alarmTriggerLevel = parseFloat(heightDownSun); shutterSettings[s].alarmTriggerAction = 'sunProtect'; - adapter.log.info('SunProtect not moving down now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%'); + adapter.log.info(`SunProtect not moving down now due to active alarm: ${shutterSettings[s].shutterName} value: ${heightDownSun}%`); } } } @@ -628,17 +619,16 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].heightUp), nameDevice, 'Sunprotect #413'); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is not active'); - adapter.log.debug('Range: ' + resultDirectionRangePlus + ' < ' + azimuth + ' OR Temperature inside: ' + insideTemp + ' < ' + hysteresisInside + ' OR ( Temperature outside: ' + outsideTemp + ' < ' + hysteresisOutside + ' OR Light: ' + sunLight + ' < ' + hysteresisLight + ')'); - adapter.log.debug('Sunprotect ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterSettings[s].heightUp + '%'); - } - else if (shutterSettings[s].currentAction == 'OpenInSunProtect') { + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is not active`); + adapter.log.debug(`Range: ${resultDirectionRangePlus} < ${azimuth} OR Temperature inside: ${insideTemp} < ${hysteresisInside} OR ( Temperature outside: ${outsideTemp} < ${hysteresisOutside} OR Light: ${sunLight} < ${hysteresisLight})`); + adapter.log.debug(`Sunprotect ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${shutterSettings[s].heightUp}%`); + } else if (shutterSettings[s].currentAction == 'OpenInSunProtect') { shutterSettings[s].sunProtectEndtimerid = '' shutterSettings[s].currentAction = 'none'; await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }).catch((e) => adapter.log.warn(e)); - adapter.log.debug('OpenInSunProtect for ' + shutterSettings[s].shutterName + ' is not longer active'); + adapter.log.debug(`OpenInSunProtect for ${shutterSettings[s].shutterName} is not longer active`); } } } else if (shutterSettings[s].alarmTriggerAction == 'sunProtect') { @@ -646,7 +636,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].alarmTriggerLevel = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].alarmTriggerAction = 'up'; - adapter.log.info('SunProtect not moving up now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + shutterSettings[s].heightUp + '%'); + adapter.log.info(`SunProtect not moving up now due to active alarm: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].heightUp}%`); } } } @@ -694,12 +684,12 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].triggerHeight = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].triggerAction = 'up'; - adapter.log.info(' Will end sunprotect ID: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%' + ' after the window has been closed '); + adapter.log.info(` Will end sunprotect ID: ${shutterSettings[s].shutterName} value: ${heightDownSun}%` + ` after the window has been closed `); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is not active anymore'); - adapter.log.debug('Temperature inside: ' + insideTemp + ' < ' + hysteresisInside + ' OR ( Temperature outside: ' + outsideTemp + ' < ' + hysteresisOutside + ' OR Light: ' + sunLight + ' < ' + hysteresisLight + ' )'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); - adapter.log.debug('save new trigger height: ' + shutterSettings[s].triggerHeight + '%'); + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is not active anymore`); + adapter.log.debug(`Temperature inside: ${insideTemp} < ${hysteresisInside} OR ( Temperature outside: ${outsideTemp} < ${hysteresisOutside} OR Light: ${sunLight} < ${hysteresisLight} )`); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); + adapter.log.debug(`save new trigger height: ${shutterSettings[s].triggerHeight}%`); } else if (shutterSettings[s].triggerAction == 'sunProtect' && shutterSettings[s].KeepSunProtect === false && @@ -716,7 +706,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { } else if (shutterSettings[s].currentAction == 'OpenInSunProtect') { shutterSettings[s].triggerAction = 'none'; - adapter.log.debug('OpenInSunProtect for ' + shutterSettings[s].shutterName + ' is not longer active'); + adapter.log.debug(`OpenInSunProtect for ${shutterSettings[s].shutterName} is not longer active`); } } } else if (shutterSettings[s].alarmTriggerAction == 'sunProtect') { @@ -724,7 +714,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].alarmTriggerLevel = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].alarmTriggerAction = 'up'; - adapter.log.info('SunProtect not moving up now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + shutterSettings[s].heightUp + '%'); + adapter.log.info(`SunProtect not moving up now due to active alarm: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].heightUp}%`); } } } @@ -741,9 +731,9 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { resultDirectionRangePlus = parseInt(shutterSettings[s].direction) + parseInt(shutterSettings[s].directionRange); _triggerState = shutterSettings[s].triggerID != '' ? await adapter.getForeignStateAsync(shutterSettings[s].triggerID).catch((e) => adapter.log.warn(e)) : null; - mustValue = ('' + shutterSettings[s].triggerState); - mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? ('' + shutterSettings[s].triggerState) : ('' + shutterSettings[s].triggerStateTilted); - currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? ('' + _triggerState.val) : ''; + mustValue = (`${shutterSettings[s].triggerState}`); + mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? (`${shutterSettings[s].triggerState}`) : (`${shutterSettings[s].triggerStateTilted}`); + currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? (`${_triggerState.val}`) : ''; if (currentValue === mustValue || currentValue === mustValueTilted || @@ -778,7 +768,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].lightSensor != '' && shutterSettings[s].valueLight < sunLight) { - adapter.log.debug('Stopping sunprotect delay for ' + shutterSettings[s].shutterName); + adapter.log.debug(`Stopping sunprotect delay for ${shutterSettings[s].shutterName}`); clearTimeout(shutterSettings[s].sunProtectEndtimerid); shutterSettings[s].sunProtectEndtimerid = ''; } @@ -803,7 +793,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); if (_shutterState?.val !== null && _shutterState?.val !== undefined) { - adapter.log.debug(shutterSettings[s].shutterName + ': Check basis for sunprotect. Height:' + Math.round(_shutterState.val / vRound) * vRound + ' > HeightDownSun: ' + heightDownSun + ' AND Height:' + Math.round(_shutterState.val / vRound) * vRound + ' == currentHeight:' + shutterSettings[s].currentHeight + ' AND currentHeight:' + shutterSettings[s].currentHeight + ' == heightUp:' + shutterSettings[s].heightUp); + adapter.log.debug(`${shutterSettings[s].shutterName}: Check basis for sunprotect. Height:${Math.round(_shutterState.val / vRound) * vRound} > HeightDownSun: ${heightDownSun} AND Height:${Math.round(_shutterState.val / vRound) * vRound} == currentHeight:${shutterSettings[s].currentHeight} AND currentHeight:${shutterSettings[s].currentHeight} == heightUp:${shutterSettings[s].heightUp}`); if (((Math.round(parseFloat(_shutterState.val) / vRound) * vRound > parseFloat(heightDownSun) && convertShutter == false) || @@ -821,46 +811,42 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(heightDownSun), nameDevice, 'Sunprotect #414'); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is active'); - adapter.log.debug('Temperatur outside: ' + outsideTemp + ' > ' + shutterSettings[s].tempOutside + ' AND Light: ' + sunLight + ' > ' + shutterSettings[s].valueLight); - adapter.log.debug('Sunprotect ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + heightDownSun + '%') - } - // Shutter closed. Set currentAction = sunProtect when sunProtect starts => - // If shutter is opened automatically it can be opened in height heightDownSun directly - else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].heightDown) && + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is active`); + adapter.log.debug(`Temperatur outside: ${outsideTemp} > ${shutterSettings[s].tempOutside} AND Light: ${sunLight} > ${shutterSettings[s].valueLight}`); + adapter.log.debug(`Sunprotect ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${heightDownSun}%`) + } else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].heightDown) && Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].currentHeight) && shutterSettings[s].currentHeight != shutterSettings[s].heightUp && shutterSettings[s].currentAction != 'down' && shutterSettings[s].currentAction != 'middle' && shutterSettings[s].currentAction != 'Xmas' && shutterSettings[s].firstCompleteUp == true) { //check currentAction!=down here. If shutter is already closed sunProtect must not be set. Otherwise shutter will be opened again when sunProtect ends! - + // Shutter closed. Set currentAction = sunProtect when sunProtect starts => + // If shutter is opened automatically it can be opened in height heightDownSun directly shutterSettings[s].currentAction = 'OpenInSunProtect'; await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }).catch((e) => adapter.log.warn(e)); - adapter.log.debug('Set sunprotect mode for ' + shutterSettings[s].shutterName + '. Currently closed. Set to sunprotect if shutter will be opened automatically'); - } - // Shutter is in position = sunProtect. Maybe restart of adapter. sunProtect not set -> - // set sunProtect again - else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(heightDownSun) && + adapter.log.debug(`Set sunprotect mode for ${shutterSettings[s].shutterName}. Currently closed. Set to sunprotect if shutter will be opened automatically`); + } else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(heightDownSun) && Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].currentHeight) && shutterSettings[s].currentHeight != shutterSettings[s].heightUp && shutterSettings[s].currentHeight != shutterSettings[s].heightDown && shutterSettings[s].currentAction == '') { - + // Shutter is in position = sunProtect. Maybe restart of adapter. sunProtect not set -> + // set sunProtect again shutterSettings[s].currentAction = 'sunProtect'; await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }).catch((e) => adapter.log.warn(e)); - adapter.log.debug(shutterSettings[s].shutterName + ': Shutter is in position sunProtect. Reset mode sunProtect to cancel sunProtect automatically. Height:' + Math.round(_shutterState.val / vRound) * vRound + ' HeightDownSun:' + heightDownSun); + adapter.log.debug(`${shutterSettings[s].shutterName}: Shutter is in position sunProtect. Reset mode sunProtect to cancel sunProtect automatically. Height:${Math.round(_shutterState.val / vRound) * vRound} HeightDownSun:${heightDownSun}`); } } } else { shutterSettings[s].alarmTriggerLevel = parseFloat(heightDownSun); shutterSettings[s].alarmTriggerAction = 'sunProtect'; - adapter.log.info('SunProtect not moving down now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%'); + adapter.log.info(`SunProtect not moving down now due to active alarm: ${shutterSettings[s].shutterName} value: ${heightDownSun}%`); } } } @@ -882,7 +868,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); if (_shutterState?.val !== null && _shutterState?.val !== undefined) { - adapter.log.debug(shutterSettings[s].shutterName + ': Check basis for sunprotect. Height:' + Math.round(_shutterState.val / vRound) * vRound + ' > HeightDownSun: ' + heightDownSun + ' AND Height:' + Math.round(_shutterState.val / vRound) * vRound + ' == currentHeight:' + shutterSettings[s].currentHeight + ' AND currentHeight:' + shutterSettings[s].currentHeight + ' == heightUp:' + shutterSettings[s].heightUp); + adapter.log.debug(`${shutterSettings[s].shutterName}: Check basis for sunprotect. Height:${Math.round(_shutterState.val / vRound) * vRound} > HeightDownSun: ${heightDownSun} AND Height:${Math.round(_shutterState.val / vRound) * vRound} == currentHeight:${shutterSettings[s].currentHeight} AND currentHeight:${shutterSettings[s].currentHeight} == heightUp:${shutterSettings[s].heightUp}`); if (((Math.round(parseFloat(_shutterState.val) / vRound) * vRound > parseFloat(heightDownSun) && convertShutter == false) || @@ -897,10 +883,10 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].triggerHeight = parseFloat(heightDownSun); shutterSettings[s].triggerAction = 'sunProtect'; - adapter.log.info(' Will sunprotect ID: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%' + ' after the window has been closed '); + adapter.log.info(` Will sunprotect ID: ${shutterSettings[s].shutterName} value: ${heightDownSun}%` + ` after the window has been closed `); - adapter.log.debug('save new trigger height: ' + heightDownSun + '%'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); + adapter.log.debug(`save new trigger height: ${heightDownSun}%`); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); } } @@ -908,7 +894,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].alarmTriggerLevel = parseFloat(heightDownSun); shutterSettings[s].alarmTriggerAction = 'sunProtect'; - adapter.log.info('SunProtect not moving down now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%'); + adapter.log.info(`SunProtect not moving down now due to active alarm: ${shutterSettings[s].shutterName} value: ${heightDownSun}%`); } } } @@ -963,17 +949,16 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].heightUp), nameDevice, 'Sunprotect #415'); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is not active'); - adapter.log.debug('Temperature outside: ' + outsideTemp + ' < ' + hysteresisOutside + ' OR Light: ' + sunLight + ' < ' + hysteresisLight); + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is not active`); + adapter.log.debug(`Temperature outside: ${outsideTemp} < ${hysteresisOutside} OR Light: ${sunLight} < ${hysteresisLight}`); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - adapter.log.debug('Sunprotect ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterSettings[s].heightUp + '%') - } - else if (shutterSettings[s].currentAction == 'OpenInSunProtect') { + adapter.log.debug(`Sunprotect ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${shutterSettings[s].heightUp}%`) + } else if (shutterSettings[s].currentAction == 'OpenInSunProtect') { shutterSettings[s].currentAction = 'none'; await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }).catch((e) => adapter.log.warn(e)); - adapter.log.debug('OpenInSunProtect for ' + shutterSettings[s].shutterName + ' is not longer active'); + adapter.log.debug(`OpenInSunProtect for ${shutterSettings[s].shutterName} is not longer active`); } } } else if (shutterSettings[s].alarmTriggerAction == 'sunProtect') { @@ -981,7 +966,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].alarmTriggerLevel = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].alarmTriggerAction = 'up'; - adapter.log.info('SunProtect not moving up now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + shutterSettings[s].heightUp + '%'); + adapter.log.info(`SunProtect not moving up now due to active alarm: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].heightUp}%`); } } } @@ -1026,11 +1011,11 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].triggerHeight = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].triggerAction = 'up'; - adapter.log.info(' Will end sunprotect ID: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%' + ' after the window has been closed '); + adapter.log.info(` Will end sunprotect ID: ${shutterSettings[s].shutterName} value: ${heightDownSun}%` + ` after the window has been closed `); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is not active anymore'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); - adapter.log.debug('save new trigger height: ' + shutterSettings[s].triggerHeight + '%'); + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is not active anymore`); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); + adapter.log.debug(`save new trigger height: ${shutterSettings[s].triggerHeight}%`); } else if (shutterSettings[s].triggerAction == 'sunProtect' && shutterSettings[s].KeepSunProtect === false && (parseFloat(shutterSettings[s].triggerHeight) == parseFloat(shutterSettings[s].heightUp) || @@ -1047,7 +1032,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].sunProtectEndtimerid = '' shutterSettings[s].triggerAction = 'none'; - adapter.log.debug('OpenInSunProtect for ' + shutterSettings[s].shutterName + ' is not longer active'); + adapter.log.debug(`OpenInSunProtect for ${shutterSettings[s].shutterName} is not longer active`); } } } else if (shutterSettings[s].alarmTriggerAction == 'sunProtect') { @@ -1055,7 +1040,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].alarmTriggerLevel = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].alarmTriggerAction = 'up'; - adapter.log.info('SunProtect not moving up now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + shutterSettings[s].heightUp + '%'); + adapter.log.info(`SunProtect not moving up now due to active alarm: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].heightUp}%`); } } } @@ -1072,9 +1057,9 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { resultDirectionRangePlus = parseInt(shutterSettings[s].direction) + parseInt(shutterSettings[s].directionRange); _triggerState = shutterSettings[s].triggerID != '' ? await adapter.getForeignStateAsync(shutterSettings[s].triggerID).catch((e) => adapter.log.warn(e)) : null; - mustValue = ('' + shutterSettings[s].triggerState); - mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? ('' + shutterSettings[s].triggerState) : ('' + shutterSettings[s].triggerStateTilted); - currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? ('' + _triggerState.val) : ''; + mustValue = (`${shutterSettings[s].triggerState}`); + mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? (`${shutterSettings[s].triggerState}`) : (`${shutterSettings[s].triggerStateTilted}`); + currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? (`${_triggerState.val}`) : ''; if (currentValue === mustValue || currentValue === mustValueTilted || @@ -1100,7 +1085,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { if (_shutterState?.val !== null && _shutterState?.val !== undefined) { - adapter.log.debug(shutterSettings[s].shutterName + ': Check basis for sunprotect. Height:' + Math.round(_shutterState.val / vRound) * vRound + ' > HeightDownSun: ' + heightDownSun + ' AND Height:' + Math.round(_shutterState.val / vRound) * vRound + ' == currentHeight:' + shutterSettings[s].currentHeight + ' AND currentHeight:' + shutterSettings[s].currentHeight + ' == heightUp:' + shutterSettings[s].heightUp); + adapter.log.debug(`${shutterSettings[s].shutterName}: Check basis for sunprotect. Height:${Math.round(_shutterState.val / vRound) * vRound} > HeightDownSun: ${heightDownSun} AND Height:${Math.round(_shutterState.val / vRound) * vRound} == currentHeight:${shutterSettings[s].currentHeight} AND currentHeight:${shutterSettings[s].currentHeight} == heightUp:${shutterSettings[s].heightUp}`); if (((Math.round(parseFloat(_shutterState.val) / vRound) * vRound > parseFloat(heightDownSun) && convertShutter == false) || @@ -1115,47 +1100,43 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(heightDownSun), nameDevice, 'Sunprotect #416'); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is active'); - adapter.log.debug('RangeMinus: ' + resultDirectionRangeMinus + ' < ' + azimuth + 'RangePlus: ' + resultDirectionRangePlus + ' > ' + azimuth); + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is active`); + adapter.log.debug(`RangeMinus: ${resultDirectionRangeMinus} < ${azimuth}RangePlus: ${resultDirectionRangePlus} > ${azimuth}`); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - adapter.log.debug('Sunprotect ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + heightDownSun + '%'); - } - // Shutter closed. Set currentAction = sunProtect when sunProtect starts => - // If shutter is opened automatically it can be opened in height heightDownSun directly - else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].heightDown) && + adapter.log.debug(`Sunprotect ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${heightDownSun}%`); + } else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].heightDown) && Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].currentHeight) && shutterSettings[s].currentHeight != shutterSettings[s].heightUp && shutterSettings[s].currentAction != 'down' && shutterSettings[s].currentAction != 'middle' && shutterSettings[s].currentAction != 'Xmas' && shutterSettings[s].firstCompleteUp == true) { //check currentAction!=down here. If shutter is already closed sunProtect must not be set. Otherwise shutter will be opened again when sunProtect ends! - + // Shutter closed. Set currentAction = sunProtect when sunProtect starts => + // If shutter is opened automatically it can be opened in height heightDownSun directly shutterSettings[s].currentAction = 'OpenInSunProtect'; await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }).catch((e) => adapter.log.warn(e)); - adapter.log.debug('Set sunprotect mode for ' + shutterSettings[s].shutterName + '. Currently closed. Set to sunprotect if shutter will be opened automatically'); - } - // Shutter is in position = sunProtect. Maybe restart of adapter. sunProtect not set -> - // set sunProtect again - else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(heightDownSun) && + adapter.log.debug(`Set sunprotect mode for ${shutterSettings[s].shutterName}. Currently closed. Set to sunprotect if shutter will be opened automatically`); + } else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(heightDownSun) && Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].currentHeight) && shutterSettings[s].currentHeight != shutterSettings[s].heightUp && shutterSettings[s].currentHeight != shutterSettings[s].heightDown && shutterSettings[s].currentAction == '') { - + // Shutter is in position = sunProtect. Maybe restart of adapter. sunProtect not set -> + // set sunProtect again shutterSettings[s].currentAction = 'sunProtect'; await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }).catch((e) => adapter.log.warn(e)); - adapter.log.debug(shutterSettings[s].shutterName + ': Shutter is in position sunProtect. Reset mode sunProtect to cancel sunProtect automatically. Height:' + Math.round(_shutterState.val / vRound) * vRound + ' HeightDownSun:' + heightDownSun); + adapter.log.debug(`${shutterSettings[s].shutterName}: Shutter is in position sunProtect. Reset mode sunProtect to cancel sunProtect automatically. Height:${Math.round(_shutterState.val / vRound) * vRound} HeightDownSun:${heightDownSun}`); } } } else { shutterSettings[s].alarmTriggerLevel = parseFloat(heightDownSun); shutterSettings[s].alarmTriggerAction = 'sunProtect'; - adapter.log.info('SunProtect not moving down now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%'); + adapter.log.info(`SunProtect not moving down now due to active alarm: ${shutterSettings[s].shutterName} value: ${heightDownSun}%`); } } } @@ -1174,7 +1155,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { if (_shutterState?.val !== null && _shutterState?.val !== undefined) { - adapter.log.debug(shutterSettings[s].shutterName + ': Check basis for sunprotect. Height:' + Math.round(_shutterState.val / vRound) * vRound + ' > HeightDownSun: ' + heightDownSun + ' AND Height:' + Math.round(_shutterState.val / vRound) * vRound + ' == currentHeight:' + shutterSettings[s].currentHeight + ' AND currentHeight:' + shutterSettings[s].currentHeight + ' == heightUp:' + shutterSettings[s].heightUp); + adapter.log.debug(`${shutterSettings[s].shutterName}: Check basis for sunprotect. Height:${Math.round(_shutterState.val / vRound) * vRound} > HeightDownSun: ${heightDownSun} AND Height:${Math.round(_shutterState.val / vRound) * vRound} == currentHeight:${shutterSettings[s].currentHeight} AND currentHeight:${shutterSettings[s].currentHeight} == heightUp:${shutterSettings[s].heightUp}`); if (((Math.round(parseFloat(_shutterState.val) / vRound) * vRound > parseFloat(heightDownSun) && convertShutter == false) || (Math.round(parseFloat(_shutterState.val) / vRound) * vRound < parseFloat(heightDownSun) && convertShutter == true)) && @@ -1187,17 +1168,17 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].triggerHeight = parseFloat(heightDownSun); shutterSettings[s].triggerAction = 'sunProtect'; - adapter.log.info(' Will sunprotect ID: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%' + ' after the window has been closed '); + adapter.log.info(` Will sunprotect ID: ${shutterSettings[s].shutterName} value: ${heightDownSun}%` + ` after the window has been closed `); - adapter.log.debug('save new trigger height: ' + heightDownSun + '%'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); + adapter.log.debug(`save new trigger height: ${heightDownSun}%`); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); } } } else { shutterSettings[s].alarmTriggerLevel = parseFloat(heightDownSun); shutterSettings[s].alarmTriggerAction = 'sunProtect'; - adapter.log.info('SunProtect not moving down now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%'); + adapter.log.info(`SunProtect not moving down now due to active alarm: ${shutterSettings[s].shutterName} value: ${heightDownSun}%`); } } @@ -1227,16 +1208,15 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].heightUp), nameDevice, 'Sunprotect #417'); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is not active'); - adapter.log.debug('Range: ' + resultDirectionRangePlus + ' < ' + azimuth); - adapter.log.debug('Sunprotect ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterSettings[s].heightUp + '%') - } - else if (shutterSettings[s].currentAction == 'OpenInSunProtect') { + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is not active`); + adapter.log.debug(`Range: ${resultDirectionRangePlus} < ${azimuth}`); + adapter.log.debug(`Sunprotect ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${shutterSettings[s].heightUp}%`) + } else if (shutterSettings[s].currentAction == 'OpenInSunProtect') { shutterSettings[s].currentAction = 'none'; await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }).catch((e) => adapter.log.warn(e)); - adapter.log.debug('OpenInSunProtect for ' + shutterSettings[s].shutterName + ' is not longer active'); + adapter.log.debug(`OpenInSunProtect for ${shutterSettings[s].shutterName} is not longer active`); } } } else if (shutterSettings[s].alarmTriggerAction == 'sunProtect') { @@ -1244,7 +1224,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].alarmTriggerLevel = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].alarmTriggerAction = 'up'; - adapter.log.info('SunProtect not moving up now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + shutterSettings[s].heightUp + '%'); + adapter.log.info(`SunProtect not moving up now due to active alarm: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].heightUp}%`); } } } @@ -1266,11 +1246,11 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].triggerHeight = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].triggerAction = 'up'; - adapter.log.info(' Will end sunprotect ID: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%' + ' after the window has been closed '); + adapter.log.info(` Will end sunprotect ID: ${shutterSettings[s].shutterName} value: ${heightDownSun}%` + ` after the window has been closed `); - adapter.log.debug('save new trigger height: ' + shutterSettings[s].triggerHeight + '%'); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is not active anymore'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); + adapter.log.debug(`save new trigger height: ${shutterSettings[s].triggerHeight}%`); + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is not active anymore`); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); } else if (shutterSettings[s].triggerAction == 'sunProtect' && shutterSettings[s].KeepSunProtect === false && (parseFloat(shutterSettings[s].triggerHeight) == parseFloat(shutterSettings[s].heightUp) || @@ -1286,7 +1266,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { } else if (shutterSettings[s].currentAction == 'OpenInSunProtect') { shutterSettings[s].triggerAction = 'none'; - adapter.log.debug('OpenInSunProtect for ' + shutterSettings[s].shutterName + ' is not longer active'); + adapter.log.debug(`OpenInSunProtect for ${shutterSettings[s].shutterName} is not longer active`); } } } else if (shutterSettings[s].alarmTriggerAction == 'sunProtect') { @@ -1294,7 +1274,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].alarmTriggerLevel = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].alarmTriggerAction = 'up'; - adapter.log.info('SunProtect not moving up now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + shutterSettings[s].heightUp + '%'); + adapter.log.info(`SunProtect not moving up now due to active alarm: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].heightUp}%`); } } } @@ -1308,9 +1288,9 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { case 'only outside temperature': //only outside temperature _triggerState = shutterSettings[s].triggerID != '' ? await adapter.getForeignStateAsync(shutterSettings[s].triggerID).catch((e) => adapter.log.warn(e)) : null; - mustValue = ('' + shutterSettings[s].triggerState); - mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? ('' + shutterSettings[s].triggerState) : ('' + shutterSettings[s].triggerStateTilted); - currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? ('' + _triggerState.val) : ''; + mustValue = (`${shutterSettings[s].triggerState}`); + mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? (`${shutterSettings[s].triggerState}`) : (`${shutterSettings[s].triggerStateTilted}`); + currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? (`${_triggerState.val}`) : ''; if (currentValue === mustValue || currentValue === mustValueTilted || @@ -1345,7 +1325,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].lightSensor != '' && shutterSettings[s].valueLight < sunLight) { - adapter.log.debug('Stopping sunprotect delay for ' + shutterSettings[s].shutterName); + adapter.log.debug(`Stopping sunprotect delay for ${shutterSettings[s].shutterName}`); clearTimeout(shutterSettings[s].sunProtectEndtimerid); shutterSettings[s].sunProtectEndtimerid = ''; } @@ -1368,7 +1348,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); if (_shutterState?.val !== null && _shutterState?.val !== undefined) { - adapter.log.debug(shutterSettings[s].shutterName + ': Check basis for sunprotect. Height:' + Math.round(_shutterState.val / vRound) * vRound + ' > HeightDownSun: ' + heightDownSun + ' AND Height:' + Math.round(_shutterState.val / vRound) * vRound + ' == currentHeight:' + shutterSettings[s].currentHeight + ' AND currentHeight:' + shutterSettings[s].currentHeight + ' == heightUp:' + shutterSettings[s].heightUp); + adapter.log.debug(`${shutterSettings[s].shutterName}: Check basis for sunprotect. Height:${Math.round(_shutterState.val / vRound) * vRound} > HeightDownSun: ${heightDownSun} AND Height:${Math.round(_shutterState.val / vRound) * vRound} == currentHeight:${shutterSettings[s].currentHeight} AND currentHeight:${shutterSettings[s].currentHeight} == heightUp:${shutterSettings[s].heightUp}`); if (((Math.round(parseFloat(_shutterState.val) / vRound) * vRound > parseFloat(heightDownSun) && convertShutter == false) || @@ -1386,46 +1366,42 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(heightDownSun), nameDevice, 'Sunprotect #418'); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is active'); - adapter.log.debug('Temperature outside: ' + outsideTemp + ' > ' + shutterSettings[s].tempOutside + ' AND Light: ' + sunLight + ' > ' + shutterSettings[s].valueLight); - adapter.log.debug('Sunprotect ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + heightDownSun + '%'); - } - // Shutter closed. Set currentAction = sunProtect when sunProtect starts => - // If shutter is opened automatically it can be opened in height heightDownSun directly - else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].heightDown) && + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is active`); + adapter.log.debug(`Temperature outside: ${outsideTemp} > ${shutterSettings[s].tempOutside} AND Light: ${sunLight} > ${shutterSettings[s].valueLight}`); + adapter.log.debug(`Sunprotect ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${heightDownSun}%`); + } else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].heightDown) && Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].currentHeight) && shutterSettings[s].currentHeight != shutterSettings[s].heightUp && shutterSettings[s].currentAction != 'down' && shutterSettings[s].currentAction != 'middle' && shutterSettings[s].currentAction != 'Xmas' && shutterSettings[s].firstCompleteUp == true) { //check currentAction!=down here. If shutter is already closed sunProtect must not be set. Otherwise shutter will be opened again when sunProtect ends! - + // Shutter closed. Set currentAction = sunProtect when sunProtect starts => + // If shutter is opened automatically it can be opened in height heightDownSun directly shutterSettings[s].currentAction = 'OpenInSunProtect'; await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }).catch((e) => adapter.log.warn(e)); - adapter.log.debug('Set sunprotect mode for ' + shutterSettings[s].shutterName + '. Currently closed. Set to sunprotect if shutter will be opened automatically'); - } - // Shutter is in position = sunProtect. Maybe restart of adapter. sunProtect not set -> - // set sunProtect again - else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(heightDownSun) && + adapter.log.debug(`Set sunprotect mode for ${shutterSettings[s].shutterName}. Currently closed. Set to sunprotect if shutter will be opened automatically`); + } else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(heightDownSun) && Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].currentHeight) && shutterSettings[s].currentHeight != shutterSettings[s].heightUp && shutterSettings[s].currentHeight != shutterSettings[s].heightDown && shutterSettings[s].currentAction == '') { - + // Shutter is in position = sunProtect. Maybe restart of adapter. sunProtect not set -> + // set sunProtect again shutterSettings[s].currentAction = 'sunProtect'; await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }).catch((e) => adapter.log.warn(e)); - adapter.log.debug(shutterSettings[s].shutterName + ': Shutter is in position sunProtect. Reset mode sunProtect to cancel sunProtect automatically. Height:' + Math.round(_shutterState.val / vRound) * vRound + ' HeightDownSun:' + heightDownSun); + adapter.log.debug(`${shutterSettings[s].shutterName}: Shutter is in position sunProtect. Reset mode sunProtect to cancel sunProtect automatically. Height:${Math.round(_shutterState.val / vRound) * vRound} HeightDownSun:${heightDownSun}`); } } } else { shutterSettings[s].alarmTriggerLevel = parseFloat(heightDownSun); shutterSettings[s].alarmTriggerAction = 'sunProtect'; - adapter.log.info('SunProtect not moving down now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%'); + adapter.log.info(`SunProtect not moving down now due to active alarm: ${shutterSettings[s].shutterName} value: ${heightDownSun}%`); } } } @@ -1445,7 +1421,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); if (_shutterState?.val !== null && _shutterState?.val !== undefined) { - adapter.log.debug(shutterSettings[s].shutterName + ': Check basis for sunprotect. Height:' + Math.round(_shutterState.val / vRound) * vRound + ' > HeightDownSun: ' + heightDownSun + ' AND Height:' + Math.round(_shutterState.val / vRound) * vRound + ' == currentHeight:' + shutterSettings[s].currentHeight + ' AND currentHeight:' + shutterSettings[s].currentHeight + ' == heightUp:' + shutterSettings[s].heightUp); + adapter.log.debug(`${shutterSettings[s].shutterName}: Check basis for sunprotect. Height:${Math.round(_shutterState.val / vRound) * vRound} > HeightDownSun: ${heightDownSun} AND Height:${Math.round(_shutterState.val / vRound) * vRound} == currentHeight:${shutterSettings[s].currentHeight} AND currentHeight:${shutterSettings[s].currentHeight} == heightUp:${shutterSettings[s].heightUp}`); if (((Math.round(parseFloat(_shutterState.val) / vRound) * vRound > parseFloat(heightDownSun) && convertShutter == false) || @@ -1460,17 +1436,17 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].triggerHeight = parseFloat(heightDownSun); shutterSettings[s].triggerAction = 'sunProtect'; - adapter.log.info(' Will sunprotect ID: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%' + ' after the window has been closed '); + adapter.log.info(` Will sunprotect ID: ${shutterSettings[s].shutterName} value: ${heightDownSun}%` + ` after the window has been closed `); - adapter.log.debug('save new trigger height: ' + heightDownSun + '%'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); + adapter.log.debug(`save new trigger height: ${heightDownSun}%`); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); } } } else { shutterSettings[s].alarmTriggerLevel = parseFloat(heightDownSun); shutterSettings[s].alarmTriggerAction = 'sunProtect'; - adapter.log.info('SunProtect not moving down now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%'); + adapter.log.info(`SunProtect not moving down now due to active alarm: ${shutterSettings[s].shutterName} value: ${heightDownSun}%`); } } @@ -1521,17 +1497,16 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].heightUp), nameDevice, 'Sunprotect #419'); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is not active'); - adapter.log.debug('Temperature outside: ' + outsideTemp + ' < ' + hysteresisOutside + ' OR Light: ' + sunLight + ' < ' + hysteresisLight); - adapter.log.debug('Sunprotect ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterSettings[s].heightUp + '%'); - } - else if (shutterSettings[s].currentAction == 'OpenInSunProtect') { + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is not active`); + adapter.log.debug(`Temperature outside: ${outsideTemp} < ${hysteresisOutside} OR Light: ${sunLight} < ${hysteresisLight}`); + adapter.log.debug(`Sunprotect ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${shutterSettings[s].heightUp}%`); + } else if (shutterSettings[s].currentAction == 'OpenInSunProtect') { shutterSettings[s].sunProtectEndtimerid = '' shutterSettings[s].currentAction = 'none'; await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }).catch((e) => adapter.log.warn(e)); - adapter.log.debug('OpenInSunProtect for ' + shutterSettings[s].shutterName + ' is not longer active'); + adapter.log.debug(`OpenInSunProtect for ${shutterSettings[s].shutterName} is not longer active`); } } } else if (shutterSettings[s].alarmTriggerAction == 'sunProtect') { @@ -1539,7 +1514,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].alarmTriggerLevel = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].alarmTriggerAction = 'up'; - adapter.log.info('SunProtect not moving up now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + shutterSettings[s].heightUp + '%'); + adapter.log.info(`SunProtect not moving up now due to active alarm: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].heightUp}%`); } } } @@ -1583,11 +1558,11 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].triggerAction = 'up'; shutterSettings[s].sunProtectEndtimerid = ''; - adapter.log.info(' Will end sunprotect ID: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%' + ' after the window has been closed '); + adapter.log.info(` Will end sunprotect ID: ${shutterSettings[s].shutterName} value: ${heightDownSun}%` + ` after the window has been closed `); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is not active anymore'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); - adapter.log.debug('save new trigger height: ' + shutterSettings[s].triggerHeight + '%'); + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is not active anymore`); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); + adapter.log.debug(`save new trigger height: ${shutterSettings[s].triggerHeight}%`); } else if (shutterSettings[s].triggerAction == 'sunProtect' && shutterSettings[s].KeepSunProtect === false && (parseFloat(shutterSettings[s].triggerHeight) == parseFloat(shutterSettings[s].heightUp) || @@ -1605,7 +1580,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].triggerAction = 'none'; shutterSettings[s].sunProtectEndtimerid = ''; - adapter.log.debug('OpenInSunProtect for ' + shutterSettings[s].shutterName + ' is not longer active'); + adapter.log.debug(`OpenInSunProtect for ${shutterSettings[s].shutterName} is not longer active`); } } } else if (shutterSettings[s].alarmTriggerAction == 'sunProtect') { @@ -1613,7 +1588,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].alarmTriggerLevel = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].alarmTriggerAction = 'up'; - adapter.log.info('SunProtect not moving up now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + shutterSettings[s].heightUp + '%'); + adapter.log.info(`SunProtect not moving up now due to active alarm: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].heightUp}%`); } } } @@ -1627,9 +1602,9 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { case 'only inside temperature': //only inside temperature _triggerState = shutterSettings[s].triggerID != '' ? await adapter.getForeignStateAsync(shutterSettings[s].triggerID).catch((e) => adapter.log.warn(e)) : null; - mustValue = ('' + shutterSettings[s].triggerState); - mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? ('' + shutterSettings[s].triggerState) : ('' + shutterSettings[s].triggerStateTilted); - currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? ('' + _triggerState.val) : ''; + mustValue = (`${shutterSettings[s].triggerState}`); + mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? (`${shutterSettings[s].triggerState}`) : (`${shutterSettings[s].triggerStateTilted}`); + currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? (`${_triggerState.val}`) : ''; if ((currentValue === mustValue || currentValue === mustValueTilted) && @@ -1675,29 +1650,26 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(heightDownSun), nameDevice, 'Sunprotect #420'); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is active'); + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is active`); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - adapter.log.debug('Sunprotect ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + heightDownSun + '%'); - } - // Shutter closed. Set currentAction = sunProtect when sunProtect starts => - // If shutter is opened automatically it can be opened in height heightDownSun directly - else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].heightDown) && + adapter.log.debug(`Sunprotect ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${heightDownSun}%`); + } else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].heightDown) && Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].currentHeight) && shutterSettings[s].currentHeight != shutterSettings[s].heightUp && shutterSettings[s].currentAction != 'down' && shutterSettings[s].currentAction != 'middle' && shutterSettings[s].currentAction != 'Xmas' && shutterSettings[s].firstCompleteUp == true) { //check currentAction!=down here. If shutter is already closed sunProtect must not be set. Otherwise shutter will be opened again when sunProtect ends! - + // Shutter closed. Set currentAction = sunProtect when sunProtect starts => + // If shutter is opened automatically it can be opened in height heightDownSun directly shutterSettings[s].currentAction = 'OpenInSunProtect'; await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }).catch((e) => adapter.log.warn(e)); - adapter.log.debug('Set sunprotect mode for ' + shutterSettings[s].shutterName + '. Currently closed. Set to sunprotect if shutter will be opened automatically'); - } - // Shutter is in position = sunProtect. Maybe restart of adapter. sunProtect not set -> - // set sunProtect again - else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(heightDownSun) && + adapter.log.debug(`Set sunprotect mode for ${shutterSettings[s].shutterName}. Currently closed. Set to sunprotect if shutter will be opened automatically`); + } else if (Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(heightDownSun) && + // Shutter is in position = sunProtect. Maybe restart of adapter. sunProtect not set -> + // set sunProtect again Math.round(parseFloat(_shutterState.val) / vRound) * vRound == parseFloat(shutterSettings[s].currentHeight) && shutterSettings[s].currentHeight != shutterSettings[s].heightUp && shutterSettings[s].currentHeight != shutterSettings[s].heightDown && @@ -1707,14 +1679,14 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }).catch((e) => adapter.log.warn(e)); - adapter.log.debug(shutterSettings[s].shutterName + ': Shutter is in position sunProtect. Reset mode sunProtect to cancel sunProtect automatically. Height:' + Math.round(_shutterState.val / vRound) * vRound + ' HeightDownSun:' + heightDownSun); + adapter.log.debug(`${shutterSettings[s].shutterName}: Shutter is in position sunProtect. Reset mode sunProtect to cancel sunProtect automatically. Height:${Math.round(_shutterState.val / vRound) * vRound} HeightDownSun:${heightDownSun}`); } } } else { shutterSettings[s].alarmTriggerLevel = parseFloat(heightDownSun); shutterSettings[s].alarmTriggerAction = 'sunProtect'; - adapter.log.info('SunProtect not moving down now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%'); + adapter.log.info(`SunProtect not moving down now due to active alarm: ${shutterSettings[s].shutterName} value: ${heightDownSun}%`); } } } @@ -1732,7 +1704,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { if (_shutterState?.val !== null && _shutterState?.val !== undefined) { - adapter.log.debug(shutterSettings[s].shutterName + ': Check basis for sunprotect. Height:' + Math.round(_shutterState.val / vRound) * vRound + ' > HeightDownSun: ' + heightDownSun + ' AND Height:' + Math.round(_shutterState.val / vRound) * vRound + ' == currentHeight:' + shutterSettings[s].currentHeight + ' AND currentHeight:' + shutterSettings[s].currentHeight + ' == heightUp:' + shutterSettings[s].heightUp); + adapter.log.debug(`${shutterSettings[s].shutterName}: Check basis for sunprotect. Height:${Math.round(_shutterState.val / vRound) * vRound} > HeightDownSun: ${heightDownSun} AND Height:${Math.round(_shutterState.val / vRound) * vRound} == currentHeight:${shutterSettings[s].currentHeight} AND currentHeight:${shutterSettings[s].currentHeight} == heightUp:${shutterSettings[s].heightUp}`); if (((Math.round(parseFloat(_shutterState.val) / vRound) * vRound > parseFloat(heightDownSun) && convertShutter == false) || @@ -1747,17 +1719,17 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].triggerAction = 'sunProtect'; shutterSettings[s].triggerHeight = parseFloat(heightDownSun); - adapter.log.info(' Will sunprotect ID: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%' + ' after the window has been closed '); + adapter.log.info(` Will sunprotect ID: ${shutterSettings[s].shutterName} value: ${heightDownSun}%` + ` after the window has been closed `); - adapter.log.debug('save new trigger height: ' + heightDownSun + '%'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); + adapter.log.debug(`save new trigger height: ${heightDownSun}%`); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); } } } else { shutterSettings[s].alarmTriggerLevel = parseFloat(heightDownSun); shutterSettings[s].alarmTriggerAction = 'sunProtect'; - adapter.log.info('SunProtect not moving down now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%'); + adapter.log.info(`SunProtect not moving down now due to active alarm: ${shutterSettings[s].shutterName} value: ${heightDownSun}%`); } } } @@ -1787,15 +1759,14 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].heightUp), nameDevice, 'Sunprotect #421'); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is not active'); - adapter.log.debug('Sunprotect ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterSettings[s].heightUp + '%'); - } - else if (shutterSettings[s].currentAction == 'OpenInSunProtect') { + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is not active`); + adapter.log.debug(`Sunprotect ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${shutterSettings[s].heightUp}%`); + } else if (shutterSettings[s].currentAction == 'OpenInSunProtect') { shutterSettings[s].currentAction = 'none'; await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }).catch((e) => adapter.log.warn(e)); - adapter.log.debug('OpenInSunProtect for ' + shutterSettings[s].shutterName + ' is not longer active'); + adapter.log.debug(`OpenInSunProtect for ${shutterSettings[s].shutterName} is not longer active`); } } } else if (shutterSettings[s].alarmTriggerAction == 'sunProtect') { @@ -1803,7 +1774,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].alarmTriggerLevel = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].alarmTriggerAction = 'up'; - adapter.log.info('SunProtect not moving up now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + shutterSettings[s].heightUp + '%'); + adapter.log.info(`SunProtect not moving up now due to active alarm: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].heightUp}%`); } } } @@ -1827,11 +1798,11 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].triggerHeight = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].triggerAction = 'up'; - adapter.log.info(' Will end sunprotect ID: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%' + ' after the window has been closed '); + adapter.log.info(` Will end sunprotect ID: ${shutterSettings[s].shutterName} value: ${heightDownSun}%` + ` after the window has been closed `); - adapter.log.debug('save new trigger height: ' + shutterSettings[s].triggerHeight + '%'); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is not active anymore'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); + adapter.log.debug(`save new trigger height: ${shutterSettings[s].triggerHeight}%`); + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is not active anymore`); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); } else if (shutterSettings[s].triggerAction == 'sunProtect' && shutterSettings[s].KeepSunProtect === false && @@ -1848,7 +1819,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { } else if (shutterSettings[s].currentAction == 'OpenInSunProtect') { shutterSettings[s].triggerAction = 'none'; - adapter.log.debug('OpenInSunProtect for ' + shutterSettings[s].shutterName + ' is not longer active'); + adapter.log.debug(`OpenInSunProtect for ${shutterSettings[s].shutterName} is not longer active`); } } } else if (shutterSettings[s].alarmTriggerAction == 'sunProtect') { @@ -1856,7 +1827,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].alarmTriggerLevel = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].alarmTriggerAction = 'up'; - adapter.log.info('SunProtect not moving up now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + shutterSettings[s].heightUp + '%'); + adapter.log.info(`SunProtect not moving up now due to active alarm: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].heightUp}%`); } } } @@ -1879,7 +1850,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { // +++++++++++++++++ End of sunprotect with Elevationslimit +++++++++++++++ if (shutterSettings) { - const result = shutterSettings.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); + const result = shutterSettings.filter((d) => d.enabled === true || d.enabled === 'true'); const sunProtEndStart = parseInt(adapter.config.sunProtEndElevation); const sunProtEndStop = (adapter.config.sunProtEndElevation - 1); @@ -1900,10 +1871,10 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { if (parseFloat(shutterSettings[s].heightDown) < parseFloat(shutterSettings[s].heightUp)) { convertShutter = false; - adapter.log.debug(shutterSettings[s].shutterName + ' level conversion is disabled ...'); + adapter.log.debug(`${shutterSettings[s].shutterName} level conversion is disabled ...`); } else if (parseFloat(shutterSettings[s].heightDown) > parseFloat(shutterSettings[s].heightUp)) { convertShutter = true; - adapter.log.debug(shutterSettings[s].shutterName + ' level conversion is enabled'); + adapter.log.debug(`${shutterSettings[s].shutterName} level conversion is enabled`); } const pendingAlarm = await checkPendingAlarm(adapter, shutterSettings[s]); @@ -1912,9 +1883,9 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { if (_autoSunState?.val === true) { const _triggerState = shutterSettings[s].triggerID != '' ? await adapter.getForeignStateAsync(shutterSettings[s].triggerID).catch((e) => adapter.log.warn(e)) : null; - const mustValue = ('' + shutterSettings[s].triggerState); - const mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? ('' + shutterSettings[s].triggerState) : ('' + shutterSettings[s].triggerStateTilted); - const currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? ('' + _triggerState.val) : ''; + const mustValue = (`${shutterSettings[s].triggerState}`); + const mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? (`${shutterSettings[s].triggerState}`) : (`${shutterSettings[s].triggerStateTilted}`); + const currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? (`${_triggerState.val}`) : ''; if ((currentValue === mustValue || currentValue === mustValueTilted) || @@ -1925,7 +1896,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { (shutterSettings[s].triggerID == '')) { if (shutterSettings[s].sunProtectEndtimerid != '' && shutterSettings[s].sunProtectEndtimerid != '0') { - adapter.log.debug('Stopping sunprotect delay for ' + shutterSettings[s].shutterName); + adapter.log.debug(`Stopping sunprotect delay for ${shutterSettings[s].shutterName}`); clearTimeout(shutterSettings[s].sunProtectEndtimerid); shutterSettings[s].sunProtectEndtimerid = ''; } @@ -1946,9 +1917,9 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].heightUp), nameDevice, 'Sunprotect #422'); - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is completed'); + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is completed`); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - adapter.log.debug('save current height: ' + shutterSettings[s].currentHeight + '%' + ' from ' + shutterSettings[s].shutterName); + adapter.log.debug(`save current height: ${shutterSettings[s].currentHeight}%` + ` from ${shutterSettings[s].shutterName}`); } } } else if (shutterSettings[s].alarmTriggerAction == 'sunProtect') { @@ -1956,7 +1927,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].alarmTriggerLevel = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].alarmTriggerAction = 'none'; - adapter.log.info('SunProtect not moving up now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + shutterSettings[s].heightUp + '%'); + adapter.log.info(`SunProtect not moving up now due to active alarm: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].heightUp}%`); } } if (currentValue != mustValue && @@ -1967,7 +1938,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { clearTimeout(shutterSettings[s].sunProtectEndtimerid); shutterSettings[s].sunProtectEndtimerid = ''; - adapter.log.debug('Stopping sunprotect delay for ' + shutterSettings[s].shutterName); + adapter.log.debug(`Stopping sunprotect delay for ${shutterSettings[s].shutterName}`); } if (pendingAlarm == false) { @@ -1984,12 +1955,12 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].triggerHeight = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].triggerAction = 'up'; shutterSettings[s].sunProtectEndtimerid = ''; - adapter.log.debug('Sunprotect for ' + shutterSettings[s].shutterName + ' is not active anymore'); - adapter.log.info(' Will end sunprotect ID: ' + shutterSettings[s].shutterName + ' value: ' + heightDownSun + '%' + ' after the window has been closed '); + adapter.log.debug(`Sunprotect for ${shutterSettings[s].shutterName} is not active anymore`); + adapter.log.info(` Will end sunprotect ID: ${shutterSettings[s].shutterName} value: ${heightDownSun}%` + ` after the window has been closed `); - adapter.log.debug('save new trigger height: ' + shutterSettings[s].triggerHeight + '%'); + adapter.log.debug(`save new trigger height: ${shutterSettings[s].triggerHeight}%`); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); shutterSettings[s].sunProtectEndtimerid = '' } } @@ -1998,7 +1969,7 @@ async function sunProtect(adapter, elevation, azimuth, shutterSettings) { shutterSettings[s].alarmTriggerLevel = parseFloat(shutterSettings[s].heightUp); shutterSettings[s].alarmTriggerAction = 'none'; - adapter.log.info('SunProtect not moving up now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + shutterSettings[s].heightUp + '%'); + adapter.log.info(`SunProtect not moving up now due to active alarm: ${shutterSettings[s].shutterName} value: ${shutterSettings[s].heightUp}%`); } } await sleep(driveDelayUpSleep); diff --git a/lib/tools.js b/lib/tools.js index 53f9b6d1..d57458f3 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -2,6 +2,7 @@ const axios = require('axios'); /** * Tests whether the given variable is a real object and not an Array + * * @param {any} it The variable to test * @returns {it is Record} */ @@ -15,6 +16,7 @@ function isObject(it) { /** * Tests whether the given variable is really an Array + * * @param {any} it The variable to test * @returns {it is any[]} */ @@ -25,6 +27,7 @@ function isArray(it) { /** * Translates text to the target language. Automatically chooses the right translation API. + * * @param {string} text The text to translate * @param {string} targetLang The target languate * @param {string} [yandexApiKey] The yandex API key. You can create one for free at https://translate.yandex.com/developers @@ -43,6 +46,7 @@ async function translateText(text, targetLang, yandexApiKey) { /** * Translates text with Yandex API + * * @param {string} text The text to translate * @param {string} targetLang The target languate * @param {string} [apiKey] The yandex API key. You can create one for free at https://translate.yandex.com/developers @@ -67,6 +71,7 @@ async function translateYandex(text, targetLang, apiKey) { /** * Translates text with Google API + * * @param {string} text The text to translate * @param {string} targetLang The target languate * @returns {Promise} diff --git a/lib/triggerChange.js b/lib/triggerChange.js index 0a9afaaa..ec6eb379 100644 --- a/lib/triggerChange.js +++ b/lib/triggerChange.js @@ -15,8 +15,8 @@ async function sleep(ms) { async function triggerChange(resTriggerChange, adapter, shutterSettings) { if (shutterSettings) { - const arrayChangeTrigger = shutterSettings.filter((/** @type {{ triggerID: any; }} */ d) => d.triggerID == resTriggerChange); // Filter changed Trigger - const result = arrayChangeTrigger.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); // Filter enabled + const arrayChangeTrigger = shutterSettings.filter((d) => d.triggerID == resTriggerChange); // Filter changed Trigger + const result = arrayChangeTrigger.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled for (const i in result) { for (const s in shutterSettings) { @@ -34,9 +34,9 @@ async function triggerChange(resTriggerChange, adapter, shutterSettings) { const _triggerState = shutterSettings[s].triggerID != '' ? await adapter.getForeignStateAsync(shutterSettings[s].triggerID).catch((e) => adapter.log.warn(e)) : null; - const mustValue = ('' + shutterSettings[s].triggerState); - const mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? ('' + shutterSettings[s].triggerState) : ('' + shutterSettings[s].triggerStateTilted); - let currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? ('' + _triggerState.val) : ''; + const mustValue = (`${shutterSettings[s].triggerState}`); + const mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? (`${shutterSettings[s].triggerState}`) : (`${shutterSettings[s].triggerStateTilted}`); + let currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? (`${_triggerState.val}`) : ''; if (currentValue != mustValue) { const setTriggerHeight = currentValue == mustValueTilted ? parseFloat(shutterSettings[s].triggerDriveTildet) : parseFloat(shutterSettings[s].triggerDrive); @@ -71,8 +71,8 @@ async function triggerChange(resTriggerChange, adapter, shutterSettings) { const _triggerState = shutterSettings[s].triggerID != '' ? await adapter.getForeignStateAsync(shutterSettings[s].triggerID).catch((e) => adapter.log.warn(e)) : null; - const mustValue = ('' + shutterSettings[s].triggerState); - currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? ('' + _triggerState.val) : ''; + const mustValue = (`${shutterSettings[s].triggerState}`); + currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? (`${_triggerState.val}`) : ''; if (currentValue != mustValue) { shutterSettings[s].currentHeight = setTriggerHeight; @@ -99,7 +99,7 @@ async function triggerChange(resTriggerChange, adapter, shutterSettings) { } } } - if (shutterSettings[s].triggerChange == 'onlyDown' || + if (shutterSettings[s].triggerChange == 'onlyDown' || shutterSettings[s].triggerChange == 'upDown') { const nameDevice = shutterSettings[s].shutterName.replace(/[.;, ]/g, '_'); @@ -110,8 +110,8 @@ async function triggerChange(resTriggerChange, adapter, shutterSettings) { const _triggerState = shutterSettings[s].triggerID != '' ? await adapter.getForeignStateAsync(shutterSettings[s].triggerID).catch((e) => adapter.log.warn(e)) : null; if (_triggerState?.val !== null && _triggerState?.val !== undefined) { - const currentValue = ('' + _triggerState.val); - const mustValue = ('' + shutterSettings[s].triggerState); + const currentValue = (`${_triggerState.val}`); + const mustValue = (`${shutterSettings[s].triggerState}`); if (currentValue === mustValue) { const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); @@ -139,8 +139,8 @@ async function triggerChange(resTriggerChange, adapter, shutterSettings) { const _triggerState = shutterSettings[s].triggerID != '' ? await adapter.getForeignStateAsync(shutterSettings[s].triggerID).catch((e) => adapter.log.warn(e)) : null; if (_triggerState?.val !== null && _triggerState?.val !== undefined) { - const currentValue = ('' + _triggerState.val); - const mustValue = ('' + shutterSettings[s].triggerState); + const currentValue = (`${_triggerState.val}`); + const mustValue = (`${shutterSettings[s].triggerState}`); if (currentValue === mustValue) { shutterSettings[s].currentHeight = shutterSettings[s].triggerHeight; @@ -175,7 +175,7 @@ async function triggerChange(resTriggerChange, adapter, shutterSettings) { } } } - if (shutterSettings[s].triggerChange == 'off' && + if (shutterSettings[s].triggerChange == 'off' && shutterSettings[s].driveAfterClose == true) { const nameDevice = shutterSettings[s].shutterName.replace(/[.;, ]/g, '_'); @@ -186,13 +186,13 @@ async function triggerChange(resTriggerChange, adapter, shutterSettings) { const _triggerState = shutterSettings[s].triggerID != '' ? await adapter.getForeignStateAsync(shutterSettings[s].triggerID).catch((e) => adapter.log.warn(e)) : null; if (_triggerState?.val !== null && _triggerState?.val !== undefined) { - const currentValue = ('' + _triggerState.val); - const mustValue = ('' + shutterSettings[s].triggerState); - const mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? ('' + shutterSettings[s].triggerState) : ('' + shutterSettings[s].triggerStateTilted); + const currentValue = (`${_triggerState.val}`); + const mustValue = (`${shutterSettings[s].triggerState}`); + const mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? (`${shutterSettings[s].triggerState}`) : (`${shutterSettings[s].triggerStateTilted}`); - if (currentValue === mustValue || + if (currentValue === mustValue || currentValue === mustValueTilted) { - + const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); if (_shutterState?.val !== null && _shutterState?.val !== undefined) { adapter.log.debug(`${shutterSettings[s].shutterName} - shutter current state.val is: ${Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound}%`); @@ -214,8 +214,8 @@ async function triggerChange(resTriggerChange, adapter, shutterSettings) { const _triggerState = shutterSettings[s].triggerID != '' ? await adapter.getForeignStateAsync(shutterSettings[s].triggerID).catch((e) => adapter.log.warn(e)) : null; if (_triggerState?.val !== null && _triggerState?.val !== undefined) { - const currentValue = ('' + _triggerState.val); - const mustValue = ('' + shutterSettings[s].triggerState); + const currentValue = (`${_triggerState.val}`); + const mustValue = (`${shutterSettings[s].triggerState}`); if (currentValue === mustValue) { shutterSettings[s].currentHeight = shutterSettings[s].triggerHeight; diff --git a/main.js b/main.js index 44a58e58..3834b6fe 100644 --- a/main.js +++ b/main.js @@ -176,7 +176,7 @@ function startAdapter(options) { schedule.cancelJob('shutterDownBrightness'); - const downBrightness = schedule.scheduleJob('shutterDownBrightness', downTime[1] + ' ' + downTime[0] + ' * * *', async function () { + const downBrightness = schedule.scheduleJob('shutterDownBrightness', `${downTime[1]} ${downTime[0]} * * *`, async function () { adapter.log.debug(`Brightness State Down is: ${brightnessDown}`); adapter.log.debug(`Brightness sensor value: ${state.val}`); shutterBrightnessSensor(adapter, state.val, shutterSettings, brightnessDown); @@ -246,7 +246,7 @@ function startAdapter(options) { }); resShutterState.forEach(async function (resShutterID) { if (id === resShutterID && state.ts === state.lc) { - const result = shutterSettings.filter((/** @type {{ name: any; }} */ d) => d.name === resShutterID); + const result = shutterSettings.filter((d) => d.name === resShutterID); if (adapter.config.currentShutterState === true && adapter.config.currentShutterStateTime) { waitTime4StateCheck = (adapter.config.currentShutterStateTime ? adapter.config.currentShutterStateTime * 1000 : 60000); @@ -311,8 +311,7 @@ function startAdapter(options) { shutterSettings[s].currentAction = 'Manu_Mode'; shutterSettings[s].triggerAction = 'Manu_Mode'; adapter.log.debug(`set Manu_Mode #1 ${shutterSettings[s].shutterName}`); - } - else { + } else { /* Shutter is closed -> open manually to heightUp (should be 100% or 0%) before it has been opened automatically -> enable possibility to activate sunprotect height if required --> if sunprotect is required: shutter is set to sunProtect height @@ -331,13 +330,12 @@ function startAdapter(options) { adapter.log.debug(`Reset firstCompleteUp #1 for ${shutterSettings[s].shutterName}`); adapter.log.debug(`${shutterSettings[s].shutterName} opened manually to ${shutterSettings[s].heightUp}% | Old value = ${shutterSettings[s].oldHeight}% | New value = ${Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound}% | Possibility to activate sunprotect enabled`); - await adapter.setStateAsync('shutters.autoState.' + nameDevice, { val: shutterSettings[s].currentAction, ack: true }) + await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }) .catch((e) => adapter.log.warn(e)); - await adapter.setStateAsync('shutters.autoLevel.' + nameDevice, { val: parseFloat(shutterSettings[s].currentHeight), ack: true }) + await adapter.setStateAsync(`shutters.autoLevel.${nameDevice}`, { val: parseFloat(shutterSettings[s].currentHeight), ack: true }) .catch((e) => adapter.log.warn(e)); - } - else { + } else { shutterSettings[s].currentAction = 'Manu_Mode'; shutterSettings[s].triggerAction = 'Manu_Mode'; adapter.log.debug(`set Manu_Mode #2 ${shutterSettings[s].shutterName}`); @@ -357,7 +355,7 @@ function startAdapter(options) { adapter.log.debug(`#1 currentShutterState: ${adapter.config.currentShutterState === true ? 'activated' : 'disabled'}`); adapter.log.debug(`#1 currentShutterStateTime: ${adapter.config.currentShutterStateTime} seconds`); - await adapter.setStateAsync('shutters.autoState.' + nameDevice, { val: shutterSettings[s].currentAction, ack: true }) + await adapter.setStateAsync(`shutters.autoState.${nameDevice}`, { val: shutterSettings[s].currentAction, ack: true }) .catch((e) => adapter.log.warn(e)); await sleep(2000); @@ -442,7 +440,7 @@ function startAdapter(options) { } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// +++++++++++++++++ Check all shutter values ​​and set default values ​​if values ​​are not available ++++++++++++++++++++++++++++ +/* ************************ Check all shutter values​and set default values ​​if values ​are not available ********************************* */ async function shutterConfigCheck() { return new Promise(async (resolve) => { @@ -561,16 +559,16 @@ async function saveCurrentStates(onStart) { currentStates[`${nameDevice}`] = null; const states = ({ - "shutterName": shutterSettings[s].shutterName, - "currentAction": shutterSettings[s].currentAction, - "currentHeight": shutterSettings[s].currentHeight, - "triggerAction": shutterSettings[s].triggerAction, - "triggerHeight": shutterSettings[s].triggerHeight, - "oldHeight": shutterSettings[s].oldHeight, - "firstCompleteUp": shutterSettings[s].firstCompleteUp, - "alarmTriggerLevel": shutterSettings[s].alarmTriggerLevel, - "alarmTriggerAction": shutterSettings[s].alarmTriggerAction, - "lastAutoAction": shutterSettings[s].lastAutoAction + shutterName: shutterSettings[s].shutterName, + currentAction: shutterSettings[s].currentAction, + currentHeight: shutterSettings[s].currentHeight, + triggerAction: shutterSettings[s].triggerAction, + triggerHeight: shutterSettings[s].triggerHeight, + oldHeight: shutterSettings[s].oldHeight, + firstCompleteUp: shutterSettings[s].firstCompleteUp, + alarmTriggerLevel: shutterSettings[s].alarmTriggerLevel, + alarmTriggerAction: shutterSettings[s].alarmTriggerAction, + lastAutoAction: shutterSettings[s].lastAutoAction }); currentStates[`${nameDevice}`] = states; @@ -829,13 +827,13 @@ function shutterDriveCalc() { adapter.log.debug('calculate astrodata ...'); // format sunset/sunrise time from the Date object - sunsetStr = ('0' + times.sunset.getHours()).slice(-2) + ':' + ('0' + times.sunset.getMinutes()).slice(-2); - sunriseStr = ('0' + times.sunrise.getHours()).slice(-2) + ':' + ('0' + times.sunrise.getMinutes()).slice(-2); + sunsetStr = `${(`0${times.sunset.getHours()}`).slice(-2)}:${(`0${times.sunset.getMinutes()}`).slice(-2)}`; + sunriseStr = `${(`0${times.sunrise.getHours()}`).slice(-2)}:${(`0${times.sunrise.getMinutes()}`).slice(-2)}`; dayStr = times.sunrise.getDay(); // format goldenhour/goldenhourend time from the Date object - goldenHour = ('0' + times.goldenHour.getHours()).slice(-2) + ':' + ('0' + times.goldenHour.getMinutes()).slice(-2); - goldenHourEnd = ('0' + times.goldenHourEnd.getHours()).slice(-2) + ':' + ('0' + times.goldenHourEnd.getMinutes()).slice(-2); + goldenHour = `${(`0${times.goldenHour.getHours()}`).slice(-2)}:${(`0${times.goldenHour.getMinutes()}`).slice(-2)}`; + goldenHourEnd = `${(`0${times.goldenHourEnd.getHours()}`).slice(-2)}:${(`0${times.goldenHourEnd.getMinutes()}`).slice(-2)}`; } catch (e) { adapter.log.warn('cannot calculate astrodata ... please check your config for latitude und longitude!!'); } @@ -1375,10 +1373,12 @@ function sunPos() { // ++++++++++++++++++++ Add delay Time ++++++++++++++++++++++++ function addMinutes(time, minsToAdd) { - function D(J) { return (J < 10 ? '0' : '') + J; } + function D(J) { + return (J < 10 ? '0' : '') + J; + } const piece = time.split(':'); const mins = piece[0] * 60 + +piece[1] + +minsToAdd; - return D(mins % (24 * 60) / 60 | 0) + ':' + D(mins % 60); + return `${D(mins % (24 * 60) / 60 | 0)}:${D(mins % 60)}`; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1395,15 +1395,15 @@ function delayCalc() { if (resultFull) { if (upTimeLiving === upTimeSleep) { - const resLiving = resultFull.filter((/** @type {{ typeUp: string; }} */ d) => d.typeUp === 'living'); // Filter Area Living - const result = resLiving.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); // Filter enabled + const resLiving = resultFull.filter((d) => d.typeUp === 'living'); // Filter Area Living + const result = resLiving.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled for (const i in result) { delayUp++; } if (autoLivingStr === true) { - const resLivingAuto = resultFull.filter((/** @type {{ typeUp: string; }} */ d) => d.typeUp === 'living-auto'); // Filter Area Living - const result2 = resLivingAuto.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); // Filter enabled + const resLivingAuto = resultFull.filter((d) => d.typeUp === 'living-auto'); // Filter Area Living + const result2 = resLivingAuto.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled for (const i in result2) { delayUp++; @@ -1414,15 +1414,15 @@ function delayCalc() { if (upTimeSleep === upTimeChildren) { delayUpChildren = delayUp; - const resLiving = resultFull.filter((/** @type {{ typeUp: string; }} */ d) => d.typeUp === 'sleep'); // Filter Area Sleep - const result = resLiving.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); // Filter enabled + const resLiving = resultFull.filter((d) => d.typeUp === 'sleep'); // Filter Area Sleep + const result = resLiving.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled for (const i in result) { delayUpChildren++; } if (autoSleepStr === true) { - const resLivingAuto = resultFull.filter((/** @type {{ typeUp: string; }} */ d) => d.typeUp === 'sleep-auto'); // Filter Area Sleep - const result2 = resLivingAuto.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); // Filter enabled + const resLivingAuto = resultFull.filter((d) => d.typeUp === 'sleep-auto'); // Filter Area Sleep + const result2 = resLivingAuto.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled for (const i in result2) { delayUpChildren++; @@ -1430,15 +1430,15 @@ function delayCalc() { } } if (downTimeLiving === downTimeSleep) { - const resLiving2 = resultFull.filter((/** @type {{ typeDown: string; }} */ d) => d.typeDown === 'living'); // Filter Area Living - const result3 = resLiving2.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); // Filter enabled + const resLiving2 = resultFull.filter((d) => d.typeDown === 'living'); // Filter Area Living + const result3 = resLiving2.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled for (const i in result3) { delayDown++; } if (autoLivingStr === true) { - const resLivingAuto2 = resultFull.filter((/** @type {{ typeDown: string; }} */ d) => d.typeDown === 'living-auto'); // Filter Area Living - const result4 = resLivingAuto2.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); // Filter enabled + const resLivingAuto2 = resultFull.filter((d) => d.typeDown === 'living-auto'); // Filter Area Living + const result4 = resLivingAuto2.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled for (const i in result4) { delayDown++; @@ -1449,16 +1449,16 @@ function delayCalc() { if (downTimeSleep === downTimeChildren) { delayDownChildren = delayDown; - const resLiving2 = resultFull.filter((/** @type {{ typeDown: string; }} */ d) => d.typeDown === 'sleep'); // Filter Area Sleep - const result3 = resLiving2.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); // Filter enabled + const resLiving2 = resultFull.filter((d) => d.typeDown === 'sleep'); // Filter Area Sleep + const result3 = resLiving2.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled for (const i in result3) { delayDownChildren++; } if (autoSleepStr === true) { - const resLivingAuto2 = resultFull.filter((/** @type {{ typeDown: string; }} */ d) => d.typeDown === 'sleep-auto'); // Filter Area Sleep - const result4 = resLivingAuto2.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); // Filter enabled + const resLivingAuto2 = resultFull.filter((d) => d.typeDown === 'sleep-auto'); // Filter Area Sleep + const result4 = resLivingAuto2.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled for (const i in result4) { delayDownChildren++; @@ -1487,15 +1487,15 @@ async function createShutter() { try { // Create Object for auto up await adapter.setObjectNotExistsAsync(`shutters.autoUp.${objectName}`, { - "type": "state", - "common": { - "role": "switch", - "name": result[i].shutterName, - "type": "boolean", - "read": true, - "write": true + type: "state", + common: { + role: "switch", + name: result[i].shutterName, + type: "boolean", + read: true, + write: true }, - "native": {}, + native: {}, }); const _autoUpState = await adapter.getStateAsync(`shutters.autoUp.${objectName}`).catch((e) => adapter.log.warn(e)); @@ -1507,15 +1507,15 @@ async function createShutter() { // Create Object for auto down await adapter.setObjectNotExistsAsync(`shutters.autoDown.${objectName}`, { - "type": "state", - "common": { - "role": "switch", - "name": result[i].shutterName, - "type": "boolean", - "read": true, - "write": true + type: "state", + common: { + role: "switch", + name: result[i].shutterName, + type: "boolean", + read: true, + write: true }, - "native": {}, + native: {}, }); const _autoDownState = await adapter.getStateAsync(`shutters.autoDown.${objectName}`).catch((e) => adapter.log.warn(e)); @@ -1527,15 +1527,15 @@ async function createShutter() { // Create Object for auto sun await adapter.setObjectNotExistsAsync(`shutters.autoSun.${objectName}`, { - "type": "state", - "common": { - "role": "switch", - "name": result[i].shutterName, - "type": "boolean", - "read": true, - "write": true + type: "state", + common: { + role: "switch", + name: result[i].shutterName, + type: "boolean", + read: true, + write: true }, - "native": {}, + native: {}, }); const _autoSunState = await adapter.getStateAsync(`shutters.autoSun.${objectName}`).catch((e) => adapter.log.warn(e)); @@ -1547,15 +1547,15 @@ async function createShutter() { // Create Object for auto state await adapter.setObjectNotExistsAsync(`shutters.autoState.${objectName}`, { - "type": "state", - "common": { - "role": "text", - "name": result[i].shutterName, - "type": "string", - "read": true, - "write": false + type: "state", + common: { + role: "text", + name: result[i].shutterName, + type: "string", + read: true, + write: false }, - "native": {}, + native: {}, }); const _autoState = await adapter.getStateAsync(`shutters.autoState.${objectName}`).catch((e) => adapter.log.warn(e)); @@ -1567,16 +1567,16 @@ async function createShutter() { // Create Object for auto level await adapter.setObjectNotExistsAsync(`shutters.autoLevel.${objectName}`, { - "type": "state", - "common": { - "role": "value", - "name": result[i].shutterName, - "type": "number", - "unit": "%", - "read": true, - "write": false + type: "state", + common: { + role: "value", + name: result[i].shutterName, + type: "number", + unit: "%", + read: true, + write: false }, - "native": {}, + native: {}, }); const _autoLevel = await adapter.getStateAsync(`shutters.autoLevel.${objectName}`).catch((e) => adapter.log.warn(e)); @@ -1739,16 +1739,13 @@ function IsLater(timeVal, timeLimit) { ret = true; adapter.log.debug(`yes, IsLater: ${timeVal} " " ${timeLimit}`); } - } - else { + } else { adapter.log.error(`string does not contain: ${timeVal} " " ${timeLimit}`); } - } - else { + } else { adapter.log.error(`not a string '${typeof timeVal} " " ${typeof timeLimit}`); } - } - catch (e) { + } catch (e) { adapter.log.error(`exception in IsLater ["${e}"]`); } return ret; @@ -1778,16 +1775,13 @@ function IsEarlier(timeVal, timeLimit) { ret = true; adapter.log.debug(`yes, IsEarlier: ${timeVal} " " ${timeLimit}`); } - } - else { + } else { adapter.log.error(`string does not contain: ${timeVal} " " ${timeLimit}`); } - } - else { + } else { adapter.log.error(`not a string ${typeof timeVal} " " ${typeof timeLimit}`); } - } - catch (e) { + } catch (e) { adapter.log.error(`exception in IsEarlier ["${e}"]`); } return ret; @@ -1815,16 +1809,13 @@ function IsEqual(timeVal, timeLimit) { ret = true; adapter.log.debug(`yes, IsEqual: ${timeVal} " " ${timeLimit}`); } - } - else { + } else { adapter.log.error(`string does not contain: ${timeVal} " " ${timeLimit}`); } - } - else { + } else { adapter.log.error(`not a string ${typeof timeVal} " " ${typeof timeLimit}`); } - } - catch (e) { + } catch (e) { adapter.log.error(`exception in IsEqual ["${e}"]`); } return ret; @@ -1923,7 +1914,7 @@ function main(adapter) { if (shutterSettings) { const res = shutterSettings.map(({ triggerID }) => ({ triggerID })); - const resTriggerActive = res.filter((/** @type {{ triggerID: string; }} */ d) => d.triggerID != ''); + const resTriggerActive = res.filter((d) => d.triggerID != ''); for (const i in resTriggerActive) { if (resTrigger.indexOf(resTriggerActive[i].triggerID) === -1) { @@ -1936,7 +1927,7 @@ function main(adapter) { }); const resInsideTemp = shutterSettings.map(({ tempSensor }) => ({ tempSensor })); - const rescurrentInsideTemp = resInsideTemp.filter((/** @type {{ tempSensor: string; }} */ d) => d.tempSensor != ''); + const rescurrentInsideTemp = resInsideTemp.filter((d) => d.tempSensor != ''); for (const i in rescurrentInsideTemp) { if (resSunInsideTemp.indexOf(rescurrentInsideTemp[i].tempSensor) === -1) { @@ -1949,7 +1940,7 @@ function main(adapter) { }); const resOutsideTemp = shutterSettings.map(({ outsideTempSensor }) => ({ outsideTempSensor })); - const rescurrentOutsideTemp = resOutsideTemp.filter((/** @type {{ outsideTempSensor: string; }} */ d) => d.outsideTempSensor != ''); + const rescurrentOutsideTemp = resOutsideTemp.filter((d) => d.outsideTempSensor != ''); for (const i in rescurrentOutsideTemp) { if (resSunOutsideTemp.indexOf(rescurrentOutsideTemp[i].outsideTempSensor) === -1) { @@ -1962,12 +1953,12 @@ function main(adapter) { }); const resLight = shutterSettings.map(({ lightSensor }) => ({ lightSensor })); - const rescurrentLight = resLight.filter((/** @type {{ lightSensor: string; }} */ d) => d.lightSensor != ''); + const rescurrentLight = resLight.filter((d) => d.lightSensor != ''); for (const i in rescurrentLight) { if (resSunLight.indexOf(rescurrentLight[i].lightSensor) === -1) { resSunLight.push(rescurrentLight[i].lightSensor); - lastLigthSensorValue[`${rescurrentLight[i].lightSensor}`] = { "ts": 0 }; + lastLigthSensorValue[`${rescurrentLight[i].lightSensor}`] = { ts: 0 }; } } resSunLight.forEach(function (element) { @@ -1976,7 +1967,7 @@ function main(adapter) { }); const resShutter = shutterSettings.map(({ name }) => ({ name })); - const rescurrentShutter = resShutter.filter((/** @type {{ name: string; }} */ d) => d.name != ''); + const rescurrentShutter = resShutter.filter((d) => d.name != ''); for (const i in rescurrentShutter) { if (resShutterState.indexOf(rescurrentShutter[i].name) === -1) { diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 7bff724c..00000000 --- a/tsconfig.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "compileOnSave": true, - "compilerOptions": { - // do not compile anything, this file is just to configure type checking - "noEmit": true, - - // check JS files - "allowJs": true, - "checkJs": true, - - "module": "commonjs", - "moduleResolution": "node", - // this is necessary for the automatic typing of the adapter config - "resolveJsonModule": true, - - // Set this to false if you want to disable the very strict rules (not recommended) - "strict": true, - // Or enable some of those features for more fine-grained control - // "strictNullChecks": true, - // "strictPropertyInitialization": true, - // "strictBindCallApply": true, - "noImplicitAny": false, - // "noUnusedLocals": true, - // "noUnusedParameters": true, - - // Consider targetting es2017 or higher if you require the new NodeJS 8+ features - "target": "es2015", - - }, - "include": [ - "**/*.js", - "**/*.d.ts" - ], - "exclude": [ - "node_modules/**", - "admin/**" - ] -} \ No newline at end of file diff --git a/tslint.json b/tslint.json deleted file mode 100644 index 18224b7c..00000000 --- a/tslint.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "enable": true, - "extends": [ - "tslint:recommended" - ], - "rules": { - "indent": [true, "spaces", 4], - "object-literal-sort-keys": false, - "object-literal-shorthand": false, - "array-type": [true, "array"], - "max-line-length": [false], - "interface-name": [false], - "variable-name": [ - true, - "ban-keywords", - "check-format", "allow-leading-underscore", "allow-trailing-underscore" - ], - "member-ordering": [false], - "curly": [true, "ignore-same-line"], - "triple-equals": [true, "allow-undefined-check", "allow-null-check"], - "arrow-parens": false, - "no-bitwise": false, - "max-classes-per-file": false, - "quotemark": [true, "single", "avoid-escape"], - "no-console": true - } -} \ No newline at end of file