From 24deb26c053f2df745fbdbb5a350594da28d9034 Mon Sep 17 00:00:00 2001 From: simatec Date: Mon, 9 Dec 2024 15:26:31 +0100 Subject: [PATCH] (simatec) Fix eslint check --- lib/elevationDown.js | 18 +++-- lib/isSummerTime.js | 12 ++-- lib/setShutter.js | 13 +--- lib/shutterAlarm.js | 119 +++++++++++++++------------------ lib/shutterBrightnessSensor.js | 36 +++++----- 5 files changed, 86 insertions(+), 112 deletions(-) diff --git a/lib/elevationDown.js b/lib/elevationDown.js index 157e7e0a..fc18db3f 100644 --- a/lib/elevationDown.js +++ b/lib/elevationDown.js @@ -13,7 +13,7 @@ const GetXmasLevel = require('./isSummerTime.js').GetXmasLevel; */ 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)}`; } let timerSleep = 0; @@ -29,8 +29,8 @@ async function sleep(ms) { async function elevationDown(adapter, elevation, azimuth, shutterSettings) { if (shutterSettings) { const driveDelayUpAstro = adapter.config.driveDelayUpAstro != 0 ? adapter.config.driveDelayUpAstro * 1000 : 20; - const resLiving = shutterSettings.filter((/** @type {{ typeDown: string; }} */ d) => d.typeDown == 'elevation'); - const result = resLiving.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); + const resLiving = shutterSettings.filter((d) => d.typeDown == 'elevation'); + const result = resLiving.filter((d) => d.enabled === true || d.enabled === 'true'); for (const i in result) { for (const s in shutterSettings) { @@ -81,10 +81,10 @@ async function elevationDown(adapter, elevation, azimuth, shutterSettings) { 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 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) : ''; + let currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? (`${_triggerState.val}`) : ''; if (currentValue === mustValue || @@ -109,8 +109,7 @@ async function elevationDown(adapter, elevation, azimuth, shutterSettings) { 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 && + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == targetLevel2Set) { shutterSettings[s].currentHeight = targetLevel2Set; @@ -134,8 +133,7 @@ async function elevationDown(adapter, elevation, azimuth, shutterSettings) { 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 && + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == targetLevel2Set) { shutterSettings[s].currentHeight = targetLevel2Set; diff --git a/lib/isSummerTime.js b/lib/isSummerTime.js index 079f9c8d..32358291 100644 --- a/lib/isSummerTime.js +++ b/lib/isSummerTime.js @@ -35,8 +35,7 @@ async function IsSummerTime(adapter, StartDate, EndDate) { //end already past, increase end year EndDate.setFullYear(EndDate.getFullYear() + 1); adapter.log.debug(`corrected End ${EndDate.toDateString()}`); - } - else { + } else { //else decrease Start year StartDate.setFullYear(StartDate.getFullYear() - 1); adapter.log.debug(`corrected Start ${StartDate.toDateString()}`); @@ -46,15 +45,13 @@ async function IsSummerTime(adapter, StartDate, EndDate) { if (now >= StartDate && now <= EndDate) { adapter.log.debug('we are in period'); ret = true; - } - else { + } else { adapter.log.debug(`we are not in period, after start ${StartDate.toDateString()} and before end ${EndDate.toDateString()}`); ret = false; } } } - } - catch (e) { + } catch (e) { adapter.log.error(`exception catch in IsSummerTime [${e}]`); } resolve(ret); @@ -73,8 +70,7 @@ async function CheckInSummerNotDown(adapter, shutter) { if (inSummerNotDown) { adapter.log.debug(`${shutter.shutterName} in summer time not down ${shutter.inSummerNotDown}`); - } - else { + } else { adapter.log.debug(`${shutter.shutterName} in summer time down ${shutter.inSummerNotDown}`); } } diff --git a/lib/setShutter.js b/lib/setShutter.js index 87f2adb8..ac52be1d 100644 --- a/lib/setShutter.js +++ b/lib/setShutter.js @@ -2,14 +2,7 @@ const shutterState = require('./shutterState.js'); // shutterState let checkShutterState = true; -/** - * @param {any} adapter - * @param {any} currentShutterSettings - * @param {number} shutterHeight - * @param {string} nameDevice - * @param {string} logInfo - * @param {any} shutterSettings - */ + async function setShutterState(adapter, shutterSettings, currentShutterSettings, shutterHeight, nameDevice, logInfo) { return new Promise(async (resolve) => { adapter.log.info(`${logInfo} Set ID: ${currentShutterSettings.shutterName} value: ${shutterHeight}%`); @@ -37,8 +30,8 @@ async function setShutterState(adapter, shutterSettings, currentShutterSettings, async function setShutterInfo(adapter, shutterSettings, currentShutterSettings, nameDevice) { return new Promise(async (resolve) => { try { - await adapter.setStateAsync('shutters.autoLevel.' + nameDevice, { val: parseFloat(currentShutterSettings.currentHeight), ack: true }); - await adapter.setStateAsync('shutters.autoState.' + nameDevice, { val: currentShutterSettings.currentAction, ack: true }); + await adapter.setStateAsync(`shutters.autoLevel.${ nameDevice}`, { val: parseFloat(currentShutterSettings.currentHeight), ack: true }); + await adapter.setStateAsync(`shutters.autoState.${ nameDevice}`, { val: currentShutterSettings.currentAction, ack: true }); } catch (err) { adapter.log.warn(`autoState and/or Level for Shutter ${nameDevice} could not be set: ${err}`); } diff --git a/lib/shutterAlarm.js b/lib/shutterAlarm.js index 452977ed..3e40c600 100644 --- a/lib/shutterAlarm.js +++ b/lib/shutterAlarm.js @@ -27,24 +27,24 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { if (shutterSettings) { switch (alarmType) { case 'alarmWind1': - resAlarm = shutterSettings.filter((/** @type {{ enableAlarmWind1: boolean; }} */ d) => d.enableAlarmWind1 == true); + resAlarm = shutterSettings.filter((d) => d.enableAlarmWind1 == true); break; case 'alarmWind2': - resAlarm = shutterSettings.filter((/** @type {{ enableAlarmWind2: boolean; }} */ d) => d.enableAlarmWind2 == true); + resAlarm = shutterSettings.filter((d) => d.enableAlarmWind2 == true); break; case 'alarmRain': - resAlarm = shutterSettings.filter((/** @type {{ enableAlarmRain: boolean; }} */ d) => d.enableAlarmRain == true); + resAlarm = shutterSettings.filter((d) => d.enableAlarmRain == true); break; case 'alarmFrost': - resAlarm = shutterSettings.filter((/** @type {{ enableAlarmFrost: boolean; }} */ d) => d.enableAlarmFrost == true); + resAlarm = shutterSettings.filter((d) => d.enableAlarmFrost == true); break; case 'alarmFire': - resAlarm = shutterSettings.filter((/** @type {{ enableAlarmFire: boolean; }} */ d) => d.enableAlarmFire == true); + resAlarm = shutterSettings.filter((d) => d.enableAlarmFire == true); break; } - const result = resAlarm.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); // Filter enabled + const result = resAlarm.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled for (const i in result) { for (const s in shutterSettings) { @@ -84,10 +84,10 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { const _triggerState = shutterSettings[s].triggerID != '' ? await adapter.getForeignStateAsync(shutterSettings[s].triggerID) .catch((e) => adapter.log.warn(e)) : null; - const currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? ('' + _triggerState.val) : ''; + const currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? (`${ _triggerState.val}`) : ''; - const mustValue = shutterSettings[s].triggerState ? ('' + shutterSettings[s].triggerState) : ''; - const mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? ('' + shutterSettings[s].triggerState) : shutterSettings[s].triggerStateTilted ? ('' + shutterSettings[s].triggerStateTilted) : ''; + const mustValue = shutterSettings[s].triggerState ? (`${ shutterSettings[s].triggerState}`) : ''; + const mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? (`${ shutterSettings[s].triggerState}`) : shutterSettings[s].triggerStateTilted ? (`${ shutterSettings[s].triggerStateTilted}`) : ''; switch (alarmType) { // +++++++++++++++++ Alarm Wind 1 +++++++++++++++ @@ -124,9 +124,8 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(alarmWind1Level), nameDevice, 'Alarm #100'); - adapter.log.debug('shutter alarm wind 1 ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterSettings[s].currentHeight + '%'); - } - else if (_shutterState?.val !== null && _shutterState?.val !== undefined && + adapter.log.debug(`shutter alarm wind 1 ${ shutterSettings[s].shutterName } old height: ${ shutterSettings[s].oldHeight }% new height: ${ shutterSettings[s].currentHeight }%`); + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(parseFloat(_shutterState.val) / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == parseFloat(alarmWind1Level) && statusAlarmFire == false) { @@ -154,7 +153,7 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice); - adapter.log.debug('shutter alarm wind 1 ' + shutterSettings[s].shutterName + ' already at: ' + shutterSettings[s].currentHeight + '% - setting current action: ' + shutterSettings[s].currentAction); + adapter.log.debug(`shutter alarm wind 1 ${ shutterSettings[s].shutterName } already at: ${ shutterSettings[s].currentHeight }% - setting current action: ${ shutterSettings[s].currentAction}`); } } else if (!statusAlarmWind1) { if (pendingAlarm == false && statusAlarmFrost == false) { @@ -175,9 +174,8 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].alarmTriggerLevel), nameDevice, 'Alarm Wind 1 ended'); - adapter.log.debug('shutter alarm wind 1 endet and no other alarm is pending ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterSettings[s].currentHeight + '%'); - } - else if (_shutterState?.val !== null && _shutterState?.val !== undefined && + adapter.log.debug(`shutter alarm wind 1 endet and no other alarm is pending ${ shutterSettings[s].shutterName } old height: ${ shutterSettings[s].oldHeight }% new height: ${ shutterSettings[s].currentHeight }%`); + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(parseFloat(_shutterState.val) / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == parseFloat(shutterSettings[s].alarmTriggerLevel)) { shutterSettings[s].currentHeight = parseFloat(shutterSettings[s].alarmTriggerLevel); @@ -187,7 +185,7 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice); - adapter.log.debug('shutter alarm wind 1 endet and no other alarm is pending ' + shutterSettings[s].shutterName + ' already at: ' + shutterSettings[s].currentHeight + '% - setting current action: ' + shutterSettings[s].currentAction); + adapter.log.debug(`shutter alarm wind 1 endet and no other alarm is pending ${ shutterSettings[s].shutterName } already at: ${ shutterSettings[s].currentHeight }% - setting current action: ${ shutterSettings[s].currentAction}`); } } else if (currentValue != '' && currentValue != mustValue && @@ -205,12 +203,12 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].currentHeight), nameDevice, '#Shutter alarm wind1 end'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); - 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 height: ${ shutterSettings[s].triggerHeight }%`); } } } else { - adapter.log.info('Alarm Wind 1 endet for ID: ' + shutterSettings[s].shutterName + ' driving to next highest alarm priority'); + adapter.log.info(`Alarm Wind 1 endet for ID: ${ shutterSettings[s].shutterName } driving to next highest alarm priority`); if (statusAlarmFire == false) { if (statusAlarmFrost == true) { @@ -236,7 +234,7 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].currentHeight), nameDevice, '#Shutter alarm wind1 end'); - adapter.log.debug('shutter alarm ' + shutterSettings[s].currentAction + ' ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterSettings[s].currentHeight + '%'); + adapter.log.debug(`shutter alarm ${ shutterSettings[s].currentAction } ${ shutterSettings[s].shutterName } old height: ${ shutterSettings[s].oldHeight }% new height: ${ shutterSettings[s].currentHeight }%`); } } } @@ -277,9 +275,8 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(alarmWind2Level), nameDevice, '#Shutter alarm wind2'); - adapter.log.debug('shutter alarm wind 2 ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterSettings[s].currentHeight + '%'); - } - else if (_shutterState?.val !== null && _shutterState?.val !== undefined && + adapter.log.debug(`shutter alarm wind 2 ${ shutterSettings[s].shutterName } old height: ${ shutterSettings[s].oldHeight }% new height: ${ shutterSettings[s].currentHeight }%`); + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(parseFloat(_shutterState.val) / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == parseFloat(alarmWind2Level)) { if (statusAlarmRain == false && @@ -305,7 +302,7 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice); - adapter.log.debug('shutter alarm wind 2 ' + shutterSettings[s].shutterName + ' already at: ' + shutterSettings[s].currentHeight + '% - setting current action: ' + shutterSettings[s].currentAction); + adapter.log.debug(`shutter alarm wind 2 ${ shutterSettings[s].shutterName } already at: ${ shutterSettings[s].currentHeight }% - setting current action: ${ shutterSettings[s].currentAction}`); } } else if (statusAlarmWind2 == false) { if (pendingAlarm == false && statusAlarmFrost == false) { @@ -327,9 +324,8 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].alarmTriggerLevel), nameDevice, 'Alarm Wind 2 end'); - adapter.log.debug('shutter alarm wind 2 endet and no other alarm is pending ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterSettings[s].currentHeight + '%'); - } - else if (_shutterState?.val !== null && _shutterState?.val !== undefined && + adapter.log.debug(`shutter alarm wind 2 endet and no other alarm is pending ${ shutterSettings[s].shutterName } old height: ${ shutterSettings[s].oldHeight }% new height: ${ shutterSettings[s].currentHeight }%`); + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(parseFloat(_shutterState.val) / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == parseFloat(shutterSettings[s].alarmTriggerLevel)) { shutterSettings[s].currentHeight = parseFloat(shutterSettings[s].alarmTriggerLevel); @@ -339,7 +335,7 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice); - adapter.log.debug('shutter alarm wind 2 endet and no other alarm is pending ' + shutterSettings[s].shutterName + ' already at: ' + shutterSettings[s].currentHeight + '% - setting current action: ' + shutterSettings[s].currentAction); + adapter.log.debug(`shutter alarm wind 2 endet and no other alarm is pending ${ shutterSettings[s].shutterName } already at: ${ shutterSettings[s].currentHeight }% - setting current action: ${ shutterSettings[s].currentAction}`); } } else if (currentValue != '' && currentValue != mustValue && @@ -357,12 +353,12 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].currentHeight), nameDevice, '#Shutter alarm wind 2 end'); - 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 height: ${ shutterSettings[s].triggerHeight }%`); + adapter.log.debug(`save new trigger action: ${ shutterSettings[s].triggerAction}`); } } } else { - adapter.log.info('Alarm Wind 2 endet for ID: ' + shutterSettings[s].shutterName + ' driving to next highest alarm priority'); + adapter.log.info(`Alarm Wind 2 endet for ID: ${ shutterSettings[s].shutterName } driving to next highest alarm priority`); if (statusAlarmFire == false) { if (statusAlarmFrost == true) { if (shutterSettings[s].alarmTriggerAction == 'down') { @@ -387,7 +383,7 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].currentHeight), nameDevice, '#Shutter alarm wind 2 end'); - adapter.log.debug('shutter alarm ' + shutterSettings[s].currentAction + ' ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterSettings[s].currentHeight + '%'); + adapter.log.debug(`shutter alarm ${ shutterSettings[s].currentAction } ${ shutterSettings[s].shutterName } old height: ${ shutterSettings[s].oldHeight }% new height: ${ shutterSettings[s].currentHeight }%`); } } } @@ -428,9 +424,8 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(alarmRainLevel), nameDevice, '#Shutter alarm Rain'); - adapter.log.debug('shutter alarm rain ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterSettings[s].currentHeight + '%'); - } - else if (_shutterState?.val !== null && _shutterState?.val !== undefined && + adapter.log.debug(`shutter alarm rain ${ shutterSettings[s].shutterName } old height: ${ shutterSettings[s].oldHeight }% new height: ${ shutterSettings[s].currentHeight }%`); + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(parseFloat(_shutterState.val) / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == parseFloat(alarmRainLevel) && statusAlarmFire == false) { @@ -458,7 +453,7 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice); - adapter.log.debug('shutter alarm rain ' + shutterSettings[s].shutterName + ' already at: ' + shutterSettings[s].currentHeight + '% - setting current action: ' + shutterSettings[s].currentAction); + adapter.log.debug(`shutter alarm rain ${ shutterSettings[s].shutterName } already at: ${ shutterSettings[s].currentHeight }% - setting current action: ${ shutterSettings[s].currentAction}`); } } else if (statusAlarmRain == false) { if (pendingAlarm == false && statusAlarmFrost == false) { @@ -479,9 +474,8 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].alarmTriggerLevel), nameDevice, 'Alarm rain end'); - adapter.log.debug('shutter alarm rain endet and no other alarm is pending ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterSettings[s].currentHeight + '%'); - } - else if (_shutterState?.val !== null && _shutterState?.val !== undefined && + adapter.log.debug(`shutter alarm rain endet and no other alarm is pending ${ shutterSettings[s].shutterName } old height: ${ shutterSettings[s].oldHeight }% new height: ${ shutterSettings[s].currentHeight }%`); + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(parseFloat(_shutterState.val) / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == parseFloat(shutterSettings[s].alarmTriggerLevel)) { shutterSettings[s].currentHeight = parseFloat(shutterSettings[s].alarmTriggerLevel); @@ -491,7 +485,7 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice); - adapter.log.debug('shutter alarm rain endet and no other alarm is pending ' + shutterSettings[s].shutterName + ' already at: ' + shutterSettings[s].currentHeight + '% - setting current action: ' + shutterSettings[s].currentAction); + adapter.log.debug(`shutter alarm rain endet and no other alarm is pending ${ shutterSettings[s].shutterName } already at: ${ shutterSettings[s].currentHeight }% - setting current action: ${ shutterSettings[s].currentAction}`); } } else if (currentValue != '' && currentValue != mustValue && @@ -509,12 +503,12 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].currentHeight), nameDevice, '#Shutter alarm rain end'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); - 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 height: ${ shutterSettings[s].triggerHeight }%`); } } } else { - adapter.log.info('Alarm Rain endet for ID: ' + shutterSettings[s].shutterName + ' driving to next highest alarm priority'); + adapter.log.info(`Alarm Rain endet for ID: ${ shutterSettings[s].shutterName } driving to next highest alarm priority`); if (statusAlarmFire == false) { if (statusAlarmFrost == true) { @@ -540,7 +534,7 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].currentHeight), nameDevice, '#Shutter alarm rain end'); - adapter.log.debug('shutter alarm ' + shutterSettings[s].currentAction + ' ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterSettings[s].currentHeight + '%'); + adapter.log.debug(`shutter alarm ${ shutterSettings[s].currentAction } ${ shutterSettings[s].shutterName } old height: ${ shutterSettings[s].oldHeight }% new height: ${ shutterSettings[s].currentHeight }%`); } } } @@ -603,12 +597,11 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(alarmFrostLevel), nameDevice, '#Shutter alarm frost'); - adapter.log.debug('shutter alarm frost ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterSettings[s].currentHeight + '%'); + adapter.log.debug(`shutter alarm frost ${ shutterSettings[s].shutterName } old height: ${ shutterSettings[s].oldHeight }% new height: ${ shutterSettings[s].currentHeight }%`); } } - } - else if (_shutterState?.val !== null && _shutterState?.val !== undefined && + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(parseFloat(_shutterState.val) / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == parseFloat(alarmFrostLevel) && statusAlarmFire == false) { @@ -645,7 +638,7 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice); - adapter.log.debug('shutter alarm frost' + shutterSettings[s].shutterName + ' already at: ' + shutterSettings[s].currentHeight + '% - setting current action: ' + shutterSettings[s].currentAction); + adapter.log.debug(`shutter alarm frost${ shutterSettings[s].shutterName } already at: ${ shutterSettings[s].currentHeight }% - setting current action: ${ shutterSettings[s].currentAction}`); } } else if (statusAlarmFrost == false) { if (pendingAlarm == false) { @@ -666,9 +659,8 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].alarmTriggerLevel), nameDevice, 'Alarm frost ended'); - adapter.log.debug('shutter alarm frost endet and no other alarm is pending ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterSettings[s].currentHeight + '%'); - } - else if (_shutterState?.val !== null && _shutterState?.val !== undefined && + adapter.log.debug(`shutter alarm frost endet and no other alarm is pending ${ shutterSettings[s].shutterName } old height: ${ shutterSettings[s].oldHeight }% new height: ${ shutterSettings[s].currentHeight }%`); + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(parseFloat(_shutterState.val) / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == parseFloat(shutterSettings[s].alarmTriggerLevel)) { shutterSettings[s].currentHeight = parseFloat(shutterSettings[s].alarmTriggerLevel); @@ -678,7 +670,7 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice); - adapter.log.debug('shutter alarm frost endet and no other alarm is pending ' + shutterSettings[s].shutterName + ' already at: ' + shutterSettings[s].currentHeight + '% - setting current action: ' + shutterSettings[s].currentAction); + adapter.log.debug(`shutter alarm frost endet and no other alarm is pending ${ shutterSettings[s].shutterName } already at: ${ shutterSettings[s].currentHeight }% - setting current action: ${ shutterSettings[s].currentAction}`); } } else if (currentValue != '' && currentValue != mustValue && @@ -696,12 +688,12 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].currentHeight), nameDevice, '#Shutter alarm frost end'); - adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction); - 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 height: ${ shutterSettings[s].triggerHeight }%`); } } } else { - adapter.log.info('Alarm frost endet for ID: ' + shutterSettings[s].shutterName + ' driving to next highest alarm priority'); + adapter.log.info(`Alarm frost endet for ID: ${ shutterSettings[s].shutterName } driving to next highest alarm priority`); if (statusAlarmFire == false) { if (statusAlarmWind1 == true) { shutterSettings[s].currentHeight = alarmWind1Level; @@ -721,7 +713,7 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(shutterSettings[s].currentHeight), nameDevice, '#Shutter alarm frost end'); - adapter.log.debug('shutter alarm ' + shutterSettings[s].currentAction + ' ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterSettings[s].currentHeight + '%'); + adapter.log.debug(`shutter alarm ${ shutterSettings[s].currentAction } ${ shutterSettings[s].shutterName } old height: ${ shutterSettings[s].oldHeight }% new height: ${ shutterSettings[s].currentHeight }%`); } } } @@ -752,9 +744,8 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterState(adapter, shutterSettings, shutterSettings[s], parseFloat(alarmFireLevel), nameDevice, '#Shutter alarm fire'); - adapter.log.debug('shutter alarm fire ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + shutterSettings[s].currentHeight + '%'); - } - else if (_shutterState?.val !== null && _shutterState?.val !== undefined && + adapter.log.debug(`shutter alarm fire ${ shutterSettings[s].shutterName } old height: ${ shutterSettings[s].oldHeight }% new height: ${ shutterSettings[s].currentHeight }%`); + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(parseFloat(_shutterState.val) / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == parseFloat(alarmFireLevel)) { if (statusAlarmWind1 == false && @@ -772,10 +763,10 @@ async function shutterAlarm(adapter, alarmType, shutterSettings) { await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice); - adapter.log.debug('shutter alarm fire ' + shutterSettings[s].shutterName + ' already at: ' + shutterSettings[s].currentHeight + '% - setting current action: ' + shutterSettings[s].currentAction); + adapter.log.debug(`shutter alarm fire ${ shutterSettings[s].shutterName } already at: ${ shutterSettings[s].currentHeight }% - setting current action: ${ shutterSettings[s].currentAction}`); } } else if (statusAlarmFire == false) { - adapter.log.info('Alarm fire endet for ID: ' + shutterSettings[s].shutterName + ' fire alarm is not driving back! - please init shutters with button "open all"'); + adapter.log.info(`Alarm fire endet for ID: ${ shutterSettings[s].shutterName } fire alarm is not driving back! - please init shutters with button "open all"`); } await sleep(driveDelayUpAstro); break; @@ -840,7 +831,7 @@ async function checkPendingAlarm(adapter, Shutter) { Shutter.enableAlarmFire == true || Shutter.enableAlarmFrost == true) { - adapter.log.debug('status alarm pending for ' + Shutter.name + ': ' + resAlarmPending); + adapter.log.debug(`status alarm pending for ${ Shutter.name }: ${ resAlarmPending}`); } resolve(resAlarmPending); }); @@ -869,7 +860,7 @@ async function checkFrostAlarm(adapter, Shutter) { Shutter.enableAlarmFire == true || Shutter.enableAlarmFrost == true) { - adapter.log.debug('status frost alarm for ' + Shutter.name + ': ' + resAlarmFrost); + adapter.log.debug(`status frost alarm for ${ Shutter.name }: ${ resAlarmFrost}`); } resolve(resAlarmFrost); }); diff --git a/lib/shutterBrightnessSensor.js b/lib/shutterBrightnessSensor.js index 6cf8e3b1..cfee578a 100644 --- a/lib/shutterBrightnessSensor.js +++ b/lib/shutterBrightnessSensor.js @@ -21,7 +21,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)}`; } function brightnessState(adapter, brightnessValue, brightnessDown) { @@ -57,8 +57,8 @@ async function shutterBrightnessSensor(adapter, brightnessValue, shutterSettings brightnessDown == false) { if (shutterSettings) { - const resLiving = shutterSettings.filter((/** @type {{ typeDown: string; }} */ d) => d.typeDown == 'lightsensor'); // 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.typeDown == 'lightsensor'); // Filter Area Living + const result = resLiving.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled for (const i in result) { for (const s in shutterSettings) { @@ -108,9 +108,9 @@ async function shutterBrightnessSensor(adapter, brightnessValue, shutterSettings 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 || @@ -135,8 +135,7 @@ async function shutterBrightnessSensor(adapter, brightnessValue, shutterSettings 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 && + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == targetLevel2Set && (shutterSettings[s].currentHeight != targetLevel2Set || shutterSettings[s].currentAction != downAction)) { @@ -164,8 +163,7 @@ async function shutterBrightnessSensor(adapter, brightnessValue, shutterSettings 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 && + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == targetLevel2Set && (shutterSettings[s].currentHeight != targetLevel2Set || shutterSettings[s].currentAction != downAction)) { @@ -215,8 +213,8 @@ async function shutterBrightnessSensor(adapter, brightnessValue, shutterSettings brightnessValue > shutterUpBrightness) { if (shutterSettings) { - const resLiving = shutterSettings.filter((/** @type {{ typeUp: string; }} */ d) => d.typeUp == 'lightsensor'); // 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 == 'lightsensor'); // Filter Area Living + const result = resLiving.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled for (const i in result) { for (const s in shutterSettings) { @@ -245,9 +243,9 @@ async function shutterBrightnessSensor(adapter, brightnessValue, 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); - 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 (pendingAlarm == false) { if (currentValue === mustValue || @@ -271,9 +269,8 @@ async function shutterBrightnessSensor(adapter, brightnessValue, shutterSettings await setShutterState(adapter, shutterSettings, shutterSettings[s], shutterHeight, nameDevice, 'Lightsensor #5'); 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; @@ -299,8 +296,7 @@ async function shutterBrightnessSensor(adapter, brightnessValue, shutterSettings 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 && + } else if (_shutterState?.val !== null && _shutterState?.val !== undefined && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterHeight) { shutterSettings[s].currentHeight = shutterHeight;