-
Notifications
You must be signed in to change notification settings - Fork 55
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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)){ | ||
this.myAPI.setValue('On', newValue); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you never set newvalue to anything, what will be sent to homekit? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?