Merge pull request #320 from fcarucci/master

LiftMaster: return garage door state
This commit is contained in:
Nick Farina
2015-11-03 10:25:41 -08:00

View File

@@ -16,9 +16,17 @@ LiftMasterAccessory.prototype = {
setState: function(state) { setState: function(state) {
this.targetState = state; this.targetState = state;
this.callback = undefined;
this.login(); this.login();
}, },
getState: function(callback) {
this.targetState = undefined;
this.callback = callback;
this.login();
return true;
},
login: function() { login: function() {
var that = this; var that = this;
@@ -95,15 +103,21 @@ LiftMasterAccessory.prototype = {
if (!that.requiredDeviceId) { if (!that.requiredDeviceId) {
var thisDeviceId = device.MyQDeviceId; var thisDeviceId = device.MyQDeviceId;
var thisDoorName = "Unknown"; var thisDoorName = "Unknown";
var thisDoorState = 2;
for (var j = 0; j < device.Attributes.length; j ++) { for (var j = 0; j < device.Attributes.length; j ++) {
var thisAttributeSet = device.Attributes[j]; var thisAttributeSet = device.Attributes[j];
if (thisAttributeSet.AttributeDisplayName == "desc") { if (thisAttributeSet.AttributeDisplayName == "desc") {
thisDoorName = thisAttributeSet.Value; thisDoorName = thisAttributeSet.Value;
break; break;
} }
if (thisAttributeSet.AttributeDisplayName == "doorstate") {
thisDoorState = thisAttributeSet.Value;
}
} }
foundDoors.push(thisDeviceId + " - " + thisDoorName); foundDoors.push(thisDeviceId + " - " + thisDoorName);
that.deviceId = thisDeviceId; that.deviceId = thisDeviceId;
that.deviceState = thisDoorState;
} }
// We specified a door ID, sanity check to make sure it's the one we expected // We specified a door ID, sanity check to make sure it's the one we expected
@@ -111,9 +125,7 @@ LiftMasterAccessory.prototype = {
that.deviceId = device.MyQDeviceId; that.deviceId = device.MyQDeviceId;
break; break;
} }
} }
} }
// If we have multiple found doors, refuse to proceed // If we have multiple found doors, refuse to proceed
@@ -132,8 +144,14 @@ LiftMasterAccessory.prototype = {
// Did we get a device ID? // Did we get a device ID?
if (that.deviceId) { if (that.deviceId) {
that.log("Found an opener with ID " + that.deviceId +". Ready to send command..."); if (that.targetState != undefined) {
that.setTargetState(); that.log("Found an opener with ID " + that.deviceId +". Ready to send command...");
that.setTargetState();
}
if (that.callback != undefined) {
that.log("Found an opener with ID " + that.deviceId + " [doorstate: " + that.deviceState + "]");
that.getCurrentState(that.callback);
}
} }
else else
{ {
@@ -146,6 +164,11 @@ LiftMasterAccessory.prototype = {
}); });
}, },
getCurrentState: function(callback) {
this.log("Getting current state: " + this.deviceState);
callback(this.deviceState == 2);
},
setTargetState: function() { setTargetState: function() {
var that = this; var that = this;
@@ -181,7 +204,6 @@ LiftMasterAccessory.prototype = {
body: body, body: body,
json: true json: true
}, function(err, response, json) { }, function(err, response, json) {
if (!err && response.statusCode == 200) { if (!err && response.statusCode == 200) {
if (json["ReturnCode"] == "0") if (json["ReturnCode"] == "0")
@@ -258,7 +280,7 @@ LiftMasterAccessory.prototype = {
onUpdate: null, onUpdate: null,
perms: ["pr"], perms: ["pr"],
format: "string", format: "string",
initialValue: "Garage Door Opener Control", initialValue: "Garage Door",
supportEvents: false, supportEvents: false,
supportBonjour: false, supportBonjour: false,
manfDescription: "Name of service", manfDescription: "Name of service",
@@ -266,6 +288,7 @@ LiftMasterAccessory.prototype = {
},{ },{
cType: types.CURRENT_DOOR_STATE_CTYPE, cType: types.CURRENT_DOOR_STATE_CTYPE,
onUpdate: function(value) { that.log("Update current state to " + value); }, onUpdate: function(value) { that.log("Update current state to " + value); },
onRead: function(callback) { that.getState(callback); },
perms: ["pr","ev"], perms: ["pr","ev"],
format: "int", format: "int",
initialValue: 0, initialValue: 0,
@@ -281,7 +304,7 @@ LiftMasterAccessory.prototype = {
onUpdate: function(value) { that.setState(value); }, onUpdate: function(value) { that.setState(value); },
perms: ["pr","pw","ev"], perms: ["pr","pw","ev"],
format: "int", format: "int",
initialValue: 0, initialValue: 1,
supportEvents: false, supportEvents: false,
supportBonjour: false, supportBonjour: false,
manfDescription: "BlaBla", manfDescription: "BlaBla",