node-alarm-dot-com 2.0.0-beta.1 → 2.0.0-beta.4

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.
@@ -1,4 +1,7 @@
1
1
  import { IdentityResponse } from './IdentityResponse';
2
+ /**
3
+ * AuthOpts is authentication information which is used in API requests to authenticate as the user.
4
+ */
2
5
  export interface AuthOpts {
3
6
  cookie: string;
4
7
  ajaxKey: string;
@@ -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: number;
517
+ deviceType: SensorType;
517
518
  openClosedStatus: number;
518
519
  state: SENSOR_STATES;
519
520
  stateText: string;
@@ -751,18 +752,12 @@ 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
- data: {
756
- id: string;
757
- type: RelationshipType;
758
- attributes: any;
759
- relationships: any;
760
- } | Array<{
761
- id: string;
762
- type: RelationshipType;
763
- attributes: any;
764
- relationships: any;
765
- }>;
760
+ data: DeviceState[] | DeviceState;
766
761
  included: [];
767
762
  meta: {
768
763
  transformer_version: '1.1' | string;
@@ -1,3 +1,7 @@
1
+ /**
2
+ * The identity response is returned upon authenticating against the Alarm.com API.
3
+ * It's then parsed and the authentication token stored for future use.
4
+ */
1
5
  export interface IdentityResponse {
2
6
  data: {
3
7
  id: number;
@@ -1,3 +1,6 @@
1
+ /**
2
+ * These options are sent when arming a partition to indicate desired arming options.
3
+ */
1
4
  export interface PartitionActionOptions {
2
5
  noEntryDelay: boolean;
3
6
  silentArming: boolean;
@@ -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 = {}));
@@ -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",
@@ -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";
@@ -1,4 +1,8 @@
1
1
  import { GarageState, LightState, LockState, PartitionState, SensorState } from './DeviceStates';
2
+ /**
3
+ * Response information from
4
+ * api/systems/systems/{id}
5
+ */
2
6
  export interface SystemState {
3
7
  data: {
4
8
  id: number;
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.
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';
@@ -175,12 +176,44 @@ exports.getCurrentState = getCurrentState;
175
176
  * @param {Object} authOpts Authentication object returned from the login.
176
177
  * @returns {Promise}
177
178
  */
178
- function getComponents(url, componentIDs, authOpts) {
179
+ async function getComponents(url, componentIDs, authOpts) {
179
180
  const IDs = Array.isArray(componentIDs) ? componentIDs : [componentIDs];
180
- let getUrl = `${url}?${IDs.map(id => `ids%5B%5D=${id}`).join('&')}`;
181
- return authenticatedGet(getUrl, authOpts);
181
+ let requests = [];
182
+ if (IDs.length <= 50) {
183
+ const getUrl = `${url}?${IDs.map(id => `ids%5B%5D=${id}`).join('&')}`;
184
+ requests.push(authenticatedGet(getUrl, authOpts));
185
+ }
186
+ else {
187
+ // We have found that the Alarm.com API will return a 404 error when there is an excessive number of query parameters.
188
+ // We get around this by breaking up our GET calls into shorter URIs.
189
+ const shortenedUrls = [];
190
+ while (IDs.length > 50) {
191
+ const currentArray = IDs.splice(0, 50);
192
+ shortenedUrls.push(`${url}?${currentArray.map(id => `ids%5B%5D=${id}`).join('&')}`);
193
+ }
194
+ shortenedUrls.push(`${url}?${IDs.map(id => `ids%5B%5D=${id}`).join('&')}`);
195
+ requests = shortenedUrls.map(u => authenticatedGet(u, authOpts));
196
+ }
197
+ return await CombineAPIDeviceAPICalls(requests);
182
198
  }
183
199
  exports.getComponents = getComponents;
200
+ async function CombineAPIDeviceAPICalls(ApiCalls) {
201
+ const apiStateCalls = await Promise.all(ApiCalls);
202
+ const stateToReturn = {
203
+ data: [],
204
+ included: []
205
+ };
206
+ for (let apiCall of apiStateCalls) {
207
+ for (const apiData of (apiCall.data)) {
208
+ stateToReturn.data.push(apiData);
209
+ }
210
+ for (const apiInclude of apiCall.included) {
211
+ stateToReturn.included.push(apiInclude);
212
+ }
213
+ }
214
+ stateToReturn.meta = apiStateCalls[0].meta;
215
+ return stateToReturn;
216
+ }
184
217
  // Partition methods ///////////////////////////////////////////////////////////
185
218
  /**
186
219
  * Perform partition actions, e.g., armAway, armStay, disarm.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-alarm-dot-com",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.4",
4
4
  "betaVersion": "2.0.0",
5
5
  "description": "An interface module written in node.js to arm and disarm Alarm.com security systems.",
6
6
  "author": {