diff --git a/README.md b/README.md index ea0862c..e72529a 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/index.js b/index.js index 5d526c2..2da9aee 100644 --- a/index.js +++ b/index.js @@ -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, @@ -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"] @@ -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"); @@ -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; @@ -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); + } }); } }