Skip to content

Commit

Permalink
(simatec) Fix Auto-Living, Auto-Sleep & Auto-Children
Browse files Browse the repository at this point in the history
  • Loading branch information
simatec committed Oct 9, 2023
1 parent fc61c64 commit 5d4dc91
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ When the adapter crashes or an other Code error happens, this error message that
### __WORK IN PROGRESS__
* (simatec) Saturday added as work week
* (simatec) Dependencies updated
* (simatec) Fix Auto-Living, Auto-Sleep & Auto-Children

### 1.6.2 (2023-08-28)
* (simatec) Dependencies updated
Expand Down
8 changes: 5 additions & 3 deletions lib/shutterUpChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ async function sleep(ms) {
// @ts-ignore
async function driveshutterUpChildren(adapter, upTimeChildren, autoChildrenStr, shutterSettings, childrenType, driveDelayUpChildren, timeoutChildrenAuto, noGoDelay) {
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; }} */ d) => d.enabled === true); // Filter enabled

let number = 0;

if (childrenType == 'children') {
if (childrenType === 'children') {
for (const i in result) {
number++;
}
timeoutChildrenAuto = number * driveDelayUpChildren;
timeoutChildrenAuto = number !== 0 ? number * driveDelayUpChildren : driveDelayUpChildren;
}

for (const i in result) {
Expand Down Expand Up @@ -127,7 +129,7 @@ async function driveshutterUpChildren(adapter, upTimeChildren, autoChildrenStr,
}
}
// start children-auto after drive children shutter
if (autoChildrenStr == true && childrenType == 'children') {
if (autoChildrenStr === true && childrenType === 'children') {
await sleep(timeoutChildrenAuto);
childrenType = 'children-auto';
driveshutterUpChildren(adapter, upTimeChildren, autoChildrenStr, shutterSettings, childrenType, driveDelayUpChildren, timeoutChildrenAuto, noGoDelay);
Expand Down
8 changes: 5 additions & 3 deletions lib/shutterUpLiving.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ async function sleep(ms) {
// @ts-ignore
async function driveshutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutterSettings, livingType, driveDelayUpLiving, timeoutLivingAuto, noGoDelay) {
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; }} */ d) => d.enabled === true); // Filter enabled

let number = 0;

if (livingType == 'living') {
if (livingType === 'living') {
for (const i in result) {
number++;
}
timeoutLivingAuto = number * driveDelayUpLiving;
timeoutLivingAuto = number !== 0 ? number * driveDelayUpLiving: driveDelayUpLiving;
}

for (const i in result) {
Expand Down Expand Up @@ -128,7 +130,7 @@ async function driveshutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutte
}
}
// start living-auto after drive living shutter
if (autoLivingStr == true && livingType == 'living') {
if (autoLivingStr === true && livingType === 'living') {
await sleep(timeoutLivingAuto);
livingType = 'living-auto';
driveshutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutterSettings, livingType, driveDelayUpLiving, timeoutLivingAuto, noGoDelay);
Expand Down
7 changes: 4 additions & 3 deletions lib/shutterUpSleep.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ async function sleep(ms) {
// @ts-ignore
async function driveshutterUpSleep(adapter, upTimeSleep, autoSleepStr, shutterSettings, sleepType, driveDelayUpSleep, timeoutSleepAuto, noGoDelay) {
if (shutterSettings) {
adapter.log.debug(`Sleep-type: ${sleepType}`);

const resSleep = shutterSettings.filter((/** @type {{ typeUp: any; }} */ d) => d.typeUp == sleepType); // Filter Area sleep
let result = resSleep.filter((/** @type {{ enabled: boolean; }} */ d) => d.enabled === true); // Filter enabled
const result = resSleep.filter((/** @type {{ enabled: boolean; }} */ d) => d.enabled === true); // Filter enabled
;
let number = 0;

if (sleepType == 'sleep') {
for (const i in result) {
number++;
}
timeoutSleepAuto = number * driveDelayUpSleep;
timeoutSleepAuto = number !== 0 ? number * driveDelayUpSleep : driveDelayUpSleep;
}

for (const i in result) {
Expand Down Expand Up @@ -128,7 +129,7 @@ async function driveshutterUpSleep(adapter, upTimeSleep, autoSleepStr, shutterSe
}
}
// start sleep-auto after drive sleep shutter
if (autoSleepStr == true && sleepType == 'sleep') {
if (autoSleepStr === true && sleepType === 'sleep') {
await sleep(timeoutSleepAuto);
sleepType = 'sleep-auto';
driveshutterUpSleep(adapter, upTimeSleep, autoSleepStr, shutterSettings, sleepType, driveDelayUpSleep, timeoutSleepAuto, noGoDelay);
Expand Down
16 changes: 8 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1193,14 +1193,14 @@ function delayCalc() {
const resultFull = shutterSettings; // Full Result

if (resultFull) {
if ((upTimeLiving) === (upTimeSleep)) {
if (upTimeLiving === upTimeSleep) {
const resLiving = resultFull.filter((/** @type {{ typeUp: string; }} */ d) => d.typeUp === 'living'); // Filter Area Living
const result = resLiving.filter((/** @type {{ enabled: boolean; }} */ d) => d.enabled === true); // Filter enabled

for (const i in result) {
delayUp++;
}
if ((autoLivingStr) === true) {
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; }} */ d) => d.enabled === true); // Filter enabled

Expand All @@ -1210,7 +1210,7 @@ function delayCalc() {
}
}

if ((upTimeSleep) === (upTimeChildren)) {
if (upTimeSleep === upTimeChildren) {
delayUpChildren = delayUp;

const resLiving = resultFull.filter((/** @type {{ typeUp: string; }} */ d) => d.typeUp === 'sleep'); // Filter Area Sleep
Expand All @@ -1219,7 +1219,7 @@ function delayCalc() {
for (const i in result) {
delayUpChildren++;
}
if ((autoSleepStr) === true) {
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; }} */ d) => d.enabled === true); // Filter enabled

Expand All @@ -1228,14 +1228,14 @@ function delayCalc() {
}
}
}
if ((downTimeLiving) === (downTimeSleep)) {
if (downTimeLiving === downTimeSleep) {
const resLiving2 = resultFull.filter((/** @type {{ typeDown: string; }} */ d) => d.typeDown === 'living'); // Filter Area Living
const result3 = resLiving2.filter((/** @type {{ enabled: boolean; }} */ d) => d.enabled === true); // Filter enabled

for (const i in result3) {
delayDown++;
}
if ((autoLivingStr) === true) {
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; }} */ d) => d.enabled === true); // Filter enabled

Expand All @@ -1245,7 +1245,7 @@ function delayCalc() {
}
}

if ((downTimeSleep) === (downTimeChildren)) {
if (downTimeSleep === downTimeChildren) {
delayDownChildren = delayDown;

const resLiving2 = resultFull.filter((/** @type {{ typeDown: string; }} */ d) => d.typeDown === 'sleep'); // Filter Area Sleep
Expand All @@ -1255,7 +1255,7 @@ function delayCalc() {
delayDownChildren++;
}

if ((autoSleepStr) === true) {
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; }} */ d) => d.enabled === true); // Filter enabled

Expand Down

0 comments on commit 5d4dc91

Please sign in to comment.