Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PulseLight add-in #141

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 47 additions & 0 deletions lib/addins/PulseLight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* jshint esversion: 6, strict: true, node: true */

'use strict';
/**
* @type {HandlerPattern}
*/
var HandlerPattern = require('./handlerpattern.js');
var log = require('debug')('PulseLight');

/**
* @class A custom handler that always sends a 1 to KNX to iterate the same pulse trigger
* @extends HandlerPattern
*/
class PulseLight extends HandlerPattern {

constructor(knxAPI) {
super(knxAPI); // call the super constructor first. Always.
}

/****
* onKNXValueChange is invoked if a Bus value for one of the bound addresses is received
*
*/
onKNXValueChange(field, oldValue, knxValue) {
var newValue; //Value for Homekit
if(field === "On"){
if((knxValue? 1:0) !== (oldValue? 1:0)){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't you compare old and knx values directly?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this code might be removed, as Homekit is the only source for setting the light there is no state to be send. Homekit remembers the state itself based on the signal send to KNX. There is no status to listen to for this PulseLight. I used existing code as base and tested it so it worked. Might be that there is code that could be removed / does not do anything special?

this.myAPI.setValue('On', newValue);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you never set newvalue to anything, what will be sent to homekit?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this code might be removed, as Homekit is the only source for setting the light there is no state to be send. Homekit remembers the state itself based on the signal send to KNX. There is no status to listen to for this PulseLight. I used existing code as base and tested it so it worked. Might be that there is code that could be removed / does not do anything special?

}
}
} // onBusValueChange

/****
* onHKValueChange is invoked if HomeKit is changing characteristic values
*
*/
onHKValueChange(field, oldValue, newValue) {
if(oldValue === undefined) oldValue = false; //For automation to work, else undefined will be compared to newValue if the light has the same state as adjusted by automation

log('INFO: onHKValueChange(' + field + ", "+ oldValue + ", "+ newValue + ")");
if(field === "On" && oldValue !== newValue){
this.myAPI.knxWrite(field, 1);
}
} // onHKValueChange

} // class
module.exports = PulseLight;