mirror of
https://github.com/mtan93/homebridge.git
synced 2026-03-08 05:31:55 +00:00
A MyQ account with multiple opener devices will trigger a fatal exception, after dumping out possible doors and their names
Also updated config-sample.json with additional option, and comments
This commit is contained in:
@@ -83,20 +83,61 @@ LiftMasterAccessory.prototype = {
|
||||
// parse and interpret the response
|
||||
var json = JSON.parse(body);
|
||||
var devices = json["Devices"];
|
||||
var foundDoors = [];
|
||||
|
||||
// look through the array of devices for an opener
|
||||
for (var i=0; i<devices.length; i++) {
|
||||
var device = devices[i];
|
||||
if ((device["MyQDeviceTypeName"] == "GarageDoorOpener") && ((that.requiredDeviceId == undefined) || (that.requiredDeviceId == device.MyQDeviceId))) {
|
||||
that.deviceId = device.MyQDeviceId;
|
||||
break;
|
||||
|
||||
if (device["MyQDeviceTypeName"] == "GarageDoorOpener") {
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
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) {
|
||||
that.log("Found an opener with ID " + that.deviceId +". Ready to send command...");
|
||||
that.setTargetState();
|
||||
}
|
||||
else
|
||||
{
|
||||
that.log("Error: Couldn't find a door device, or the ID you specified isn't associated with your account");
|
||||
}
|
||||
}
|
||||
else {
|
||||
that.log("Error '"+err+"' getting devices: " + body);
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
"accessory": "LiftMaster",
|
||||
"name": "Garage Door",
|
||||
"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",
|
||||
"password" : "your-liftmaster-password"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user