Skip to content

Commit

Permalink
(simatec) Code revision and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
simatec committed Aug 7, 2024
1 parent 6633474 commit 54e39cb
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions lib/shutterDownChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ async function driveshutterDownChildren(adapter, downTimeChildren, autoChildrenS
shutterSettings[s].alarmTriggerAction = downAction;

// overwrite target position and downAction if frost alarm is set.
if (statusAlarmFrost == true && shutterSettings[s].enableAlarmFrost == true && downAction != 'Xmas') {
if (statusAlarmFrost == true &&
shutterSettings[s].enableAlarmFrost == true &&
downAction != 'Xmas') {

targetLevel2Set = parseFloat(adapter.config.alarmFrostLevel);
downAction = 'frost';
}
Expand All @@ -80,22 +83,27 @@ async function driveshutterDownChildren(adapter, downTimeChildren, autoChildrenS
const nameDevice = shutterSettings[s].shutterName.replace(/[.;, ]/g, '_');
const _autoDownState = await adapter.getStateAsync(`shutters.autoDown.${nameDevice}`).catch((e) => adapter.log.warn(e));

if (_autoDownState && _autoDownState === true || _autoDownState && _autoDownState.val === true) {
if (_autoDownState?.val === true) {
if (pendingAlarm == false) {
let currentValue = '';
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 ? ('' + _triggerState.val) : '';

if (typeof _triggerState != undefined && _triggerState != null) {
currentValue = ('' + _triggerState.val);
}

if (currentValue === mustValue || currentValue === mustValueTilted || (currentValue != mustValue && currentValue != mustValueTilted && shutterSettings[s].autoDrive != 'onlyUp' && shutterSettings[s].autoDrive != 'off')) {
if (currentValue === mustValue ||
currentValue === mustValueTilted ||
(currentValue != mustValue &&
currentValue != mustValueTilted &&
shutterSettings[s].autoDrive != 'onlyUp' &&
shutterSettings[s].autoDrive != 'off')) {

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 != targetLevel2Set) {
if (_shutterState?.val &&
Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != targetLevel2Set) {

shutterSettings[s].currentHeight = targetLevel2Set;
shutterSettings[s].currentAction = downAction;
shutterSettings[s].lastAutoAction = 'Down_ChildrenTime';
Expand All @@ -107,7 +115,9 @@ async function driveshutterDownChildren(adapter, downTimeChildren, autoChildrenS
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 (typeof _shutterState != undefined && _shutterState != null && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == targetLevel2Set) {
else if (_shutterState?.val &&
Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == targetLevel2Set) {

shutterSettings[s].currentHeight = targetLevel2Set;
shutterSettings[s].currentAction = downAction;

Expand All @@ -118,7 +128,9 @@ async function driveshutterDownChildren(adapter, downTimeChildren, autoChildrenS
} else if (shutterSettings[s].triggerID == '') {
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 != targetLevel2Set) {
if (_shutterState?.val &&
Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != targetLevel2Set) {

shutterSettings[s].currentHeight = targetLevel2Set;
shutterSettings[s].currentAction = downAction;
shutterSettings[s].lastAutoAction = 'Down_ChildrenTime';
Expand All @@ -128,18 +140,25 @@ async function driveshutterDownChildren(adapter, downTimeChildren, autoChildrenS
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 (typeof _shutterState != undefined && _shutterState != null && Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == targetLevel2Set) {
else if (_shutterState?.val &&
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);
}
} 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 != targetLevel2Set) {
if (_shutterState?.val &&
Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != targetLevel2Set) {

shutterSettings[s].triggerHeight = targetLevel2Set;
shutterSettings[s].triggerAction = 'down';

Expand Down

0 comments on commit 54e39cb

Please sign in to comment.