Add Carwings accessory shim

This commit is contained in:
Nick Farina
2014-11-30 22:44:44 -08:00
parent 1ff9f9e235
commit b4fe5421b8
6 changed files with 191 additions and 17 deletions

View File

@@ -3,9 +3,10 @@ var wemo = require('wemo');
function WeMoAccessory(log, config) {
this.log = log;
this.friendlyName = config["wemo_name"];
this.siriName = config["siri_name"];
this.wemoName = config["wemo_name"];
this.device = null;
this.log("Searching for WeMo device with exact name '" + this.friendlyName + "'...");
this.log("Searching for WeMo device with exact name '" + this.wemoName + "'...");
this.search();
}
@@ -14,8 +15,8 @@ WeMoAccessory.prototype = {
search: function() {
var that = this;
wemo.Search(this.friendlyName, function(err, device) {
that.log("Found '"+that.friendlyName+"' device at " + device.ip);
wemo.Search(this.wemoName, function(err, device) {
that.log("Found '"+that.wemoName+"' device at " + device.ip);
that.device = new wemo(device.ip, device.port);
});
},
@@ -23,21 +24,21 @@ WeMoAccessory.prototype = {
setPowerState: function(powerOn) {
if (!this.device) {
this.log("No '"+this.friendlyName+"' device found (yet?)");
this.log("No '"+this.wemoName+"' device found (yet?)");
return;
}
var binaryState = powerOn ? 1 : 0;
var that = this;
this.log("Setting power state on the '"+this.friendlyName+"' to " + binaryState);
this.log("Setting power state on the '"+this.wemoName+"' to " + binaryState);
this.device.setBinaryState(binaryState, function(err, result) {
if (!err) {
that.log("Successfully set power state on the '"+that.friendlyName+"' to " + binaryState);
that.log("Successfully set power state on the '"+that.wemoName+"' to " + binaryState);
}
else {
that.log("Error setting power state on the '"+that.friendlyName+"'")
that.log("Error setting power state on the '"+that.wemoName+"'")
}
});
},
@@ -52,7 +53,7 @@ WeMoAccessory.prototype = {
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: this.friendlyName,
initialValue: this.siriName,
supportEvents: false,
supportBonjour: false,
manfDescription: "Name of the accessory",
@@ -105,7 +106,7 @@ WeMoAccessory.prototype = {
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: this.friendlyName,
initialValue: this.siriName,
supportEvents: false,
supportBonjour: false,
manfDescription: "Name of service",