Skip to content

Commit

Permalink
(simatec) Fix Trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
simatec committed Aug 8, 2024
1 parent e1e29a5 commit 661128d
Show file tree
Hide file tree
Showing 17 changed files with 207 additions and 213 deletions.
14 changes: 7 additions & 7 deletions lib/buttonAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async function buttonAction(adapter, buttonState, shutterSettings) {

const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e));

if (_shutterState?.val &&
if (_shutterState?.val !== null && _shutterState?.val !== undefined &&
Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != targetLevel2Set) {

shutterSettings[s].currentHeight = targetLevel2Set;
Expand All @@ -106,7 +106,7 @@ async function buttonAction(adapter, buttonState, shutterSettings) {

adapter.log.debug(`shutterDownButton ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${targetLevel2Set}%`);
}
else if (_shutterState?.val &&
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 @@ -125,7 +125,7 @@ async function buttonAction(adapter, buttonState, shutterSettings) {

const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e));

if (_shutterState?.val &&
if (_shutterState?.val !== null && _shutterState?.val !== undefined &&
Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != shutterSettings[s].heightUp) {

shutterSettings[s].currentHeight = shutterSettings[s].heightUp;
Expand All @@ -139,7 +139,7 @@ async function buttonAction(adapter, buttonState, shutterSettings) {

adapter.log.debug(`shutterUpButton ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${shutterSettings[s].heightUp}%`);
}
else if (_shutterState?.val &&
else if (_shutterState?.val !== null && _shutterState?.val !== undefined &&
Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterSettings[s].heightUp) {

shutterSettings[s].currentHeight = shutterSettings[s].heightUp;
Expand All @@ -160,7 +160,7 @@ async function buttonAction(adapter, buttonState, shutterSettings) {

const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e));

if (_shutterState?.val &&
if (_shutterState?.val !== null && _shutterState?.val !== undefined &&
Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != shutterSettings[s].heightDownSun) {

shutterSettings[s].currentHeight = shutterSettings[s].heightDownSun;
Expand All @@ -174,7 +174,7 @@ async function buttonAction(adapter, buttonState, shutterSettings) {

adapter.log.debug(`shutterUpButton ${shutterSettings[s].shutterName} old height: ${shutterSettings[s].oldHeight}% new height: ${shutterSettings[s].heightUp}%`);
}
else if (_shutterState?.val &&
else if (_shutterState?.val !== null && _shutterState?.val !== undefined &&
Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterSettings[s].heightDownSun) {

shutterSettings[s].currentHeight = shutterSettings[s].heightDownSun;
Expand All @@ -191,7 +191,7 @@ async function buttonAction(adapter, buttonState, shutterSettings) {
} else if (buttonState == 'autoAll') {
const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e));

if (_shutterState?.val) {
if (_shutterState?.val !== null && _shutterState?.val !== undefined) {
adapter.log.info(`Set ID: ${shutterSettings[s].shutterName} to Auto-Mode`);

if (Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound == shutterSettings[s].heightDownSun) {
Expand Down
12 changes: 6 additions & 6 deletions lib/elevationDown.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function elevationDown(adapter, elevation, azimuth, shutterSettings) {
const mustValue = ('' + shutterSettings[s].triggerState);
const mustValueTilted = shutterSettings[s].triggerStateTilted == 'none' ? ('' + shutterSettings[s].triggerState) : ('' + shutterSettings[s].triggerStateTilted);

let currentValue = _triggerState?.val ? ('' + _triggerState.val) : '';
let currentValue = _triggerState?.val !== null && _triggerState?.val !== undefined ? ('' + _triggerState.val) : '';


if (currentValue === mustValue ||
Expand All @@ -96,7 +96,7 @@ async function elevationDown(adapter, elevation, azimuth, shutterSettings) {

const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e));

if (_shutterState?.val &&
if (_shutterState?.val !== null && _shutterState?.val !== undefined &&
Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != targetLevel2Set) {

shutterSettings[s].currentHeight = targetLevel2Set;
Expand All @@ -110,7 +110,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 &&
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 @@ -123,7 +123,7 @@ async function elevationDown(adapter, elevation, azimuth, shutterSettings) {
} else if (shutterSettings[s].triggerID == '') {
const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e));

if (_shutterState?.val &&
if (_shutterState?.val !== null && _shutterState?.val !== undefined &&
Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != targetLevel2Set) {

shutterSettings[s].currentHeight = targetLevel2Set;
Expand All @@ -135,7 +135,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 &&
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 @@ -152,7 +152,7 @@ async function elevationDown(adapter, elevation, azimuth, shutterSettings) {

const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e));

if (_shutterState?.val &&
if (_shutterState?.val !== null && _shutterState?.val !== undefined &&
Math.round(_shutterState.val / adapter.config.shutterStateRound) * adapter.config.shutterStateRound != targetLevel2Set) {

shutterSettings[s].triggerHeight = targetLevel2Set;
Expand Down
Loading

0 comments on commit 661128d

Please sign in to comment.