node-alarm-dot-com 1.11.0 → 2.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_models/AuthOpts.d.ts +3 -0
- package/dist/_models/DeviceStates.d.ts +6 -1
- package/dist/_models/IdentityResponse.d.ts +4 -0
- package/dist/_models/PartitionActionOptions.d.ts +3 -0
- package/dist/_models/SensorType.d.ts +13 -0
- package/dist/_models/SensorType.js +17 -0
- package/dist/_models/States.d.ts +19 -0
- package/dist/_models/States.js +19 -0
- package/dist/_models/SystemState.d.ts +4 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +38 -9
- package/package.json +10 -8
@@ -1,6 +1,7 @@
|
|
1
1
|
import { Relationship } from './IdentityResponse';
|
2
2
|
import { RelationshipType } from './SystemState';
|
3
3
|
import { GARAGE_STATES, LIGHT_STATES, LOCK_STATES, SENSOR_STATES, SYSTEM_STATES } from './States';
|
4
|
+
import { SensorType } from './SensorType';
|
4
5
|
export interface ApiLightState extends ApiDeviceState {
|
5
6
|
data: {
|
6
7
|
id: string;
|
@@ -513,7 +514,7 @@ export interface SensorState extends DeviceState {
|
|
513
514
|
id: string;
|
514
515
|
type: RelationshipType.Sensor;
|
515
516
|
attributes: {
|
516
|
-
deviceType:
|
517
|
+
deviceType: SensorType;
|
517
518
|
openClosedStatus: number;
|
518
519
|
state: SENSOR_STATES;
|
519
520
|
stateText: string;
|
@@ -751,6 +752,10 @@ export interface CameraState extends DeviceState {
|
|
751
752
|
};
|
752
753
|
};
|
753
754
|
}
|
755
|
+
/**
|
756
|
+
* Base interface for retrieving device state from Alarm.com's API
|
757
|
+
* All devices retrieved contain these properties.
|
758
|
+
*/
|
754
759
|
export interface ApiDeviceState {
|
755
760
|
data: {
|
756
761
|
id: string;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/**
|
2
|
+
* Number indicating the type of sensor according to the Alarm.com API
|
3
|
+
*/
|
4
|
+
export declare enum SensorType {
|
5
|
+
Contact_Sensor = 1,
|
6
|
+
Motion_Sensor = 2,
|
7
|
+
Smoke_Detector = 5,
|
8
|
+
CO_Detector = 6,
|
9
|
+
Heat_Detector = 8,
|
10
|
+
Fob = 9,
|
11
|
+
Water_Sensor = 17,
|
12
|
+
Glass_Break = 19
|
13
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.SensorType = void 0;
|
4
|
+
/**
|
5
|
+
* Number indicating the type of sensor according to the Alarm.com API
|
6
|
+
*/
|
7
|
+
var SensorType;
|
8
|
+
(function (SensorType) {
|
9
|
+
SensorType[SensorType["Contact_Sensor"] = 1] = "Contact_Sensor";
|
10
|
+
SensorType[SensorType["Motion_Sensor"] = 2] = "Motion_Sensor";
|
11
|
+
SensorType[SensorType["Smoke_Detector"] = 5] = "Smoke_Detector";
|
12
|
+
SensorType[SensorType["CO_Detector"] = 6] = "CO_Detector";
|
13
|
+
SensorType[SensorType["Heat_Detector"] = 8] = "Heat_Detector";
|
14
|
+
SensorType[SensorType["Fob"] = 9] = "Fob";
|
15
|
+
SensorType[SensorType["Water_Sensor"] = 17] = "Water_Sensor";
|
16
|
+
SensorType[SensorType["Glass_Break"] = 19] = "Glass_Break";
|
17
|
+
})(SensorType = exports.SensorType || (exports.SensorType = {}));
|
package/dist/_models/States.d.ts
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
/***
|
2
|
+
* State of the partition as defined by Alarm.com
|
3
|
+
*/
|
1
4
|
export declare enum SYSTEM_STATES {
|
2
5
|
UNKNOWN = 0,
|
3
6
|
DISARMED = 1,
|
@@ -5,6 +8,9 @@ export declare enum SYSTEM_STATES {
|
|
5
8
|
ARMED_AWAY = 3,
|
6
9
|
ARMED_NIGHT = 4
|
7
10
|
}
|
11
|
+
/***
|
12
|
+
* State of the sensor as defined by Alarm.com
|
13
|
+
*/
|
8
14
|
export declare enum SENSOR_STATES {
|
9
15
|
UNKNOWN = 0,
|
10
16
|
CLOSED = 1,
|
@@ -14,18 +20,31 @@ export declare enum SENSOR_STATES {
|
|
14
20
|
DRY = 5,
|
15
21
|
WET = 6
|
16
22
|
}
|
23
|
+
/***
|
24
|
+
* State of the light as defined by Alarm.com
|
25
|
+
*/
|
17
26
|
export declare enum LIGHT_STATES {
|
18
27
|
ON = 2,
|
19
28
|
OFF = 3
|
20
29
|
}
|
30
|
+
/***
|
31
|
+
* State of the lock as defined by Alarm.com
|
32
|
+
*/
|
21
33
|
export declare enum LOCK_STATES {
|
22
34
|
SECURED = 1,
|
23
35
|
UNSECURED = 2
|
24
36
|
}
|
37
|
+
/***
|
38
|
+
* State of the garage as defined by Alarm.com
|
39
|
+
*/
|
25
40
|
export declare enum GARAGE_STATES {
|
26
41
|
OPEN = 1,
|
27
42
|
CLOSED = 2
|
28
43
|
}
|
44
|
+
/***
|
45
|
+
* Relation types as defined by Alarm.com.
|
46
|
+
* Relationship types tell you what object is being sent from the API.
|
47
|
+
*/
|
29
48
|
export declare enum REL_TYPES {
|
30
49
|
CONFIGURATION = "systems/configuration",
|
31
50
|
PARTITION = "devices/partition",
|
package/dist/_models/States.js
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.REL_TYPES = exports.GARAGE_STATES = exports.LOCK_STATES = exports.LIGHT_STATES = exports.SENSOR_STATES = exports.SYSTEM_STATES = void 0;
|
4
|
+
/***
|
5
|
+
* State of the partition as defined by Alarm.com
|
6
|
+
*/
|
4
7
|
var SYSTEM_STATES;
|
5
8
|
(function (SYSTEM_STATES) {
|
6
9
|
SYSTEM_STATES[SYSTEM_STATES["UNKNOWN"] = 0] = "UNKNOWN";
|
@@ -9,6 +12,9 @@ var SYSTEM_STATES;
|
|
9
12
|
SYSTEM_STATES[SYSTEM_STATES["ARMED_AWAY"] = 3] = "ARMED_AWAY";
|
10
13
|
SYSTEM_STATES[SYSTEM_STATES["ARMED_NIGHT"] = 4] = "ARMED_NIGHT";
|
11
14
|
})(SYSTEM_STATES = exports.SYSTEM_STATES || (exports.SYSTEM_STATES = {}));
|
15
|
+
/***
|
16
|
+
* State of the sensor as defined by Alarm.com
|
17
|
+
*/
|
12
18
|
var SENSOR_STATES;
|
13
19
|
(function (SENSOR_STATES) {
|
14
20
|
SENSOR_STATES[SENSOR_STATES["UNKNOWN"] = 0] = "UNKNOWN";
|
@@ -19,22 +25,35 @@ var SENSOR_STATES;
|
|
19
25
|
SENSOR_STATES[SENSOR_STATES["DRY"] = 5] = "DRY";
|
20
26
|
SENSOR_STATES[SENSOR_STATES["WET"] = 6] = "WET";
|
21
27
|
})(SENSOR_STATES = exports.SENSOR_STATES || (exports.SENSOR_STATES = {}));
|
28
|
+
/***
|
29
|
+
* State of the light as defined by Alarm.com
|
30
|
+
*/
|
22
31
|
var LIGHT_STATES;
|
23
32
|
(function (LIGHT_STATES) {
|
24
33
|
LIGHT_STATES[LIGHT_STATES["ON"] = 2] = "ON";
|
25
34
|
LIGHT_STATES[LIGHT_STATES["OFF"] = 3] = "OFF";
|
26
35
|
})(LIGHT_STATES = exports.LIGHT_STATES || (exports.LIGHT_STATES = {}));
|
36
|
+
/***
|
37
|
+
* State of the lock as defined by Alarm.com
|
38
|
+
*/
|
27
39
|
var LOCK_STATES;
|
28
40
|
(function (LOCK_STATES) {
|
29
41
|
LOCK_STATES[LOCK_STATES["SECURED"] = 1] = "SECURED";
|
30
42
|
LOCK_STATES[LOCK_STATES["UNSECURED"] = 2] = "UNSECURED";
|
31
43
|
})(LOCK_STATES = exports.LOCK_STATES || (exports.LOCK_STATES = {}));
|
44
|
+
/***
|
45
|
+
* State of the garage as defined by Alarm.com
|
46
|
+
*/
|
32
47
|
var GARAGE_STATES;
|
33
48
|
(function (GARAGE_STATES) {
|
34
49
|
//UNKNOWN: 0, //ADC does not have an unknown state. ADC returns temp popup
|
35
50
|
GARAGE_STATES[GARAGE_STATES["OPEN"] = 1] = "OPEN";
|
36
51
|
GARAGE_STATES[GARAGE_STATES["CLOSED"] = 2] = "CLOSED"; //double check
|
37
52
|
})(GARAGE_STATES = exports.GARAGE_STATES || (exports.GARAGE_STATES = {}));
|
53
|
+
/***
|
54
|
+
* Relation types as defined by Alarm.com.
|
55
|
+
* Relationship types tell you what object is being sent from the API.
|
56
|
+
*/
|
38
57
|
var REL_TYPES;
|
39
58
|
(function (REL_TYPES) {
|
40
59
|
REL_TYPES["CONFIGURATION"] = "systems/configuration";
|
package/dist/index.d.ts
CHANGED
@@ -11,6 +11,7 @@ export * from './_models/IdentityResponse';
|
|
11
11
|
export * from './_models/PartitionActionOptions';
|
12
12
|
export * from './_models/RequestOptions';
|
13
13
|
export * from './_models/SystemState';
|
14
|
+
export * from './_models/SensorType';
|
14
15
|
/**
|
15
16
|
* Authenticate with alarm.com.
|
16
17
|
* Returns an authentication object that can be passed to other methods.
|
@@ -86,9 +87,10 @@ export declare function disarm(partitionID: string, authOpts: AuthOpts): Promise
|
|
86
87
|
* @param {string} lightID Light ID string.
|
87
88
|
* @param {number} brightness An integer, 1-100, indicating brightness.
|
88
89
|
* @param {Object} authOpts Authentication object returned from the login.
|
90
|
+
* @param {boolean} isDimmer Indicates whether or not light is dimmable.
|
89
91
|
* @returns {Promise}
|
90
92
|
*/
|
91
|
-
export declare function setLightOn(lightID: string, authOpts: AuthOpts, brightness: number): Promise<any>;
|
93
|
+
export declare function setLightOn(lightID: string, authOpts: AuthOpts, brightness: number, isDimmer: boolean): Promise<any>;
|
92
94
|
/**
|
93
95
|
* Convenience Method:
|
94
96
|
* Sets a light to OFF. The brightness level is ignored.
|
@@ -96,9 +98,10 @@ export declare function setLightOn(lightID: string, authOpts: AuthOpts, brightne
|
|
96
98
|
* @param {string} lightID Light ID string.
|
97
99
|
* @param {number} brightness An integer, 1-100, indicating brightness. Ignored.
|
98
100
|
* @param {Object} authOpts Authentication object returned from the login.
|
101
|
+
* @param {boolean} isDimmer Indicates whether or not light is dimmable.
|
99
102
|
* @returns {Promise}
|
100
103
|
*/
|
101
|
-
export declare function setLightOff(lightID: string, authOpts: AuthOpts, brightness: number): Promise<any>;
|
104
|
+
export declare function setLightOff(lightID: string, authOpts: AuthOpts, brightness: number, isDimmer: boolean): Promise<any>;
|
102
105
|
/**
|
103
106
|
* Convenience Method:
|
104
107
|
* Sets a lock to "locked" (SECURED).
|
package/dist/index.js
CHANGED
@@ -24,6 +24,7 @@ __exportStar(require("./_models/IdentityResponse"), exports);
|
|
24
24
|
__exportStar(require("./_models/PartitionActionOptions"), exports);
|
25
25
|
__exportStar(require("./_models/RequestOptions"), exports);
|
26
26
|
__exportStar(require("./_models/SystemState"), exports);
|
27
|
+
__exportStar(require("./_models/SensorType"), exports);
|
27
28
|
const ADCLOGIN_URL = 'https://www.alarm.com/login';
|
28
29
|
const ADCFORMLOGIN_URL = 'https://www.alarm.com/web/Default.aspx';
|
29
30
|
const IDENTITIES_URL = 'https://www.alarm.com/web/api/identities';
|
@@ -71,7 +72,7 @@ async function login(username, password, existingMfaToken) {
|
|
71
72
|
.catch(err => {
|
72
73
|
throw new Error(`GET ${ADCLOGIN_URL} failed: ${err.message || err}`);
|
73
74
|
});
|
74
|
-
await node_fetch_1.default(ADCFORMLOGIN_URL, {
|
75
|
+
await (0, node_fetch_1.default)(ADCFORMLOGIN_URL, {
|
75
76
|
method: 'POST',
|
76
77
|
headers: {
|
77
78
|
'Content-Type': 'application/x-www-form-urlencoded',
|
@@ -262,14 +263,30 @@ exports.disarm = disarm;
|
|
262
263
|
// about any of the components, sensors included.
|
263
264
|
// Light methods ///////////////////////////////////////////////////////////////
|
264
265
|
/**
|
265
|
-
* Perform light actions, e.
|
266
|
+
* Perform non-dimmable light actions, i.e. turn on, turn off
|
267
|
+
*
|
268
|
+
* @param {string} lightID Light ID string.
|
269
|
+
* @param {string} action Action (verb) to perform on the light.
|
270
|
+
* @param {Object} authOpts Authentication object returned from the login.
|
271
|
+
*/
|
272
|
+
function lightAction(lightID, authOpts, action) {
|
273
|
+
const url = `${LIGHTS_URL}${lightID}/${action}`;
|
274
|
+
const postOpts = Object.assign({}, authOpts, {
|
275
|
+
body: {
|
276
|
+
statePollOnly: false
|
277
|
+
}
|
278
|
+
});
|
279
|
+
return authenticatedPost(url, postOpts);
|
280
|
+
}
|
281
|
+
/**
|
282
|
+
* Perform dimmable light actions, e.g., turn on, turn off, change brightness level.
|
266
283
|
*
|
267
284
|
* @param {string} lightID Light ID string.
|
268
285
|
* @param {string} action Action (verb) to perform on the light.
|
269
286
|
* @param {Object} authOpts Authentication object returned from the login.
|
270
287
|
* @param {number} brightness An integer, 1-100, indicating brightness.
|
271
288
|
*/
|
272
|
-
function
|
289
|
+
function dimmerAction(lightID, authOpts, brightness, action) {
|
273
290
|
const url = `${LIGHTS_URL}${lightID}/${action}`;
|
274
291
|
const postOpts = Object.assign({}, authOpts, {
|
275
292
|
body: {
|
@@ -286,10 +303,16 @@ function lightAction(lightID, authOpts, brightness, action) {
|
|
286
303
|
* @param {string} lightID Light ID string.
|
287
304
|
* @param {number} brightness An integer, 1-100, indicating brightness.
|
288
305
|
* @param {Object} authOpts Authentication object returned from the login.
|
306
|
+
* @param {boolean} isDimmer Indicates whether or not light is dimmable.
|
289
307
|
* @returns {Promise}
|
290
308
|
*/
|
291
|
-
function setLightOn(lightID, authOpts, brightness) {
|
292
|
-
|
309
|
+
function setLightOn(lightID, authOpts, brightness, isDimmer) {
|
310
|
+
if (isDimmer) {
|
311
|
+
return dimmerAction(lightID, authOpts, brightness, 'turnOn');
|
312
|
+
}
|
313
|
+
else {
|
314
|
+
return lightAction(lightID, authOpts, 'turnOn');
|
315
|
+
}
|
293
316
|
}
|
294
317
|
exports.setLightOn = setLightOn;
|
295
318
|
/**
|
@@ -299,10 +322,16 @@ exports.setLightOn = setLightOn;
|
|
299
322
|
* @param {string} lightID Light ID string.
|
300
323
|
* @param {number} brightness An integer, 1-100, indicating brightness. Ignored.
|
301
324
|
* @param {Object} authOpts Authentication object returned from the login.
|
325
|
+
* @param {boolean} isDimmer Indicates whether or not light is dimmable.
|
302
326
|
* @returns {Promise}
|
303
327
|
*/
|
304
|
-
function setLightOff(lightID, authOpts, brightness) {
|
305
|
-
|
328
|
+
function setLightOff(lightID, authOpts, brightness, isDimmer) {
|
329
|
+
if (isDimmer) {
|
330
|
+
return dimmerAction(lightID, authOpts, brightness, 'turnOff');
|
331
|
+
}
|
332
|
+
else {
|
333
|
+
return lightAction(lightID, authOpts, 'turnOff');
|
334
|
+
}
|
306
335
|
}
|
307
336
|
exports.setLightOff = setLightOff;
|
308
337
|
// Lock methods ////////////////////////////////////////////////////////////////
|
@@ -438,7 +467,7 @@ async function get(url, opts) {
|
|
438
467
|
let status;
|
439
468
|
let resHeaders;
|
440
469
|
try {
|
441
|
-
const res = await node_fetch_1.default(url, {
|
470
|
+
const res = await (0, node_fetch_1.default)(url, {
|
442
471
|
method: 'GET',
|
443
472
|
redirect: 'manual',
|
444
473
|
headers: opts.headers
|
@@ -468,7 +497,7 @@ async function post(url, opts) {
|
|
468
497
|
let status;
|
469
498
|
let resHeaders;
|
470
499
|
try {
|
471
|
-
const res = await node_fetch_1.default(url, {
|
500
|
+
const res = await (0, node_fetch_1.default)(url, {
|
472
501
|
method: 'POST',
|
473
502
|
redirect: 'manual',
|
474
503
|
body: opts.body ? JSON.stringify(opts.body) : undefined,
|
package/package.json
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "node-alarm-dot-com",
|
3
|
-
"version": "
|
3
|
+
"version": "2.0.0-beta.2",
|
4
|
+
"betaVersion": "2.0.0",
|
4
5
|
"description": "An interface module written in node.js to arm and disarm Alarm.com security systems.",
|
5
6
|
"author": {
|
6
|
-
"name": "
|
7
|
-
"
|
7
|
+
"name": "Chase Lau",
|
8
|
+
"url": "https://github.com/chase9"
|
8
9
|
},
|
9
10
|
"license": "MIT",
|
10
11
|
"keywords": [
|
@@ -44,17 +45,18 @@
|
|
44
45
|
"test": "echo \"Error: no test specified\" && exit 1"
|
45
46
|
},
|
46
47
|
"engines": {
|
47
|
-
"node": "
|
48
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
48
49
|
},
|
49
50
|
"dependencies": {
|
50
|
-
"@types/node-fetch": "^
|
51
|
+
"@types/node-fetch": "^3.0.2",
|
52
|
+
"@types/node": "^17.0.16",
|
51
53
|
"node-fetch": "^2.6.1",
|
52
54
|
"semver": "^7.3.5"
|
53
55
|
},
|
54
56
|
"devDependencies": {
|
55
57
|
"rimraf": "^3.0.2",
|
56
|
-
"ts-node": "^10.
|
57
|
-
"typescript": "^4.
|
58
|
-
"yargs": "^17.1
|
58
|
+
"ts-node": "^10.5.0",
|
59
|
+
"typescript": "^4.5.5",
|
60
|
+
"yargs": "^17.3.1"
|
59
61
|
}
|
60
62
|
}
|