Removed tabs

This commit is contained in:
Mike Riccio
2015-10-15 16:47:59 -07:00
parent 9ad8a111c6
commit 6fa69c5c4b

View File

@@ -8,10 +8,10 @@
// { // {
// "platform": "Indigo", // required // "platform": "Indigo", // required
// "name": "Indigo", // required // "name": "Indigo", // required
// "host": "127.0.0.1", // required // "host": "127.0.0.1", // required
// "port": "8176", // required // "port": "8176", // required
// "username": "username", // optional // "username": "username", // optional
// "password": "password" // optional // "password": "password" // optional
// } // }
// ], // ],
// //
@@ -28,19 +28,19 @@ var async = require('async');
function IndigoPlatform(log, config) { function IndigoPlatform(log, config) {
this.log = log; this.log = log;
this.baseURL = "http://" + config["host"] + ":" + config["port"]; this.baseURL = "http://" + config["host"] + ":" + config["port"];
if (config["username"] && config["password"]) { if (config["username"] && config["password"]) {
this.auth = { this.auth = {
'user': config["username"], 'user': config["username"],
'pass': config["password"], 'pass': config["password"],
'sendImmediately': false 'sendImmediately': false
}; };
} }
} }
IndigoPlatform.prototype = { IndigoPlatform.prototype = {
accessories: function(callback) { accessories: function(callback) {
var that = this; var that = this;
this.log("Discovering Indigo Devices."); this.log("Discovering Indigo Devices.");
@@ -48,11 +48,11 @@ IndigoPlatform.prototype = {
url: this.baseURL + "/devices.json/", url: this.baseURL + "/devices.json/",
method: 'GET' method: 'GET'
}; };
if (this.auth) { if (this.auth) {
options['auth'] = this.auth; options['auth'] = this.auth;
} }
this.foundAccessories = []; this.foundAccessories = [];
this.callback = callback; this.callback = callback;
request(options, function(error, response, body) { request(options, function(error, response, body) {
if (error) { if (error) {
@@ -61,73 +61,73 @@ IndigoPlatform.prototype = {
return error; return error;
} }
// Cheesy hack because response may have an extra comma at the start of the array, which is invalid // Cheesy hack because response may have an extra comma at the start of the array, which is invalid
var firstComma = body.indexOf(","); var firstComma = body.indexOf(",");
if (firstComma < 10) { if (firstComma < 10) {
body = "[" + body.substr(firstComma + 1); body = "[" + body.substr(firstComma + 1);
} }
var json = JSON.parse(body); var json = JSON.parse(body);
async.each(json, function(item, asyncCallback) { async.each(json, function(item, asyncCallback) {
var deviceURL = that.baseURL + item.restURL; var deviceURL = that.baseURL + item.restURL;
var deviceOptions = { var deviceOptions = {
url: deviceURL, url: deviceURL,
method: 'GET' method: 'GET'
}; };
if (that.auth) { if (that.auth) {
deviceOptions['auth'] = that.auth; deviceOptions['auth'] = that.auth;
} }
request(deviceOptions, function(deviceError, deviceResponse, deviceBody) { request(deviceOptions, function(deviceError, deviceResponse, deviceBody) {
if (deviceError) { if (deviceError) {
asyncCallback(deviceError); asyncCallback(deviceError);
} }
var deviceJson = JSON.parse(deviceBody); var deviceJson = JSON.parse(deviceBody);
that.log("Discovered " + deviceJson.type + ": " + deviceJson.name); that.log("Discovered " + deviceJson.type + ": " + deviceJson.name);
that.foundAccessories.push( that.foundAccessories.push(
new IndigoAccessory(that.log, that.auth, deviceURL, deviceJson)); new IndigoAccessory(that.log, that.auth, deviceURL, deviceJson));
asyncCallback(); asyncCallback();
}); });
}, function(asyncError) { }, function(asyncError) {
// This will be called after all the requests complete // This will be called after all the requests complete
if (asyncError) { if (asyncError) {
console.trace("Requesting Indigo device info."); console.trace("Requesting Indigo device info.");
that.log(asyncError); that.log(asyncError);
} else { } else {
that.callback(that.foundAccessories.sort(function (a,b) { that.callback(that.foundAccessories.sort(function (a,b) {
return (a.name > b.name) - (a.name < b.name); return (a.name > b.name) - (a.name < b.name);
})); }));
} }
}); });
}); });
} }
} }
function IndigoAccessory(log, auth, deviceURL, json) { function IndigoAccessory(log, auth, deviceURL, json) {
this.log = log; this.log = log;
this.auth = auth; this.auth = auth;
this.deviceURL = deviceURL; this.deviceURL = deviceURL;
for (var prop in json) { for (var prop in json) {
if (json.hasOwnProperty(prop)) { if (json.hasOwnProperty(prop)) {
this[prop] = json[prop]; this[prop] = json[prop];
} }
} }
} }
IndigoAccessory.prototype = { IndigoAccessory.prototype = {
getStatus: function(callback) { getStatus: function(callback) {
var that = this; var that = this;
var options = { var options = {
url: this.deviceURL, url: this.deviceURL,
method: 'GET' method: 'GET'
}; };
if (this.auth) { if (this.auth) {
options['auth'] = this.auth; options['auth'] = this.auth;
} }
request(options, function(error, response, body) { request(options, function(error, response, body) {
if (error) { if (error) {
@@ -136,22 +136,22 @@ IndigoAccessory.prototype = {
return error; return error;
} }
that.log("getStatus of " + that.name + ": " + body); that.log("getStatus of " + that.name + ": " + body);
callback(JSON.parse(body)); callback(JSON.parse(body));
}); });
}, },
updateStatus: function(params) { updateStatus: function(params) {
var that = this; var that = this;
var options = { var options = {
url: this.deviceURL + "?" + params, url: this.deviceURL + "?" + params,
method: 'PUT' method: 'PUT'
}; };
if (this.auth) { if (this.auth) {
options['auth'] = this.auth; options['auth'] = this.auth;
} }
this.log("updateStatus of " + that.name + ": " + params); this.log("updateStatus of " + that.name + ": " + params);
request(options, function(error, response, body) { request(options, function(error, response, body) {
if (error) { if (error) {
console.trace("Updating Device Status."); console.trace("Updating Device Status.");
@@ -162,101 +162,101 @@ IndigoAccessory.prototype = {
}, },
query: function(prop, callback) { query: function(prop, callback) {
this.getStatus(function(json) { this.getStatus(function(json) {
callback(json[prop]); callback(json[prop]);
}); });
}, },
turnOn: function() { turnOn: function() {
if (this.typeSupportsOnOff) { if (this.typeSupportsOnOff) {
this.updateStatus("isOn=1"); this.updateStatus("isOn=1");
} }
}, },
turnOff: function() { turnOff: function() {
if (this.typeSupportsOnOff) { if (this.typeSupportsOnOff) {
this.updateStatus("isOn=0"); this.updateStatus("isOn=0");
} }
}, },
setBrightness: function(brightness) { setBrightness: function(brightness) {
if (this.typeSupportsDim && brightness >= 0 && brightness <= 100) { if (this.typeSupportsDim && brightness >= 0 && brightness <= 100) {
this.updateStatus("brightness=" + brightness); this.updateStatus("brightness=" + brightness);
} }
}, },
setSpeedIndex: function(speedIndex) { setSpeedIndex: function(speedIndex) {
if (this.typeSupportsSpeedControl && speedIndex >= 0 && speedIndex <= 3) { if (this.typeSupportsSpeedControl && speedIndex >= 0 && speedIndex <= 3) {
this.updateStatus("speedIndex=" + speedIndex); this.updateStatus("speedIndex=" + speedIndex);
} }
}, },
getCurrentHeatingCooling: function(callback) { getCurrentHeatingCooling: function(callback) {
this.getStatus(function(json) { this.getStatus(function(json) {
var mode = 0; var mode = 0;
if (json["hvacOperatonModeIsHeat"]) { if (json["hvacOperatonModeIsHeat"]) {
mode = 1; mode = 1;
} }
else if (json["hvacOperationModeIsCool"]) { else if (json["hvacOperationModeIsCool"]) {
mode = 2; mode = 2;
} }
else if (json["hvacOperationModeIsAuto"]) { else if (json["hvacOperationModeIsAuto"]) {
mode = 3; mode = 3;
} }
callback(mode); callback(mode);
}); });
}, },
setTargetHeatingCooling: function(mode) { setTargetHeatingCooling: function(mode) {
if (mode == 0) { if (mode == 0) {
param = "Off"; param = "Off";
} }
else if (mode == 1) { else if (mode == 1) {
param = "Heat"; param = "Heat";
} }
else if (mode == 2) { else if (mode == 2) {
param = "Cool"; param = "Cool";
} }
else if (mode == 3) { else if (mode == 3) {
param = "Auto"; param = "Auto";
} }
if (param) { if (param) {
this.updateStatus("hvacOperationModeIs" + param + "=true"); this.updateStatus("hvacOperationModeIs" + param + "=true");
} }
}, },
getTargetTemperature: function(callback) { getTargetTemperature: function(callback) {
this.getStatus(function(json) { this.getStatus(function(json) {
var result; var result;
if (json["hvacOperatonModeIsHeat"]) { if (json["hvacOperatonModeIsHeat"]) {
result = json["setpointHeat"]; result = json["setpointHeat"];
} }
else if (json["hvacOperationModeIsCool"]) { else if (json["hvacOperationModeIsCool"]) {
result = json["setpointCool"]; result = json["setpointCool"];
} }
else { else {
result = (json["setpointHeat"] + json["setpointCool"]) / 2; result = (json["setpointHeat"] + json["setpointCool"]) / 2;
} }
callback(result); callback(result);
}); });
}, },
setTargetTemperature: function(temperature) { setTargetTemperature: function(temperature) {
var that = this; var that = this;
this.getStatus(function(json) { this.getStatus(function(json) {
if (json["hvacOperatonModeIsHeat"]) { if (json["hvacOperatonModeIsHeat"]) {
that.updateStatus("setpointHeat=" + temperature); that.updateStatus("setpointHeat=" + temperature);
} }
else if (json["hvacOperationModeIsCool"]) { else if (json["hvacOperationModeIsCool"]) {
that.updateStatus("setpointCool=" + temperature); that.updateStatus("setpointCool=" + temperature);
} }
else { else {
var cool = temperature + 5; var cool = temperature + 5;
var heat = temperature - 5; var heat = temperature - 5;
that.updateStatus("setpointCool=" + cool + "&setpointHeat=" + heat); that.updateStatus("setpointCool=" + cool + "&setpointHeat=" + heat);
} }
}); });
}, },
informationCharacteristics: function() { informationCharacteristics: function() {
@@ -316,7 +316,7 @@ IndigoAccessory.prototype = {
}, },
controlCharacteristics: function(that) { controlCharacteristics: function(that) {
var cTypes = [{ var cTypes = [{
cType: types.NAME_CTYPE, cType: types.NAME_CTYPE,
onUpdate: null, onUpdate: null,
perms: [Characteristic.Perms.READ], perms: [Characteristic.Perms.READ],
@@ -326,15 +326,15 @@ IndigoAccessory.prototype = {
supportBonjour: false, supportBonjour: false,
manfDescription: "Name of the accessory", manfDescription: "Name of the accessory",
designedMaxLength: 255 designedMaxLength: 255
}]; }];
/* if (that.typeSupportsOnOff) /* if (that.typeSupportsOnOff)
{ */ { */
cTypes.push({ cTypes.push({
cType: types.POWER_STATE_CTYPE, cType: types.POWER_STATE_CTYPE,
perms: [Characteristic.Perms.WRITE,Characteristic.Perms.READ,Characteristic.Perms.NOTIFY], perms: [Characteristic.Perms.WRITE,Characteristic.Perms.READ,Characteristic.Perms.NOTIFY],
format: Characteristic.Formats.BOOL, format: Characteristic.Formats.BOOL,
initialValue: (that.isOn) ? 1 : 0, initialValue: (that.isOn) ? 1 : 0,
supportEvents: true, supportEvents: true,
supportBonjour: false, supportBonjour: false,
manfDescription: "Change the power state", manfDescription: "Change the power state",
@@ -347,14 +347,14 @@ IndigoAccessory.prototype = {
} }
}, },
onRead: function(callback) { onRead: function(callback) {
that.query("isOn", function(isOn) { that.query("isOn", function(isOn) {
callback((isOn) ? 1 : 0); callback((isOn) ? 1 : 0);
}); });
} }
}); });
// } // }
if (that.typeSupportsDim) if (that.typeSupportsDim)
{ {
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],
@@ -368,10 +368,10 @@ IndigoAccessory.prototype = {
designedMinStep: 1, designedMinStep: 1,
unit: Characteristic.Units.PERCENTAGE, unit: Characteristic.Units.PERCENTAGE,
onUpdate: function(value) { onUpdate: function(value) {
that.setBrightness(value); that.setBrightness(value);
}, },
onRead: function(callback) { onRead: function(callback) {
that.query("brightness", callback); that.query("brightness", callback);
} }
}); });
} }
@@ -386,11 +386,11 @@ IndigoAccessory.prototype = {
supportBonjour: false, supportBonjour: false,
manfDescription: "Change the speed of the fan", manfDescription: "Change the speed of the fan",
designedMaxLength: 1, designedMaxLength: 1,
designedMinValue: 0, designedMinValue: 0,
designedMaxValue: 3, designedMaxValue: 3,
designedMinStep: 1, designedMinStep: 1,
onUpdate: function(value) { onUpdate: function(value) {
that.setSpeedIndex(value); that.setSpeedIndex(value);
}, },
onRead: function(callback) { onRead: function(callback) {
that.query("speedIndex", callback); that.query("speedIndex", callback);
@@ -400,44 +400,44 @@ IndigoAccessory.prototype = {
if (that.typeSupportsHVAC) if (that.typeSupportsHVAC)
{ {
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],
format: Characteristic.Formats.INT, format: Characteristic.Formats.INT,
initialValue: 0, initialValue: 0,
supportEvents: true, supportEvents: true,
supportBonjour: false, supportBonjour: false,
manfDescription: "Current Mode", manfDescription: "Current Mode",
designedMaxLength: 1, designedMaxLength: 1,
designedMinValue: 0, designedMinValue: 0,
designedMaxValue: 3, designedMaxValue: 3,
designedMinStep: 1, designedMinStep: 1,
onUpdate: null, onUpdate: null,
onRead: function(callback) { onRead: function(callback) {
that.getCurrentHeatingCooling(callback); that.getCurrentHeatingCooling(callback);
} }
}); });
cTypes.push({ cTypes.push({
cType: types.TARGETHEATINGCOOLING_CTYPE, cType: types.TARGETHEATINGCOOLING_CTYPE,
perms: [Characteristic.Perms.WRITE,Characteristic.Perms.READ,Characteristic.Perms.NOTIFY], perms: [Characteristic.Perms.WRITE,Characteristic.Perms.READ,Characteristic.Perms.NOTIFY],
format: Characteristic.Formats.INT, format: Characteristic.Formats.INT,
initialValue: 0, initialValue: 0,
supportEvents: true, supportEvents: true,
supportBonjour: false, supportBonjour: false,
manfDescription: "Target Mode", manfDescription: "Target Mode",
designedMaxLength: 1, designedMaxLength: 1,
designedMinValue: 0, designedMinValue: 0,
designedMaxValue: 3, designedMaxValue: 3,
designedMinStep: 1, designedMinStep: 1,
onUpdate: function(value) { onUpdate: function(value) {
that.setTargetHeatingCooling(value); that.setTargetHeatingCooling(value);
}, },
onRead: function(callback) { onRead: function(callback) {
that.getCurrentHeatingCooling(callback); that.getCurrentHeatingCooling(callback);
} }
}); });
cTypes.push({ cTypes.push({
cType: types.CURRENT_TEMPERATURE_CTYPE, cType: types.CURRENT_TEMPERATURE_CTYPE,
perms: [Characteristic.Perms.READ,Characteristic.Perms.NOTIFY], perms: [Characteristic.Perms.READ,Characteristic.Perms.NOTIFY],
format: Characteristic.Formats.INT, format: Characteristic.Formats.INT,
designedMinValue: 0, designedMinValue: 0,
designedMaxValue: 110, designedMaxValue: 110,
@@ -446,11 +446,11 @@ IndigoAccessory.prototype = {
supportEvents: true, supportEvents: true,
supportBonjour: false, supportBonjour: false,
manfDescription: "Current Temperature", manfDescription: "Current Temperature",
unit: Characteristic.Units.FAHRENHEIT, unit: Characteristic.Units.FAHRENHEIT,
onUpdate: null, onUpdate: null,
onRead: function(callback) { onRead: function(callback) {
that.query("displayRawState", callback); that.query("displayRawState", callback);
} }
}); });
cTypes.push({ cTypes.push({
cType: types.TARGET_TEMPERATURE_CTYPE, cType: types.TARGET_TEMPERATURE_CTYPE,
@@ -463,12 +463,12 @@ IndigoAccessory.prototype = {
supportEvents: true, supportEvents: true,
supportBonjour: false, supportBonjour: false,
manfDescription: "Target Temperature", manfDescription: "Target Temperature",
unit: Characteristic.Units.FAHRENHEIT, unit: Characteristic.Units.FAHRENHEIT,
onUpdate: function(value) { onUpdate: function(value) {
that.setTargetTemperature(value); that.setTargetTemperature(value);
}, },
onRead: function(callback) { onRead: function(callback) {
that.getTargetTemperature(callback); that.getTargetTemperature(callback);
} }
}); });
cTypes.push({ cTypes.push({
@@ -479,9 +479,9 @@ IndigoAccessory.prototype = {
supportEvents: false, supportEvents: false,
supportBonjour: false, supportBonjour: false,
manfDescription: "Unit", manfDescription: "Unit",
onUpdate: null, onUpdate: null,
onRead: function(callback) { onRead: function(callback) {
callback(Characteristic.Units.FAHRENHEIT); callback(Characteristic.Units.FAHRENHEIT);
} }
}); });
} }
@@ -490,13 +490,13 @@ IndigoAccessory.prototype = {
}, },
sType: function() { sType: function() {
if (this.typeSupportsHVAC) { if (this.typeSupportsHVAC) {
return types.THERMOSTAT_STYPE; return types.THERMOSTAT_STYPE;
} else if (this.typeSupportsDim) { } else if (this.typeSupportsDim) {
return types.LIGHTBULB_STYPE; return types.LIGHTBULB_STYPE;
} else if (this.typeSupportsSpeedControl) { } else if (this.typeSupportsSpeedControl) {
return types.FAN_STYPE; return types.FAN_STYPE;
} else if (this.typeSupportsOnOff) { } else if (this.typeSupportsOnOff) {
return types.SWITCH_STYPE; return types.SWITCH_STYPE;
} }
@@ -504,7 +504,7 @@ IndigoAccessory.prototype = {
}, },
getServices: function() { getServices: function() {
var that = this; var that = this;
var services = [{ var services = [{
sType: types.ACCESSORY_INFORMATION_STYPE, sType: types.ACCESSORY_INFORMATION_STYPE,
characteristics: that.informationCharacteristics(), characteristics: that.informationCharacteristics(),