mirror of
https://github.com/mtan93/homebridge.git
synced 2026-05-19 14:18:54 +01:00
Merge pull request #50 from alistairg/master
Ability to specify a specific MyQDeviceId for the Liftmaster shim
This commit is contained in:
@@ -9,6 +9,7 @@ function LiftMasterAccessory(log, config) {
|
|||||||
this.name = config["name"];
|
this.name = config["name"];
|
||||||
this.username = config["username"];
|
this.username = config["username"];
|
||||||
this.password = config["password"];
|
this.password = config["password"];
|
||||||
|
this.requiredDeviceId = config["requiredDeviceId"];
|
||||||
}
|
}
|
||||||
|
|
||||||
LiftMasterAccessory.prototype = {
|
LiftMasterAccessory.prototype = {
|
||||||
@@ -82,20 +83,61 @@ LiftMasterAccessory.prototype = {
|
|||||||
// parse and interpret the response
|
// parse and interpret the response
|
||||||
var json = JSON.parse(body);
|
var json = JSON.parse(body);
|
||||||
var devices = json["Devices"];
|
var devices = json["Devices"];
|
||||||
|
var foundDoors = [];
|
||||||
|
|
||||||
// look through the array of devices for an opener
|
// look through the array of devices for an opener
|
||||||
for (var i=0; i<devices.length; i++) {
|
for (var i=0; i<devices.length; i++) {
|
||||||
var device = devices[i];
|
var device = devices[i];
|
||||||
|
|
||||||
if (device["MyQDeviceTypeName"] == "GarageDoorOpener") {
|
if (device["MyQDeviceTypeName"] == "GarageDoorOpener") {
|
||||||
that.deviceId = device.MyQDeviceId;
|
|
||||||
|
// If we haven't explicity specified a door ID, we'll loop to make sure we don't have multiple openers, which is confusing
|
||||||
|
if (that.requiredDeviceId == undefined) {
|
||||||
|
var thisDeviceId = device.MyQDeviceId;
|
||||||
|
var thisDoorName = "Unknown";
|
||||||
|
for (var j = 0; j < device.Attributes.length; j ++) {
|
||||||
|
var thisAttributeSet = device.Attributes[j];
|
||||||
|
if (thisAttributeSet.AttributeDisplayName == "desc") {
|
||||||
|
thisDoorName = thisAttributeSet.Value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
foundDoors.push(thisDeviceId + " - " + thisDoorName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// We specified a door ID, sanity check to make sure it's the one we expected
|
||||||
|
else if (that.requiredDeviceId == device.MyQDeviceId) {
|
||||||
|
that.deviceId = device.MyQDeviceId;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we have multiple found doors, refuse to proceed
|
||||||
|
if (foundDoors.length > 1) {
|
||||||
|
that.log("WARNING: You have multiple doors on your MyQ account.");
|
||||||
|
that.log("WARNING: Specify the ID of the door you want to control using the 'requiredDeviceId' property in your config.json file.");
|
||||||
|
that.log("WARNING: You can have multiple liftmaster accessories to cover your multiple doors");
|
||||||
|
|
||||||
|
for (var j = 0; j < foundDoors.length; j++) {
|
||||||
|
that.log("Found Door: " + foundDoors[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw "FATAL: Please specify which specific door this Liftmaster accessory should control - you have multiples on your account";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Did we get a device ID?
|
||||||
if (that.deviceId) {
|
if (that.deviceId) {
|
||||||
that.log("Found an opener with ID " + that.deviceId +". Ready to open.");
|
that.log("Found an opener with ID " + that.deviceId +". Ready to send command...");
|
||||||
that.setTargetState();
|
that.setTargetState();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
that.log("Error: Couldn't find a door device, or the ID you specified isn't associated with your account");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
that.log("Error '"+err+"' getting devices: " + body);
|
that.log("Error '"+err+"' getting devices: " + body);
|
||||||
@@ -145,6 +187,7 @@ LiftMasterAccessory.prototype = {
|
|||||||
that.log("State was successfully set.");
|
that.log("State was successfully set.");
|
||||||
else
|
else
|
||||||
that.log("Bad return code: " + json["ReturnCode"]);
|
that.log("Bad return code: " + json["ReturnCode"]);
|
||||||
|
that.log("Raw response " + JSON.stringify(json));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
that.log("Error '"+err+"' setting door state: " + JSON.stringify(json));
|
that.log("Error '"+err+"' setting door state: " + JSON.stringify(json));
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
"accessory": "LiftMaster",
|
"accessory": "LiftMaster",
|
||||||
"name": "Garage Door",
|
"name": "Garage Door",
|
||||||
"description": "This shim supports LiftMaster garage door openers that are already internet-connected to the 'MyQ' service.",
|
"description": "This shim supports LiftMaster garage door openers that are already internet-connected to the 'MyQ' service.",
|
||||||
|
// "requiredDeviceId", "<ID of door if you have multiple doors, prompted by shim during startup if needed>",
|
||||||
"username": "your-liftmaster-username",
|
"username": "your-liftmaster-username",
|
||||||
"password" : "your-liftmaster-password"
|
"password" : "your-liftmaster-password"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user