Skip to content

Commit 4332af6

Browse files
committed
Merge branch 'feature/ad2usb' into develop
2 parents a3e3408 + 9a69bf7 commit 4332af6

File tree

6 files changed

+393
-2
lines changed

6 files changed

+393
-2
lines changed

accessories/AD2USB.js

+245
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
var types = require("../lib/HAP-NodeJS/accessories/types.js");
2+
var AD2USB = require('ad2usb');
3+
var CUSTOM_PANEL_LCD_TEXT_CTYPE = "A3E7B8F9-216E-42C1-A21C-97D4E3BE52C8";
4+
5+
function AD2USBAccessory(log, config) {
6+
7+
this.log = log;
8+
this.name = config["name"];
9+
this.host = config["host"];
10+
this.port = config["port"];
11+
this.pin = config["pin"];
12+
var that = this;
13+
this.currentArmState = 2;
14+
this.currentStateCharacteristic = undefined;
15+
this.targetStateCharacteristic = undefined;
16+
this.lcdCharacteristic = undefined;
17+
18+
var alarm = AD2USB.connect(this.host, this.port, function() {
19+
20+
// Send an initial empty character to get status
21+
alarm.send('');
22+
23+
// Armed Away
24+
alarm.on('armedAway', function() {
25+
26+
that.log("Armed to AWAY");
27+
if (that.currentStateCharacteristic) {
28+
that.currentStateCharacteristic.updateValue(0, null);
29+
}
30+
if (that.targetStateCharacteristic) {
31+
that.targetStateCharacteristic.updateValue(1, null);
32+
}
33+
34+
});
35+
36+
// Armed Stay
37+
alarm.on('armedStay', function() {
38+
39+
that.log("Armed to STAY");
40+
if (that.currentStateCharacteristic) {
41+
that.currentStateCharacteristic.updateValue(0, null);
42+
}
43+
if (that.targetStateCharacteristic) {
44+
that.targetStateCharacteristic.updateValue(0, null);
45+
}
46+
47+
});
48+
49+
// Armed Night
50+
alarm.on('armedNight', function() {
51+
52+
that.log("Armed to NIGHT");
53+
if (that.currentStateCharacteristic) {
54+
that.currentStateCharacteristic.updateValue(0, null);
55+
}
56+
if (that.targetStateCharacteristic) {
57+
that.targetStateCharacteristic.updateValue(2, null);
58+
}
59+
60+
});
61+
62+
// Disarmed
63+
alarm.on('disarmed', function() {
64+
65+
that.log("Disarmed");
66+
if (that.currentStateCharacteristic) {
67+
that.currentStateCharacteristic.updateValue(1, null);
68+
}
69+
if (that.targetStateCharacteristic) {
70+
that.targetStateCharacteristic.updateValue(3, null);
71+
}
72+
73+
});
74+
75+
// Text Change
76+
alarm.on('lcdtext', function(newText) {
77+
78+
that.log("LCD: " + newText);
79+
if (that.lcdCharacteristic) {
80+
that.lcdCharacteristic.updateValue(newText, null);
81+
}
82+
83+
});
84+
85+
86+
});
87+
this.alarm = alarm;
88+
89+
}
90+
91+
AD2USBAccessory.prototype = {
92+
93+
setArmState: function(targetArmState) {
94+
95+
var that = this;
96+
that.log("Desired target arm state: " + targetArmState);
97+
98+
// TARGET
99+
// 0 - Stay
100+
// 1 - Away
101+
// 2 - Night
102+
// 3 - Disarm
103+
if (targetArmState == 0) {
104+
that.alarm.armStay(that.pin);
105+
}
106+
else if (targetArmState == 1) {
107+
that.alarm.armAway(that.pin);
108+
}
109+
else if (targetArmState == 2) {
110+
that.alarm.armNight(that.pin);
111+
}
112+
else if (targetArmState == 3) {
113+
that.alarm.disarm(that.pin);
114+
}
115+
116+
117+
// CURRENT
118+
// 0 - Armed
119+
// 1 - Disarmed
120+
// 2 - Hold
121+
122+
},
123+
124+
getServices: function() {
125+
var that = this;
126+
return [{
127+
sType: types.ACCESSORY_INFORMATION_STYPE,
128+
characteristics: [{
129+
cType: types.NAME_CTYPE,
130+
onUpdate: null,
131+
perms: ["pr"],
132+
format: "string",
133+
initialValue: this.name,
134+
supportEvents: false,
135+
supportBonjour: false,
136+
manfDescription: "Name of the accessory",
137+
designedMaxLength: 255
138+
},{
139+
cType: types.MANUFACTURER_CTYPE,
140+
onUpdate: null,
141+
perms: ["pr"],
142+
format: "string",
143+
initialValue: "Nutech",
144+
supportEvents: false,
145+
supportBonjour: false,
146+
manfDescription: "Manufacturer",
147+
designedMaxLength: 255
148+
},{
149+
cType: types.MODEL_CTYPE,
150+
onUpdate: null,
151+
perms: ["pr"],
152+
format: "string",
153+
initialValue: "AD2USB",
154+
supportEvents: false,
155+
supportBonjour: false,
156+
manfDescription: "Model",
157+
designedMaxLength: 255
158+
},{
159+
cType: types.SERIAL_NUMBER_CTYPE,
160+
onUpdate: null,
161+
perms: ["pr"],
162+
format: "string",
163+
initialValue: "AD2USBIF",
164+
supportEvents: false,
165+
supportBonjour: false,
166+
manfDescription: "SN",
167+
designedMaxLength: 255
168+
},{
169+
cType: types.IDENTIFY_CTYPE,
170+
onUpdate: null,
171+
perms: ["pw"],
172+
format: "bool",
173+
initialValue: false,
174+
supportEvents: false,
175+
supportBonjour: false,
176+
manfDescription: "Identify Accessory",
177+
designedMaxLength: 1
178+
}]
179+
},{
180+
sType: types.ALARM_STYPE,
181+
characteristics: [{
182+
cType: types.NAME_CTYPE,
183+
onUpdate: null,
184+
perms: ["pr"],
185+
format: "string",
186+
initialValue: this.name,
187+
supportEvents: false,
188+
supportBonjour: false,
189+
manfDescription: "Name of service",
190+
designedMaxLength: 255
191+
},{
192+
cType: types.ALARM_CURRENT_STATE_CTYPE,
193+
onUpdate: null,
194+
onRegister: function(characteristic) {
195+
196+
that.currentStateCharacteristic = characteristic;
197+
characteristic.eventEnabled = true;
198+
199+
},
200+
perms: ["pr","ev"],
201+
format: "int",
202+
initialValue: 2,
203+
supportEvents: true,
204+
supportBonjour: false,
205+
manfDescription: "Alarm current arm state",
206+
designedMaxLength: 1
207+
},{
208+
cType: types.ALARM_TARGET_STATE_CTYPE,
209+
onUpdate: function(value) { that.setArmState(value); },
210+
onRegister: function(characteristic) {
211+
212+
that.targetStateCharacteristic = characteristic;
213+
characteristic.eventEnabled = true;
214+
215+
},
216+
perms: ["pw","pr","ev"],
217+
format: "int",
218+
initialValue: 1,
219+
supportEvents: true,
220+
supportBonjour: false,
221+
manfDescription: "Alarm target arm state",
222+
designedMaxLength: 1
223+
},
224+
{
225+
cType: CUSTOM_PANEL_LCD_TEXT_CTYPE,
226+
onUpdate: null,
227+
onRegister: function(characteristic) {
228+
229+
that.lcdCharacteristic = characteristic;
230+
characteristic.eventEnabled = true;
231+
232+
},
233+
perms: ["pr","ev"],
234+
format: "string",
235+
initialValue: "Unknown",
236+
supportEvents: false,
237+
supportBonjour: false,
238+
manfDescription: "Keypad Text",
239+
designedMaxLength: 64
240+
}]
241+
}];
242+
}
243+
};
244+
245+
module.exports.accessory = AD2USBAccessory;

accessories/ELKM1.js

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
var types = require("../lib/HAP-NodeJS/accessories/types.js");
2+
var elkington = require("elkington");
3+
4+
function ElkM1Accessory(log, config) {
5+
this.log = log;
6+
this.name = config["name"];
7+
this.zone = config["zone"];
8+
this.host = config["host"];
9+
this.port = config["port"];
10+
this.pin = config["pin"];
11+
this.arm = config["arm"];
12+
}
13+
14+
ElkM1Accessory.prototype = {
15+
setPowerState: function(alarmOn) {
16+
var that = this;
17+
18+
if (!alarmOn)
19+
{
20+
return;
21+
}
22+
23+
var elk = elkington.createConnection({
24+
port: that.port,
25+
host: that.host,
26+
});
27+
28+
switch (that.arm)
29+
{
30+
case 'Away':
31+
elk.armAway({area: that.zone, code: that.pin});
32+
break;
33+
case 'Stay':
34+
elk.armStay({area: that.zone, code: that.pin});
35+
break;
36+
case 'Night':
37+
elk.armNightInstant({area: that.zone, code: that.pin});
38+
break;
39+
default:
40+
break;
41+
}
42+
},
43+
44+
getServices: function() {
45+
var that = this;
46+
return [{
47+
sType: types.ACCESSORY_INFORMATION_STYPE,
48+
characteristics: [{
49+
cType: types.NAME_CTYPE,
50+
onUpdate: null,
51+
perms: ["pr"],
52+
format: "string",
53+
initialValue: this.name,
54+
supportEvents: false,
55+
supportBonjour: false,
56+
manfDescription: "Name of the accessory",
57+
designedMaxLength: 255
58+
},{
59+
cType: types.MANUFACTURER_CTYPE,
60+
onUpdate: null,
61+
perms: ["pr"],
62+
format: "string",
63+
initialValue: "Elk",
64+
supportEvents: false,
65+
supportBonjour: false,
66+
manfDescription: "Manufacturer",
67+
designedMaxLength: 255
68+
},{
69+
cType: types.MODEL_CTYPE,
70+
onUpdate: null,
71+
perms: ["pr"],
72+
format: "string",
73+
initialValue: "M1",
74+
supportEvents: false,
75+
supportBonjour: false,
76+
manfDescription: "Model",
77+
designedMaxLength: 255
78+
},{
79+
cType: types.SERIAL_NUMBER_CTYPE,
80+
onUpdate: null,
81+
perms: ["pr"],
82+
format: "string",
83+
initialValue: "A1S2NASF88EW",
84+
supportEvents: false,
85+
supportBonjour: false,
86+
manfDescription: "SN",
87+
designedMaxLength: 255
88+
},{
89+
cType: types.IDENTIFY_CTYPE,
90+
onUpdate: null,
91+
perms: ["pw"],
92+
format: "bool",
93+
initialValue: false,
94+
supportEvents: false,
95+
supportBonjour: false,
96+
manfDescription: "Identify Accessory",
97+
designedMaxLength: 1
98+
}]
99+
},{
100+
sType: types.SWITCH_STYPE,
101+
characteristics: [{
102+
cType: types.NAME_CTYPE,
103+
onUpdate: null,
104+
perms: ["pr"],
105+
format: "string",
106+
initialValue: this.name,
107+
supportEvents: false,
108+
supportBonjour: false,
109+
manfDescription: "Name of service",
110+
designedMaxLength: 255
111+
},{
112+
cType: types.POWER_STATE_CTYPE,
113+
onUpdate: function(value) { that.setPowerState(value); },
114+
perms: ["pw","pr","ev"],
115+
format: "bool",
116+
initialValue: false,
117+
supportEvents: false,
118+
supportBonjour: false,
119+
manfDescription: "Alarm the Zone",
120+
designedMaxLength: 1
121+
}]
122+
}];
123+
}
124+
};
125+
126+
module.exports.accessory = ElkM1Accessory;

app.js

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ function createHAPServer(name, services) {
124124
for (var k = 0; k < services[j].characteristics.length; k++) {
125125
var options = {
126126
onRead: services[j].characteristics[k].onRead,
127+
onRegister: services[j].characteristics[k].onRegister,
127128
type: services[j].characteristics[k].cType,
128129
perms: services[j].characteristics[k].perms,
129130
format: services[j].characteristics[k].format,

0 commit comments

Comments
 (0)