From f28e9493dfd3e282b683652f9098e6051cbacbca Mon Sep 17 00:00:00 2001 From: Ray Bennett Date: Mon, 29 Jun 2015 17:48:40 -0700 Subject: [PATCH] Adding support for arming Elk M1 security system. --- accessories/ELKM1.js | 126 +++++++++++++++++++++++++++++++++++++++++++ config-sample.json | 9 ++++ package.json | 3 +- 3 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 accessories/ELKM1.js diff --git a/accessories/ELKM1.js b/accessories/ELKM1.js new file mode 100644 index 0000000..7ac2ba3 --- /dev/null +++ b/accessories/ELKM1.js @@ -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; diff --git a/config-sample.json b/config-sample.json index e8e4b96..639ccb1 100644 --- a/config-sample.json +++ b/config-sample.json @@ -102,6 +102,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" } ] } diff --git a/package.json b/package.json index c12ab9f..822badd 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,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" } }