Merge branch 'master' into feature/ad2usb

This commit is contained in:
Alistair Galbraith
2015-07-01 15:12:20 -07:00
4 changed files with 182 additions and 4 deletions

126
accessories/ELKM1.js Normal file
View File

@@ -0,0 +1,126 @@
var types = require("../lib/HAP-NodeJS/accessories/types.js");
var elkington = require("elkington");
function ElkM1Accessory(log, config) {
this.log = log;
this.name = config["name"];
this.zone = config["zone"];
this.host = config["host"];
this.port = config["port"];
this.pin = config["pin"];
this.arm = config["arm"];
}
ElkM1Accessory.prototype = {
setPowerState: function(alarmOn) {
var that = this;
if (!alarmOn)
{
return;
}
var elk = elkington.createConnection({
port: that.port,
host: that.host,
});
switch (that.arm)
{
case 'Away':
elk.armAway({area: that.zone, code: that.pin});
break;
case 'Stay':
elk.armStay({area: that.zone, code: that.pin});
break;
case 'Night':
elk.armNightInstant({area: that.zone, code: that.pin});
break;
default:
break;
}
},
getServices: function() {
var that = this;
return [{
sType: types.ACCESSORY_INFORMATION_STYPE,
characteristics: [{
cType: types.NAME_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: this.name,
supportEvents: false,
supportBonjour: false,
manfDescription: "Name of the accessory",
designedMaxLength: 255
},{
cType: types.MANUFACTURER_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "Elk",
supportEvents: false,
supportBonjour: false,
manfDescription: "Manufacturer",
designedMaxLength: 255
},{
cType: types.MODEL_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "M1",
supportEvents: false,
supportBonjour: false,
manfDescription: "Model",
designedMaxLength: 255
},{
cType: types.SERIAL_NUMBER_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: "A1S2NASF88EW",
supportEvents: false,
supportBonjour: false,
manfDescription: "SN",
designedMaxLength: 255
},{
cType: types.IDENTIFY_CTYPE,
onUpdate: null,
perms: ["pw"],
format: "bool",
initialValue: false,
supportEvents: false,
supportBonjour: false,
manfDescription: "Identify Accessory",
designedMaxLength: 1
}]
},{
sType: types.SWITCH_STYPE,
characteristics: [{
cType: types.NAME_CTYPE,
onUpdate: null,
perms: ["pr"],
format: "string",
initialValue: this.name,
supportEvents: false,
supportBonjour: false,
manfDescription: "Name of service",
designedMaxLength: 255
},{
cType: types.POWER_STATE_CTYPE,
onUpdate: function(value) { that.setPowerState(value); },
perms: ["pw","pr","ev"],
format: "bool",
initialValue: false,
supportEvents: false,
supportBonjour: false,
manfDescription: "Alarm the Zone",
designedMaxLength: 1
}]
}];
}
};
module.exports.accessory = ElkM1Accessory;

View File

@@ -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);

View File

@@ -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"
},
@@ -102,6 +103,15 @@
"off_url": "https://192.168.1.22:3030/devices/23222/off",
"brightness_url": "https://192.168.1.22:3030/devices/23222/brightness/%b",
"http_method": "POST"
},{
"accessory": "ELKM1",
"name": "Security System",
"description": "Allows basic control of Elk M1 security system. You can use 1 of 3 arm modes: Away, Stay, Night. If you need to access all 3, create 3 accessories with different names.",
"zone": "1",
"host": "192.168.1.10",
"port": "2101",
"pin": "1234",
"arm": "Away"
}
]
}

View File

@@ -19,6 +19,7 @@
"carwingsjs": "0.0.x",
"sonos": "0.8.x",
"wemo": "0.2.x",
"wink-js": "0.0.5"
"wink-js": "0.0.5",
"elkington": "kevinohara80/elkington"
}
}