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 236ecf1 commit 4f0cd36
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 99 deletions.
2 changes: 1 addition & 1 deletion lib/shutterState.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
66 changes: 31 additions & 35 deletions lib/shutterSunriseSunset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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 ||
Expand All @@ -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;
Expand All @@ -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));
Expand All @@ -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 &&
Expand All @@ -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) {

Expand All @@ -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);
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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 ||
Expand All @@ -241,16 +239,15 @@ 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;
shutterSettings[s].currentAction = downAction;

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));
Expand All @@ -265,16 +262,15 @@ 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;
shutterSettings[s].currentAction = downAction;

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 &&
Expand All @@ -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 }%`);
}
}
}
Expand Down
Loading

0 comments on commit 4f0cd36

Please sign in to comment.