From ade3da17229a18d8494f82731330641996d665dd Mon Sep 17 00:00:00 2001 From: simatec Date: Mon, 5 Aug 2024 21:10:06 +0200 Subject: [PATCH] (simatec) Fix Shutter up when open the Window --- README.md | 2 +- lib/shutterBrightnessSensor.js | 13 ++++++++++++- lib/shutterGoldenHour.js | 12 +++++++++++- lib/shutterSunriseSunset.js | 13 ++++++++++++- lib/shutterUpChildren.js | 9 +++++++++ lib/shutterUpLiving.js | 22 ++++++++++++++++++---- 6 files changed, 63 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 44ee29c..8a92929 100644 --- a/README.md +++ b/README.md @@ -53,8 +53,8 @@ When the adapter crashes or an other Code error happens, this error message that * (simatec) Trigger changed * (simatec) Code revision and improvements * (simatec) many small fixes -* (simatec) Fix sleep up when open the Window * (simatec) Fix Sunprotect end by Shutter up +* (simatec) Fix Shutter up when open the Window ### 1.7.3 (2024-06-20) * (simatec) Fix Sunprotect End-Delay diff --git a/lib/shutterBrightnessSensor.js b/lib/shutterBrightnessSensor.js index 6e6b8c0..f3067fd 100644 --- a/lib/shutterBrightnessSensor.js +++ b/lib/shutterBrightnessSensor.js @@ -262,13 +262,24 @@ async function shutterBrightnessSensor(adapter, brightnessValue, shutterSettings } else if (currentValue != mustValue && currentValue != mustValueTilted && shutterSettings[s].driveAfterClose == true) { const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); - if (typeof _shutterState != undefined && _shutterState != null && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != shutterHeight) { + if (_shutterState?.val && + Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != shutterHeight) { + shutterSettings[s].triggerHeight = shutterHeight; shutterSettings[s].triggerAction = shutterSettings[s].currentAction; adapter.log.info(`Lightsensor #7 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 && + Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterHeight) { + + shutterSettings[s].triggerHeight = shutterHeight; + shutterSettings[s].triggerAction = shutterSettings[s].currentAction; + + adapter.log.info(`Lightsensor #8 Will open ID: ${shutterSettings[s].shutterName} value: ${shutterHeight}% after is the value for Lightsensor up`); + adapter.log.debug(`save new trigger height: ${shutterHeight}%`); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); } } } diff --git a/lib/shutterGoldenHour.js b/lib/shutterGoldenHour.js index 5310a5d..87b6b6e 100644 --- a/lib/shutterGoldenHour.js +++ b/lib/shutterGoldenHour.js @@ -117,13 +117,23 @@ async function shutterGoldenHour(adapter, goldenHourEnd, goldenHour, shutterSett } else if (currentValue != mustValue && currentValue != mustValueTilted && shutterSettings[s].driveAfterClose == true) { const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); - if (typeof _shutterState != undefined && _shutterState != null && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != shutterHeight) { + if (_shutterState?.val && + Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != shutterHeight) { shutterSettings[s].triggerHeight = shutterHeight; shutterSettings[s].triggerAction = shutterSettings[s].currentAction; adapter.log.info('#7 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 && + Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterHeight) { + + shutterSettings[s].triggerHeight = shutterHeight; + shutterSettings[s].triggerAction = shutterSettings[s].currentAction; + + adapter.log.info(`#8 Will open ID: ${shutterSettings[s].shutterName} value: ${shutterHeight}% after is the value for Goldenhour up`); + adapter.log.debug(`save new trigger height: ${shutterHeight}%`); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); } } } else { diff --git a/lib/shutterSunriseSunset.js b/lib/shutterSunriseSunset.js index 17e7d75..6b8643b 100644 --- a/lib/shutterSunriseSunset.js +++ b/lib/shutterSunriseSunset.js @@ -120,13 +120,24 @@ async function shutterSunriseSunset(adapter, sunriseStr, sunsetStr, shutterSetti } else if (currentValue != mustValue && currentValue != mustValueTilted && shutterSettings[s].driveAfterClose == true) { const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); - if (typeof _shutterState != undefined && _shutterState != null && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != shutterHeight) { + if (_shutterState?.val && + Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != shutterHeight) { + 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); + } else if (_shutterState?.val && + Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterHeight) { + + shutterSettings[s].triggerHeight = shutterHeight; + shutterSettings[s].triggerAction = shutterSettings[s].currentAction; + + adapter.log.info(`#22 Will open ID: ${shutterSettings[s].shutterName} value: ${shutterHeight}% after is the value for Sunrise up`); + adapter.log.debug(`save new trigger height: ${shutterHeight}%`); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); } } } else { diff --git a/lib/shutterUpChildren.js b/lib/shutterUpChildren.js index 09befba..030961f 100644 --- a/lib/shutterUpChildren.js +++ b/lib/shutterUpChildren.js @@ -118,6 +118,15 @@ async function driveshutterUpChildren(adapter, upTimeChildren, autoChildrenStr, 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 && + Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterHeight) { + + shutterSettings[s].triggerHeight = shutterHeight; + shutterSettings[s].triggerAction = shutterSettings[s].currentAction; + + adapter.log.info(`#24 Will open ID: ${shutterSettings[s].shutterName} value: ${shutterHeight}% after is the value for Children up`); + adapter.log.debug(`save new trigger height: ${shutterHeight}%`); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); } } } else { diff --git a/lib/shutterUpLiving.js b/lib/shutterUpLiving.js index 093a746..48c79da 100644 --- a/lib/shutterUpLiving.js +++ b/lib/shutterUpLiving.js @@ -29,7 +29,7 @@ async function driveshutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutte for (const i in result) { number++; } - timeoutLivingAuto = number !== 0 ? number * driveDelayUpLiving: driveDelayUpLiving; + timeoutLivingAuto = number !== 0 ? number * driveDelayUpLiving : driveDelayUpLiving; } for (const i in result) { @@ -109,16 +109,30 @@ async function driveshutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutte adapter.log.debug('shutterUpLiving #2 ' + shutterSettings[s].shutterName + ' already up at: ' + shutterHeight + '% - setting current action: ' + shutterSettings[s].currentAction); } - } else if (currentValue != mustValue && currentValue != mustValueTilted && shutterSettings[s].driveAfterClose == true) { + } else if (currentValue != mustValue && + currentValue != mustValueTilted && + shutterSettings[s].driveAfterClose == true) { + const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e)); - if (typeof _shutterState != undefined && _shutterState != null && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != shutterSettings[s].shutterHeight) { + if (_shutterState?.val && + Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != shutterSettings[s].shutterHeight) { + 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); + } else if (_shutterState?.val && + Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterHeight) { + + shutterSettings[s].triggerHeight = shutterHeight; + shutterSettings[s].triggerAction = shutterSettings[s].currentAction; + + adapter.log.info(`#16 Will open ID: ${shutterSettings[s].shutterName} value: ${shutterHeight}% after is the value for living up`); + adapter.log.debug(`save new trigger height: ${shutterHeight}%`); + adapter.log.debug(`save new trigger action: ${shutterSettings[s].triggerAction}`); } } } else { @@ -130,7 +144,7 @@ async function driveshutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutte } } adapter.log.debug(`Adapter Auto-Living is: ${autoLivingStr}`); - + // start living-auto after drive living shutter if ((autoLivingStr === true || autoLivingStr === 'true') && livingType === 'living') { await sleep(timeoutLivingAuto);