From 4f0cd365830bf6176cc77cf2af66856a41c97827 Mon Sep 17 00:00:00 2001 From: simatec Date: Mon, 9 Dec 2024 15:15:49 +0100 Subject: [PATCH] (simatec) Fix eslint error --- lib/shutterState.js | 2 +- lib/shutterSunriseSunset.js | 66 +++++++++++++++++-------------------- lib/shutterUpChildren.js | 56 +++++++++++++++---------------- lib/shutterUpLiving.js | 38 +++++++++------------ lib/shutterUpSleep.js | 22 ++++++------- 5 files changed, 85 insertions(+), 99 deletions(-) diff --git a/lib/shutterState.js b/lib/shutterState.js index de98e19..4498ab0 100644 --- a/lib/shutterState.js +++ b/lib/shutterState.js @@ -20,7 +20,7 @@ async function shutterState(shutterID, adapter, shutterSettings, checkTimeDelay) } if (shutterSettings) { - const result = shutterSettings.filter((/** @type {{ name: any; }} */ d) => d.name == shutterID); + const result = shutterSettings.filter((d) => d.name == shutterID); await sleep(checkTime); for (const i in result) { diff --git a/lib/shutterSunriseSunset.js b/lib/shutterSunriseSunset.js index 85b7855..f29c66f 100644 --- a/lib/shutterSunriseSunset.js +++ b/lib/shutterSunriseSunset.js @@ -23,7 +23,7 @@ async function sleep(ms) { */ function getDate(d) { d = d || new Date(); - return ('0' + d.getHours()).slice(-2) + ':' + ('0' + d.getMinutes()).slice(-2); + return `${(`0${ d.getHours()}`).slice(-2) }:${ (`0${ d.getMinutes()}`).slice(-2)}`; } // @ts-ignore @@ -35,10 +35,10 @@ async function shutterSunriseSunset(adapter, sunriseStr, sunsetStr, shutterSetti schedule.cancelJob('shutterUpSunrise'); - const upSunrise = schedule.scheduleJob('shutterUpSunrise', upTime[1] + ' ' + upTime[0] + ' * * *', async function () { + const upSunrise = schedule.scheduleJob('shutterUpSunrise', `${upTime[1] } ${ upTime[0] } * * *`, async function () { if (shutterSettings) { - const resLiving = shutterSettings.filter((/** @type {{ typeUp: string; }} */ d) => d.typeUp == 'sunrise'); // Filter Area Sunrise - const result = resLiving.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); // Filter enabled + const resLiving = shutterSettings.filter((d) => d.typeUp == 'sunrise'); // Filter Area Sunrise + const result = resLiving.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled for (const i in result) { for (const s in shutterSettings) { @@ -65,9 +65,9 @@ async function shutterSunriseSunset(adapter, sunriseStr, sunsetStr, shutterSetti if (pendingAlarm == false) { 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 || @@ -89,9 +89,8 @@ async function shutterSunriseSunset(adapter, sunriseStr, sunsetStr, shutterSetti await setShutterState(adapter, shutterSettings, shutterSettings[s], shutterHeight, nameDevice, 'Sunrise #9'); 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); - } - else if (_shutterState?.val !== null && _shutterState?.val !== undefined && + adapter.log.debug(`save current height: ${ shutterSettings[s].currentHeight }%` + ` from ${ shutterSettings[s].shutterName}`); + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterHeight) { shutterSettings[s].currentHeight = shutterHeight; @@ -100,7 +99,7 @@ async function shutterSunriseSunset(adapter, sunriseStr, sunsetStr, shutterSetti await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice); - adapter.log.debug('Sunrise up ' + shutterSettings[s].shutterName + ' already up at: ' + shutterSettings[s].heightUp + '% - setting current action: ' + shutterSettings[s].currentAction); + adapter.log.debug(`Sunrise up ${ shutterSettings[s].shutterName } already up at: ${ shutterSettings[s].heightUp }% - setting current action: ${ shutterSettings[s].currentAction}`); } } else if (shutterSettings[s].triggerID == '') { const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); @@ -114,16 +113,15 @@ async function shutterSunriseSunset(adapter, sunriseStr, sunsetStr, shutterSetti await setShutterState(adapter, shutterSettings, shutterSettings[s], shutterHeight, nameDevice, 'Sunrise #10'); 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); - } - else if (_shutterState?.val !== null && _shutterState?.val !== undefined && + adapter.log.debug(`save current height: ${ shutterSettings[s].currentHeight }%` + ` from ${ shutterSettings[s].shutterName}`); + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterHeight) { shutterSettings[s].currentHeight = shutterHeight; await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice); - adapter.log.debug('Sunrise up ' + shutterSettings[s].shutterName + ' already up at: ' + shutterSettings[s].heightUp + '% - setting current action: ' + shutterSettings[s].currentAction); + adapter.log.debug(`Sunrise up ${ shutterSettings[s].shutterName } already up at: ${ shutterSettings[s].heightUp }% - setting current action: ${ shutterSettings[s].currentAction}`); } } else if (currentValue != mustValue && currentValue != mustValueTilted && @@ -136,9 +134,9 @@ async function shutterSunriseSunset(adapter, sunriseStr, sunsetStr, shutterSetti shutterSettings[s].triggerHeight = shutterHeight; shutterSettings[s].triggerAction = shutterSettings[s].currentAction; - adapter.log.info('#11 Will open ID: ' + shutterSettings[s].shutterName + ' value: ' + shutterHeight + '%' + ' after the window has been closed '); - adapter.log.debug('save new trigger height: ' + shutterHeight + '%'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); + adapter.log.info(`#11 Will open ID: ${ shutterSettings[s].shutterName } value: ${ shutterHeight }%` + ` after the window has been closed `); + adapter.log.debug(`save new trigger height: ${ shutterHeight }%`); + adapter.log.debug(`save new trigger action: ${ shutterSettings[s].triggerAction}`); } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterHeight) { @@ -151,7 +149,7 @@ async function shutterSunriseSunset(adapter, sunriseStr, sunsetStr, shutterSetti } } } else { - adapter.log.info('Sunrise/Sunset up not moving now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + shutterHeight + '%'); + adapter.log.info(`Sunrise/Sunset up not moving now due to active alarm: ${ shutterSettings[s].shutterName } value: ${ shutterHeight }%`); } await sleep(driveDelayUpAstro); } @@ -169,10 +167,10 @@ async function shutterSunriseSunset(adapter, sunriseStr, sunsetStr, shutterSetti schedule.cancelJob('shutterDownSunset'); - const downSunset = schedule.scheduleJob('shutterDownSunset', upTime[1] + ' ' + upTime[0] + ' * * *', async function () { + const downSunset = schedule.scheduleJob('shutterDownSunset', `${upTime[1] } ${ upTime[0] } * * *`, async function () { if (shutterSettings) { - const resLiving = shutterSettings.filter((/** @type {{ typeDown: string; }} */ d) => d.typeDown == 'sunset'); // Filter Area Sunset - const result = resLiving.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); // Filter enabled + const resLiving = shutterSettings.filter((d) => d.typeDown == 'sunset'); // Filter Area Sunset + const result = resLiving.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled for (const i in result) { for (const s in shutterSettings) { @@ -216,9 +214,9 @@ async function shutterSunriseSunset(adapter, sunriseStr, sunsetStr, shutterSetti if (_autoDownState?.val === true) { if (pendingAlarm == false) { 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 || @@ -241,8 +239,7 @@ async function shutterSunriseSunset(adapter, sunriseStr, sunsetStr, shutterSetti await setShutterState(adapter, shutterSettings, shutterSettings[s], targetLevel2Set, nameDevice, 'Sunset #12'); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - } - 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; @@ -250,7 +247,7 @@ async function shutterSunriseSunset(adapter, sunriseStr, sunsetStr, shutterSetti await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice); - adapter.log.debug('Sunset down ' + shutterSettings[s].shutterName + ' already down at: ' + targetLevel2Set + '% - setting current action: ' + shutterSettings[s].currentAction); + adapter.log.debug(`Sunset down ${ shutterSettings[s].shutterName } already down at: ${ targetLevel2Set }% - setting current action: ${ shutterSettings[s].currentAction}`); } } else if (shutterSettings[s].triggerID == '') { const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); @@ -265,8 +262,7 @@ async function shutterSunriseSunset(adapter, sunriseStr, sunsetStr, shutterSetti await setShutterState(adapter, shutterSettings, shutterSettings[s], targetLevel2Set, nameDevice, 'Sunset #12'); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - } - 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; @@ -274,7 +270,7 @@ async function shutterSunriseSunset(adapter, sunriseStr, sunsetStr, shutterSetti await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice); - adapter.log.debug('Sunset down ' + shutterSettings[s].shutterName + ' already down at: ' + targetLevel2Set + '% - setting current action: ' + shutterSettings[s].currentAction); + adapter.log.debug(`Sunset down ${ shutterSettings[s].shutterName } already down at: ${ targetLevel2Set }% - setting current action: ${ shutterSettings[s].currentAction}`); } } else if (currentValue != mustValue && currentValue != mustValueTilted && @@ -288,14 +284,14 @@ async function shutterSunriseSunset(adapter, sunriseStr, sunsetStr, shutterSetti shutterSettings[s].triggerHeight = targetLevel2Set; shutterSettings[s].triggerAction = downAction; - adapter.log.info('#14 Will close ID: ' + shutterSettings[s].shutterName + ' value: ' + targetLevel2Set + '%' + ' after the window has been closed '); - adapter.log.debug('save new trigger height: ' + targetLevel2Set + '%'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); + adapter.log.info(`#14 Will close ID: ${ shutterSettings[s].shutterName } value: ${ targetLevel2Set }%` + ` after the window has been closed `); + adapter.log.debug(`save new trigger height: ${ targetLevel2Set }%`); + adapter.log.debug(`save new trigger action: ${ shutterSettings[s].triggerAction}`); } } await sleep(driveDelayUpAstro); } else { - adapter.log.info('Sunrise/Sunset down not moving now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + targetLevel2Set + '%'); + adapter.log.info(`Sunrise/Sunset down not moving now due to active alarm: ${ shutterSettings[s].shutterName } value: ${ targetLevel2Set }%`); } } } diff --git a/lib/shutterUpChildren.js b/lib/shutterUpChildren.js index b38d442..f6edeb6 100644 --- a/lib/shutterUpChildren.js +++ b/lib/shutterUpChildren.js @@ -20,8 +20,8 @@ async function driveshutterUpChildren(adapter, upTimeChildren, autoChildrenStr, if (shutterSettings) { adapter.log.debug(`Children-type: ${childrenType}`); - const resChildren = shutterSettings.filter((/** @type {{ typeUp: string; }} */ d) => d.typeUp == childrenType); // Filter Area Children - const result = resChildren.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); // Filter enabled + const resChildren = shutterSettings.filter((d) => d.typeUp == childrenType); // Filter Area Children + const result = resChildren.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled let number = 0; @@ -58,9 +58,9 @@ async function driveshutterUpChildren(adapter, upTimeChildren, autoChildrenStr, if (pendingAlarm == false) { 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 || @@ -71,8 +71,8 @@ async function driveshutterUpChildren(adapter, upTimeChildren, autoChildrenStr, const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); - if (_shutterState?.val !== null && _shutterState?.val !== undefined && - Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != shutterHeight && + if (_shutterState?.val !== null && _shutterState?.val !== undefined && + Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != shutterHeight && Date.now() >= (_shutterState.lc + noGoDelay)) { shutterSettings[s].currentHeight = shutterHeight; @@ -83,10 +83,9 @@ async function driveshutterUpChildren(adapter, upTimeChildren, autoChildrenStr, await setShutterState(adapter, shutterSettings, shutterSettings[s], shutterHeight, nameDevice, 'Children Up #21'); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - adapter.log.debug('shutterUpChildren #1 ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterHeight + '%'); - } - else if (_shutterState?.val !== null && _shutterState?.val !== undefined && - Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterHeight && + adapter.log.debug(`shutterUpChildren #1 ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${shutterHeight}%`); + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && + Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterHeight && Date.now() >= (_shutterState.lc + noGoDelay)) { shutterSettings[s].currentHeight = shutterHeight; @@ -95,13 +94,13 @@ async function driveshutterUpChildren(adapter, upTimeChildren, autoChildrenStr, await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice); - adapter.log.debug('shutterUpChildren #1 ' + shutterSettings[s].shutterName + ' already up at: ' + shutterHeight + '% - setting current action: ' + shutterSettings[s].currentAction); + adapter.log.debug(`shutterUpChildren #1 ${shutterSettings[s].shutterName} already up at: ${shutterHeight}% - setting current action: ${shutterSettings[s].currentAction}`); } } else if (shutterSettings[s].triggerID == '') { const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); - if (_shutterState?.val !== null && _shutterState?.val !== undefined && - Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != shutterHeight && + if (_shutterState?.val !== null && _shutterState?.val !== undefined && + Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != shutterHeight && Date.now() >= (_shutterState.lc + noGoDelay)) { shutterSettings[s].currentHeight = shutterHeight; @@ -110,20 +109,19 @@ async function driveshutterUpChildren(adapter, upTimeChildren, autoChildrenStr, await setShutterState(adapter, shutterSettings, shutterSettings[s], shutterHeight, nameDevice, 'Children Up #22'); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - adapter.log.debug('shutterUpChildren #2 ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterHeight + '%'); - } - else if (_shutterState?.val !== null && _shutterState?.val !== undefined && - Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterHeight && + adapter.log.debug(`shutterUpChildren #2 ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${shutterHeight}%`); + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && + Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterHeight && Date.now() >= (_shutterState.lc + noGoDelay)) { shutterSettings[s].currentHeight = shutterHeight; await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice); - adapter.log.debug('shutterUpChildren #2 ' + shutterSettings[s].shutterName + ' already up at: ' + shutterHeight + '% - setting current action: ' + shutterSettings[s].currentAction); + adapter.log.debug(`shutterUpChildren #2 ${shutterSettings[s].shutterName} already up at: ${shutterHeight}% - setting current action: ${shutterSettings[s].currentAction}`); } - } else if (currentValue != mustValue && - currentValue != mustValueTilted && + } else if (currentValue != mustValue && + currentValue != mustValueTilted && shutterSettings[s].driveAfterClose == true) { const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); @@ -132,9 +130,9 @@ async function driveshutterUpChildren(adapter, upTimeChildren, autoChildrenStr, shutterSettings[s].triggerHeight = shutterHeight; shutterSettings[s].triggerAction = shutterSettings[s].currentAction; - adapter.log.info('#23 Will open ID: ' + shutterSettings[s].shutterName + ' value: ' + shutterHeight + '%' + ' after the window has been closed '); - adapter.log.debug('save new trigger height: ' + shutterHeight + '%'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); + adapter.log.info(`#23 Will open ID: ${shutterSettings[s].shutterName} value: ${shutterHeight}%` + ` after the window has been closed `); + adapter.log.debug(`save new trigger height: ${shutterHeight}%`); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterHeight) { @@ -147,7 +145,7 @@ async function driveshutterUpChildren(adapter, upTimeChildren, autoChildrenStr, } } } else { - adapter.log.info('Children up not moving now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + shutterHeight + '%'); + adapter.log.info(`Children up not moving now due to active alarm: ${shutterSettings[s].shutterName} value: ${shutterHeight}%`); } await sleep(driveDelayUpChildren); } @@ -157,10 +155,10 @@ async function driveshutterUpChildren(adapter, upTimeChildren, autoChildrenStr, adapter.log.debug(`Adapter Auto-Children is: ${autoChildrenStr}`); // start children-auto after drive children shutter - if ((autoChildrenStr === true || - autoChildrenStr === 'true') && + if ((autoChildrenStr === true || + autoChildrenStr === 'true') && childrenType === 'children') { - + await sleep(timeoutChildrenAuto); childrenType = 'children-auto'; driveshutterUpChildren(adapter, upTimeChildren, autoChildrenStr, shutterSettings, childrenType, driveDelayUpChildren, timeoutChildrenAuto, noGoDelay); @@ -193,7 +191,7 @@ async function shutterUpChildren(adapter, upTimeChildren, delayUp, autoChildrenS schedule.cancelJob('shutterUpChildren'); try { - const upChildren = schedule.scheduleJob('shutterUpChildren', upTime[1] + ' ' + upTime[0] + ' * * *', async function () { + const upChildren = schedule.scheduleJob('shutterUpChildren', `${upTime[1]} ${upTime[0]} * * *`, async function () { delayUp = delayUp * driveDelayUpLiving; await sleep(delayUp); driveshutterUpChildren(adapter, upTimeChildren, autoChildrenStr, shutterSettings, childrenType, driveDelayUpChildren, timeoutChildrenAuto, noGoDelay); diff --git a/lib/shutterUpLiving.js b/lib/shutterUpLiving.js index 2e896a6..5d89223 100644 --- a/lib/shutterUpLiving.js +++ b/lib/shutterUpLiving.js @@ -20,8 +20,8 @@ async function driveshutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutte if (shutterSettings) { adapter.log.debug(`Living-type: ${livingType}`); - const resLiving = shutterSettings.filter((/** @type {{ typeUp: string; }} */ d) => d.typeUp == livingType); // Filter Area Living - const result = resLiving.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); // Filter enabled + const resLiving = shutterSettings.filter((d) => d.typeUp == livingType); // Filter Area Living + const result = resLiving.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled let number = 0; @@ -57,9 +57,9 @@ async function driveshutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutte if (pendingAlarm == false) { 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 || @@ -82,9 +82,8 @@ async function driveshutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutte await setShutterState(adapter, shutterSettings, shutterSettings[s], shutterHeight, nameDevice, 'Living up #13'); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - adapter.log.debug('shutterUpLiving #1 ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterHeight + '%'); - } - else if (_shutterState?.val !== null && _shutterState?.val !== undefined && + adapter.log.debug(`shutterUpLiving #1 ${ shutterSettings[s].shutterName } old height: ${ shutterSettings[s].oldHeight }% new height: ${ shutterHeight }%`); + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterHeight && Date.now() >= (_shutterState.lc + noGoDelay)) { @@ -94,7 +93,7 @@ async function driveshutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutte await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice); - adapter.log.debug('shutterUpLiving #1 ' + shutterSettings[s].shutterName + ' already up at: ' + shutterHeight + '% - setting current action: ' + shutterSettings[s].currentAction); + adapter.log.debug(`shutterUpLiving #1 ${ shutterSettings[s].shutterName } already up at: ${ shutterHeight }% - setting current action: ${ shutterSettings[s].currentAction}`); } } else if (shutterSettings[s].triggerID == '') { const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); @@ -109,9 +108,8 @@ async function driveshutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutte await setShutterState(adapter, shutterSettings, shutterSettings[s], shutterHeight, nameDevice, 'Living up #13'); adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); - adapter.log.debug('shutterUpLiving #2 ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterHeight + '%'); - } - else if (_shutterState?.val !== null && _shutterState?.val !== undefined && + adapter.log.debug(`shutterUpLiving #2 ${ shutterSettings[s].shutterName } old height: ${ shutterSettings[s].oldHeight }% new height: ${ shutterHeight }%`); + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterHeight && Date.now() >= (_shutterState.lc + noGoDelay)) { @@ -119,7 +117,7 @@ async function driveshutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutte await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice); - adapter.log.debug('shutterUpLiving #2 ' + shutterSettings[s].shutterName + ' already up at: ' + shutterHeight + '% - setting current action: ' + shutterSettings[s].currentAction); + adapter.log.debug(`shutterUpLiving #2 ${ shutterSettings[s].shutterName } already up at: ${ shutterHeight }% - setting current action: ${ shutterSettings[s].currentAction}`); } } else if (currentValue != mustValue && currentValue != mustValueTilted && @@ -133,9 +131,9 @@ async function driveshutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutte shutterSettings[s].triggerHeight = shutterHeight; shutterSettings[s].triggerAction = shutterSettings[s].currentAction; - adapter.log.info('#15 Will open ID: ' + shutterSettings[s].shutterName + ' value: ' + shutterHeight + '%' + ' after the window has been closed '); - adapter.log.debug('save new trigger height: ' + shutterHeight + '%'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); + adapter.log.info(`#15 Will open ID: ${ shutterSettings[s].shutterName } value: ${ shutterHeight }%` + ` after the window has been closed `); + adapter.log.debug(`save new trigger height: ${ shutterHeight }%`); + adapter.log.debug(`save new trigger action: ${ shutterSettings[s].triggerAction}`); } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterHeight) { @@ -148,7 +146,7 @@ async function driveshutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutte } } } else { - adapter.log.info('Living up not moving now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + shutterHeight + '%'); + adapter.log.info(`Living up not moving now due to active alarm: ${ shutterSettings[s].shutterName } value: ${ shutterHeight }%`); } await sleep(driveDelayUpLiving); } @@ -172,10 +170,6 @@ async function driveshutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutte } } -// @ts-ignore -/** - * @param {boolean} autoLivingStr - */ async function shutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutterSettings) { const driveDelayUpLiving = adapter.config.driveDelayUpLiving != 0 ? adapter.config.driveDelayUpLiving * 1000 : 20; const noGoDelay = adapter.config.noGoTime * 1000 * 60; @@ -188,7 +182,7 @@ async function shutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutterSett schedule.cancelJob('shutterUpLiving'); - const upLiving = schedule.scheduleJob('shutterUpLiving', upTime[1] + ' ' + upTime[0] + ' * * *', async function () { + const upLiving = schedule.scheduleJob('shutterUpLiving', `${upTime[1] } ${ upTime[0] } * * *`, async function () { driveshutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutterSettings, livingType, driveDelayUpLiving, timeoutLivingAuto, noGoDelay); }); } diff --git a/lib/shutterUpSleep.js b/lib/shutterUpSleep.js index 3f7dd95..f1c4767 100644 --- a/lib/shutterUpSleep.js +++ b/lib/shutterUpSleep.js @@ -20,8 +20,8 @@ async function driveshutterUpSleep(adapter, upTimeSleep, autoSleepStr, shutterSe if (shutterSettings) { adapter.log.debug(`Sleep-type: ${sleepType}`); - const resSleep = shutterSettings.filter((/** @type {{ typeUp: any; }} */ d) => d.typeUp == sleepType); // Filter Area sleep - const result = resSleep.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); // Filter enabled + const resSleep = shutterSettings.filter((d) => d.typeUp == sleepType); // Filter Area sleep + const result = resSleep.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled ; let number = 0; @@ -42,7 +42,7 @@ async function driveshutterUpSleep(adapter, upTimeSleep, autoSleepStr, shutterSe if (_autoUpState?.val === true) { let shutterHeight = 0; - if (shutterSettings[s].currentAction == 'sunProtect' || + if (shutterSettings[s].currentAction == 'sunProtect' || shutterSettings[s].currentAction == 'OpenInSunProtect') { shutterHeight = parseFloat(shutterSettings[s].heightDownSun); @@ -58,9 +58,9 @@ async function driveshutterUpSleep(adapter, upTimeSleep, autoSleepStr, shutterSe if (pendingAlarm == false) { 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 || @@ -84,8 +84,7 @@ async function driveshutterUpSleep(adapter, upTimeSleep, autoSleepStr, shutterSe adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); adapter.log.debug(`shutterUpSleep #1 ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${shutterHeight}%`); - } - 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 == shutterHeight && Date.now() >= (_shutterState.lc + noGoDelay)) { @@ -111,8 +110,7 @@ async function driveshutterUpSleep(adapter, upTimeSleep, autoSleepStr, shutterSe adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`); adapter.log.debug(`shutterUpSleep #2 ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${shutterHeight}%`); - } - 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 == shutterHeight && Date.now() >= (_shutterState.lc + noGoDelay)) { @@ -159,7 +157,7 @@ async function driveshutterUpSleep(adapter, upTimeSleep, autoSleepStr, shutterSe adapter.log.debug(`Adapter Auto-Sleep is: ${autoSleepStr}`); // start sleep-auto after drive sleep shutter - if ((autoSleepStr === true || + if ((autoSleepStr === true || autoSleepStr === 'true') && sleepType === 'sleep') { @@ -187,7 +185,7 @@ async function shutterUpSleep(adapter, upTimeSleep, delayUp, autoSleepStr, shutt schedule.cancelJob('shutterUpSleep'); - const upSleep = schedule.scheduleJob('shutterUpSleep', upTime[1] + ' ' + upTime[0] + ' * * *', async function () { + const upSleep = schedule.scheduleJob('shutterUpSleep', `${upTime[1]} ${upTime[0]} * * *`, async function () { delayUp = delayUp * driveDelayUpLiving; await sleep(delayUp);