Skip to content

Commit

Permalink
Update GarageDoorOpenerAdvanced.js
Browse files Browse the repository at this point in the history
Fixing issues for initial run of the addin.
  • Loading branch information
christof-fersch authored and snowdd1 committed Apr 6, 2023
1 parent 2382a1d commit 695f740
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions lib/addins/GarageDoorOpenerAdvanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
* "sensorOn"-keyword in knx_config.json (both need to operate the same way).
*
*/

/* jshint esversion: 6, strict: true, node: true */

'use strict';
/** * @type {HandlerPattern}
*/
Expand Down Expand Up @@ -103,7 +100,7 @@ class GarageDoorOpenerAdvanced extends HandlerPattern {
// - open - if the "open"-contact is present
// - closed - if the "closed"-contact is present
// - both - if both ontacts are present - no simulation in this case
this.doorContactPresent = this.myAPI.getLocalConstant("doorContactPresent");
this.doorContactPresent = this.myAPI.getLocalConstant("doorContactPresent");;

// Door run-time
this.doorRunTime = this.myAPI.getLocalConstant("doorRunTime"); // in mil.seconds
Expand Down Expand Up @@ -145,12 +142,10 @@ class GarageDoorOpenerAdvanced extends HandlerPattern {
if (field === "KNXPulseMove") {

if (knxValue === 1) {
var curDate = new Date();
var percentageRun;

if (oldValue !== 1){ // value changed?
console.log('INFO ' + this.debugName + ': KNXPulseMove detected');


if (this.timer1 !== undefined){
clearTimeout(this.timer1);
this.timer1 = undefined;
Expand Down Expand Up @@ -230,7 +225,8 @@ class GarageDoorOpenerAdvanced extends HandlerPattern {
this.myAPI.setValue("CurrentDoorState", 4); // STOPPED

// calculate percentageOpen

var curDate = new Date();
var percentageRun = undefined;

percentageRun = (curDate.getTime() - this.dateRunStart.getTime()) / this.doorRunTime;
console.log('INFO ' + this.debugName + ': percentageRun = ' + percentageRun);
Expand Down Expand Up @@ -266,7 +262,9 @@ class GarageDoorOpenerAdvanced extends HandlerPattern {
this.myAPI.setValue("CurrentDoorState", 4); // STOPPED

// calculate percentageOpen

var curDate = new Date();
var percentageRun = undefined;

percentageRun = (curDate.getTime() - this.dateRunStart.getTime()) / this.doorRunTime;
console.log('INFO ' + this.debugName + ': percentageRun = ' + percentageRun);
console.log('INFO ' + this.debugName + ': percentageOpen before = ' + this.percentageOpen);
Expand Down Expand Up @@ -349,7 +347,7 @@ class GarageDoorOpenerAdvanced extends HandlerPattern {
} // simulateDoorContactMode

}
else if (this.lastMove === "goingDown"){
else { // if (this.lastMove === "goingDown"){

console.log('INFO ' + this.debugName + ': TargetDoorState = 1 OPEN set');
this.myAPI.setValue("TargetDoorState", 0); // OPEN
Expand Down Expand Up @@ -733,7 +731,7 @@ class GarageDoorOpenerAdvanced extends HandlerPattern {
console.log('INFO ' + this.debugName + ': KNXDoorClosed = timer running detected');
}

} else if (oldValue === null) { // Init run
} else { // if (oldValue === null) { // Init run

console.log('INFO ' + this.debugName + ': Init Garage Door HK Status KNXDoorClosed = false');

Expand All @@ -757,10 +755,6 @@ class GarageDoorOpenerAdvanced extends HandlerPattern {
} // KNXDoorClosed


// TODO: Door is open, gets closed automatically by someone going through
// -> TargetDoorState needs to be set.


if (field==="KNXDoorOpened") {

console.log('INFO ' + this.debugName + ': In if-case -> field===KNXDoorOpened');
Expand Down Expand Up @@ -861,7 +855,7 @@ class GarageDoorOpenerAdvanced extends HandlerPattern {
console.log('INFO ' + this.debugName + ': KNXDoorOpened = timer running detected');
}

} else if (oldValue === null) { // Init run
} else { // if (oldValue === null) { // Init run

console.log('INFO ' + this.debugName + ': Init Garage Door HK Status KNXDoorOpened = false');

Expand Down Expand Up @@ -908,7 +902,7 @@ class GarageDoorOpenerAdvanced extends HandlerPattern {
// - open - if the "open"-contact is present
// - closed - if the "closed"-contact is present
// - both - if both ontacts are present - no simulation in this case
this.doorContactPresent = this.myAPI.getLocalConstant("doorContactPresent");
this.doorContactPresent = this.myAPI.getLocalConstant("doorContactPresent");;

// Door run-time
this.doorRunTime = this.myAPI.getLocalConstant("doorRunTime"); // in mil.seconds
Expand Down

0 comments on commit 695f740

Please sign in to comment.