Add devices even if discovery errors.

Don't assign everything POWER_STATE_CTYPE.
This commit is contained in:
Mike Riccio
2015-10-16 20:21:30 -07:00
parent 831480d035
commit c5499c122e

View File

@@ -19,8 +19,8 @@
// The default code for all HomeBridge accessories is 031-45-154. // The default code for all HomeBridge accessories is 031-45-154.
// //
var types = require("HAP-NodeJS/accessories/types.js"); var types = require("hap-nodejs/accessories/types.js");
var Characteristic = require("HAP-NodeJS").Characteristic; var Characteristic = require("hap-nodejs").Characteristic;
var request = require('request'); var request = require('request');
var async = require('async'); var async = require('async');
@@ -96,11 +96,11 @@ IndigoPlatform.prototype = {
if (asyncError) { if (asyncError) {
console.trace("Requesting Indigo device info."); console.trace("Requesting Indigo device info.");
that.log(asyncError); that.log(asyncError);
} else {
that.callback(that.foundAccessories.sort(function (a,b) {
return (a.name > b.name) - (a.name < b.name);
}));
} }
that.callback(that.foundAccessories.sort(function (a,b) {
return (a.name > b.name) - (a.name < b.name);
}));
}); });
}); });
} }
@@ -326,6 +326,8 @@ IndigoAccessory.prototype = {
}, },
controlCharacteristics: function(that) { controlCharacteristics: function(that) {
var hasAType = false;
var cTypes = [{ var cTypes = [{
cType: types.NAME_CTYPE, cType: types.NAME_CTYPE,
onUpdate: null, onUpdate: null,
@@ -338,30 +340,8 @@ IndigoAccessory.prototype = {
designedMaxLength: 255 designedMaxLength: 255
}]; }];
cTypes.push({
cType: types.POWER_STATE_CTYPE,
perms: [Characteristic.Perms.WRITE,Characteristic.Perms.READ,Characteristic.Perms.NOTIFY],
format: Characteristic.Formats.BOOL,
initialValue: (that.isOn) ? 1 : 0,
supportEvents: false,
supportBonjour: false,
manfDescription: "Change the power state",
designedMaxLength: 1,
onUpdate: function(value) {
if (value == 0) {
that.turnOff();
} else {
that.turnOn();
}
},
onRead: function(callback) {
that.query("isOn", function(isOn) {
callback((isOn) ? 1 : 0);
});
}
});
if (that.typeSupportsDim) { if (that.typeSupportsDim) {
hasAType = true;
cTypes.push({ cTypes.push({
cType: types.BRIGHTNESS_CTYPE, cType: types.BRIGHTNESS_CTYPE,
perms: [Characteristic.Perms.WRITE,Characteristic.Perms.READ,Characteristic.Perms.NOTIFY], perms: [Characteristic.Perms.WRITE,Characteristic.Perms.READ,Characteristic.Perms.NOTIFY],
@@ -384,6 +364,7 @@ IndigoAccessory.prototype = {
} }
if (that.typeSupportsSpeedControl) { if (that.typeSupportsSpeedControl) {
hasAType = true;
cTypes.push({ cTypes.push({
cType: types.ROTATION_SPEED_CTYPE, cType: types.ROTATION_SPEED_CTYPE,
perms: [Characteristic.Perms.WRITE,Characteristic.Perms.READ,Characteristic.Perms.NOTIFY], perms: [Characteristic.Perms.WRITE,Characteristic.Perms.READ,Characteristic.Perms.NOTIFY],
@@ -406,6 +387,7 @@ IndigoAccessory.prototype = {
} }
if (that.typeSupportsHVAC) { if (that.typeSupportsHVAC) {
hasAType = true;
cTypes.push({ cTypes.push({
cType: types.CURRENTHEATINGCOOLING_CTYPE, cType: types.CURRENTHEATINGCOOLING_CTYPE,
perms: [Characteristic.Perms.READ,Characteristic.Perms.NOTIFY], perms: [Characteristic.Perms.READ,Characteristic.Perms.NOTIFY],
@@ -486,7 +468,7 @@ IndigoAccessory.prototype = {
cType: types.TEMPERATURE_UNITS_CTYPE, cType: types.TEMPERATURE_UNITS_CTYPE,
perms: [Characteristic.Perms.READ,Characteristic.Perms.NOTIFY], perms: [Characteristic.Perms.READ,Characteristic.Perms.NOTIFY],
format: Characteristic.Formats.INT, format: Characteristic.Formats.INT,
initialValue: 1, initialValue: Characteristic.Units.FAHRENHEIT,
supportEvents: false, supportEvents: false,
supportBonjour: false, supportBonjour: false,
manfDescription: "Unit", manfDescription: "Unit",
@@ -497,6 +479,31 @@ IndigoAccessory.prototype = {
}); });
} }
if (that.typeSupportsOnOff || !hasAType) {
cTypes.push({
cType: types.POWER_STATE_CTYPE,
perms: [Characteristic.Perms.WRITE,Characteristic.Perms.READ,Characteristic.Perms.NOTIFY],
format: Characteristic.Formats.BOOL,
initialValue: (that.isOn) ? 1 : 0,
supportEvents: false,
supportBonjour: false,
manfDescription: "Change the power state",
designedMaxLength: 1,
onUpdate: function(value) {
if (value == 0) {
that.turnOff();
} else {
that.turnOn();
}
},
onRead: function(callback) {
that.query("isOn", function(isOn) {
callback((isOn) ? 1 : 0);
});
}
});
}
return cTypes; return cTypes;
}, },