Skip to content

Commit

Permalink
(simatec) Fix eslint error
Browse files Browse the repository at this point in the history
  • Loading branch information
simatec committed Dec 9, 2024
1 parent 4f0cd36 commit fad46a2
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 129 deletions.
36 changes: 17 additions & 19 deletions lib/shutterDownChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ 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
async function driveshutterDownChildren(adapter, downTimeChildren, autoChildrenStr, shutterSettings, childrenType, driveDelayUpChildren, timeoutChildrenAuto) {
if (shutterSettings) {
const resChildren = shutterSettings.filter((/** @type {{ typeDown: string; }} */ d) => d.typeDown == childrenType); // Filter Area children or children-auto
const result = resChildren.filter((/** @type {{ enabled: boolean | string; }} */ d) => d.enabled === true || d.enabled === 'true'); // Filter enabled
const resChildren = shutterSettings.filter((d) => d.typeDown == childrenType); // Filter Area children or children-auto
const result = resChildren.filter((d) => d.enabled === true || d.enabled === 'true'); // Filter enabled
let number = 0;

if (childrenType == 'children') {
Expand Down Expand Up @@ -87,9 +87,9 @@ async function driveshutterDownChildren(adapter, downTimeChildren, autoChildrenS
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 ||
Expand All @@ -113,17 +113,16 @@ async function driveshutterDownChildren(adapter, downTimeChildren, autoChildrenS
await setShutterState(adapter, shutterSettings, shutterSettings[s], targetLevel2Set, nameDevice, 'Children down #26');

adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`);
adapter.log.debug('shutterDownChildren #1 ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + targetLevel2Set + '%');
}
else if (_shutterState?.val !== null && _shutterState?.val !== undefined &&
adapter.log.debug(`shutterDownChildren #1 ${ shutterSettings[s].shutterName } old height: ${ shutterSettings[s].oldHeight }% new height: ${ targetLevel2Set }%`);
} 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;

await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice);

adapter.log.debug('shutterDownChildren #1 ' + shutterSettings[s].shutterName + ' already down at: ' + targetLevel2Set + '% - setting current action: ' + shutterSettings[s].currentAction);
adapter.log.debug(`shutterDownChildren #1 ${ 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));
Expand All @@ -138,17 +137,16 @@ async function driveshutterDownChildren(adapter, downTimeChildren, autoChildrenS
await setShutterState(adapter, shutterSettings, shutterSettings[s], targetLevel2Set, nameDevice, 'Children down #27');

adapter.log.debug(`last automatic Action for ${shutterSettings[s].shutterName}: ${shutterSettings[s].lastAutoAction}`);
adapter.log.debug('shutterDownChildren #2 ' + shutterSettings[s].shutterName + ' old height: ' + shutterSettings[s].oldHeight + '% new height: ' + targetLevel2Set + '%');
}
else if (_shutterState?.val !== null && _shutterState?.val !== undefined &&
adapter.log.debug(`shutterDownChildren #2 ${ shutterSettings[s].shutterName } old height: ${ shutterSettings[s].oldHeight }% new height: ${ targetLevel2Set }%`);
} 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;

await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice);

adapter.log.debug('shutterDownChildren #2 ' + shutterSettings[s].shutterName + ' already down at: ' + targetLevel2Set + '% - setting current action: ' + shutterSettings[s].currentAction);
adapter.log.debug(`shutterDownChildren #2 ${ shutterSettings[s].shutterName } already down at: ${ targetLevel2Set }% - setting current action: ${ shutterSettings[s].currentAction}`);
}
} else if (currentValue != mustValue &&
currentValue != mustValueTilted &&
Expand All @@ -162,14 +160,14 @@ async function driveshutterDownChildren(adapter, downTimeChildren, autoChildrenS
shutterSettings[s].triggerHeight = targetLevel2Set;
shutterSettings[s].triggerAction = 'down';

adapter.log.info('#28 Will close ID: ' + shutterSettings[s].shutterName + ' value: ' + targetLevel2Set + '%' + ' after the window has been closed ');
adapter.log.debug('save new trigger height: ' + shutterSettings[s].triggerHeight + '%');
adapter.log.debug('save new trigger action: ' + shutterSettings[s].triggerAction);
adapter.log.info(`#28 Will close ID: ${ shutterSettings[s].shutterName } value: ${ targetLevel2Set }%` + ` after the window has been closed `);
adapter.log.debug(`save new trigger height: ${ shutterSettings[s].triggerHeight }%`);
adapter.log.debug(`save new trigger action: ${ shutterSettings[s].triggerAction}`);
}
}
await sleep(driveDelayUpChildren);
} else {
adapter.log.info('Down children not moving now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + targetLevel2Set + '%');
adapter.log.info(`Down children not moving now due to active alarm: ${ shutterSettings[s].shutterName } value: ${ targetLevel2Set }%`);
}
}
}
Expand Down Expand Up @@ -208,7 +206,7 @@ async function shutterDownChildren(adapter, downTimeChildren, delayDown, autoChi

schedule.cancelJob('shutterDownChildren');
try {
const downChildren = schedule.scheduleJob('shutterDownChildren', downTime[1] + ' ' + downTime[0] + ' * * *', async function () {
const downChildren = schedule.scheduleJob('shutterDownChildren', `${downTime[1] } ${ downTime[0] } * * *`, async function () {
delayDown = delayDown * driveDelayUpLiving;
await sleep(delayDown);
driveshutterDownChildren(adapter, downTimeChildren, autoChildrenStr, shutterSettings, childrenType, driveDelayUpChildren, timeoutChildrenAuto);
Expand Down
37 changes: 17 additions & 20 deletions lib/shutterDownComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ async function shutterDownComplete(adapter, delayDown, shutterSettings) {
const driveDelayDownLiving = adapter.config.driveDelayDownLiving * 1000;
const downTimeComplete = adapter.config.betweenPositionTime.split(':');

adapter.log.debug('complete down at ' + adapter.config.betweenPositionTime);
adapter.log.debug(`complete down at ${ adapter.config.betweenPositionTime}`);

schedule.cancelJob('shutterDownComplete');

const downComplete = schedule.scheduleJob('shutterDownComplete', downTimeComplete[1] + ' ' + downTimeComplete[0] + ' * * *', async function () {
const downComplete = schedule.scheduleJob('shutterDownComplete', `${downTimeComplete[1] } ${ downTimeComplete[0] } * * *`, async function () {
delayDown = delayDown * driveDelayDownLiving;

if (shutterSettings) {
const resLiving = shutterSettings.filter((/** @type {{ betweenPosition: boolean; }} */ d) => d.betweenPosition == true); // 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.betweenPosition == true); // 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) {
Expand Down Expand Up @@ -72,9 +72,9 @@ async function shutterDownComplete(adapter, delayDown, shutterSettings) {
if (_autoDownState?.val) {
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 ||
Expand All @@ -97,16 +97,15 @@ async function shutterDownComplete(adapter, delayDown, shutterSettings) {
await setShutterState(adapter, shutterSettings, shutterSettings[s], targetLevel2Set, nameDevice, 'Complete Down #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;
shutterSettings[s].currentAction = 'down';

await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice);

adapter.log.debug('Complete down ' + shutterSettings[s].shutterName + ' already down at: ' + targetLevel2Set + '% - setting current action: ' + shutterSettings[s].currentAction);
adapter.log.debug(`Complete 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));
Expand All @@ -121,16 +120,15 @@ async function shutterDownComplete(adapter, delayDown, shutterSettings) {
await setShutterState(adapter, shutterSettings, shutterSettings[s], targetLevel2Set, nameDevice, 'Complete Down #13');

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;
shutterSettings[s].currentAction = 'down';

await setShutterInfo(adapter, shutterSettings, shutterSettings[s], nameDevice);

adapter.log.debug('Complete down ' + shutterSettings[s].shutterName + ' already down at: ' + targetLevel2Set + '% - setting current action: ' + shutterSettings[s].currentAction);
adapter.log.debug(`Complete down ${ shutterSettings[s].shutterName } already down at: ${ targetLevel2Set }% - setting current action: ${ shutterSettings[s].currentAction}`);
}
} else if (currentValue != mustValue &&
currentValue != mustValueTilted &&
Expand All @@ -144,14 +142,14 @@ async function shutterDownComplete(adapter, delayDown, shutterSettings) {
shutterSettings[s].triggerHeight = targetLevel2Set;
shutterSettings[s].triggerAction = 'down';

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(delayDown);
} else {
adapter.log.info('Down Complete not moving now due to active alarm: ' + shutterSettings[s].shutterName + ' value: ' + targetLevel2Set + '%');
adapter.log.info(`Down Complete not moving now due to active alarm: ${ shutterSettings[s].shutterName } value: ${ targetLevel2Set }%`);
}
}
}
Expand All @@ -162,9 +160,8 @@ async function shutterDownComplete(adapter, delayDown, shutterSettings) {
return (shutterSettings);
}
});
}
catch (e) {
adapter.log.error('exception catch shutterDownComplete [' + e + ']');
} catch (e) {
adapter.log.error(`exception catch shutterDownComplete [${ e }]`);
}
}
module.exports = shutterDownComplete;
Loading

0 comments on commit fad46a2

Please sign in to comment.