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

Pponce light fix #16

Merged
merged 18 commits into from
May 23, 2017
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ You must also set the fan_name to the name returned here.
| fan_name | _*Required*_ | Must get this from `getFanInfo.js` |
| fan_id | _*Required*_ | Must get this from `getFanInfo.js` |
| fan_ip_address | Optional | IP address of fan, defaults to broadcast |
| light_exists | Optional | Has light? set to true - default false |
| light_on | Optional | What "On" means - default Max |
| fan_on | Optional | What "On" means - default 3/7 |
| homekit_fan_name | Optional | Name to call the Fan in Homekit |
Expand Down
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ BigAssFansPlatform.prototype.addAccessory = function(theFan) {
"fan_name" : theFan.name,
"fan_id" : theFan.id,
"fan_ip_address" : theFan.address,
"light_exists" : theFan.light.exists,
"light_on" : platform.config.light_on,
"fan_on" : platform.config.fan_on,
"homekit_fan_name" : platform.config.homekit_fan_name,
Expand Down Expand Up @@ -122,6 +123,7 @@ function BigAssFanAccessory(log, config, existingAccessory) {
this.fanName = config["fan_name"]; // TODO: Allow this to be null
this.fanID = config["fan_id"];
this.fanIPAddress = config["fan_ip_address"]; // Can be null - resorts to broadcasting
this.lightExists = config["light_exists"] // Can be null - default is below
this.lightOn = config["light_on"]; // Can be null - default is below
this.fanOn = config["fan_on"]; // Can be null - default is below
this.homekitFanName = config["homekit_fan_name"]
Expand All @@ -136,6 +138,7 @@ function BigAssFanAccessory(log, config, existingAccessory) {
setDefault("fanIPAddress", "255.255.255.255");
setDefault("lightOn", 16);
setDefault("fanOn", 3);
setDefault("lightExists", false);

setDefault("name", this.fanName);
setDefault("homekitFanName", this.name + " Fan");
Expand Down Expand Up @@ -248,7 +251,7 @@ function BigAssFanAccessory(log, config, existingAccessory) {
var lightMaxBrightness = this.myBigAss.light.max ? this.myBigAss.light.max : 16;
var fanMaxSpeed = this.myBigAss.fan.max ? this.myBigAss.fan.max : 7;

if (this.myBigAss.light.exists) {
if (this.lightExists) {
this.log("Found a light for: " + this.homekitLightName);

var existingLightBulbService;
Expand Down Expand Up @@ -319,9 +322,15 @@ function BigAssFanAccessory(log, config, existingAccessory) {

BigAssFanAccessory.prototype.getStateFactory = function(propertyToWrap, subProperty, outputMapping) {
return function(callback) {
// TODO: Determine why update can callback multiple times
// This temporarily prevents multiple calls to the callback
var callbackCalled = false;
this.myBigAss[propertyToWrap].update(subProperty, function(err, value) {
var returnVal = outputMapping(value);
callback(err, returnVal);
if (!callbackCalled) { // TODO: remove after bug is found
callbackCalled = true;
callback(err, returnVal);
}
});
}
}
Expand Down