Skip to content

Commit

Permalink
(simatec) Fix eslint check
Browse files Browse the repository at this point in the history
  • Loading branch information
simatec committed Dec 9, 2024
1 parent fad46a2 commit 24deb26
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 112 deletions.
18 changes: 8 additions & 10 deletions lib/elevationDown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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 ||
Expand All @@ -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;
Expand All @@ -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;
Expand Down
12 changes: 4 additions & 8 deletions lib/isSummerTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`);
Expand All @@ -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);
Expand All @@ -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}`);
}
}
Expand Down
13 changes: 3 additions & 10 deletions lib/setShutter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}%`);
Expand Down Expand Up @@ -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}`);
}
Expand Down
Loading

0 comments on commit 24deb26

Please sign in to comment.