node-alarm-dot-com 2.0.0-beta.3 → 2.0.0-beta.5

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,6 +1,6 @@
1
1
  import { Relationship } from './IdentityResponse';
2
- import { RelationshipType } from './SystemState';
3
- import { GARAGE_STATES, LIGHT_STATES, LOCK_STATES, SENSOR_STATES, SYSTEM_STATES } from './States';
2
+ import { AutomationType, RelationshipType } from './SystemState';
3
+ import { GARAGE_STATES, LIGHT_STATES, LOCK_STATES, SENSOR_STATES, SYSTEM_STATES, THERMOSTAT_STATES } from './States';
4
4
  import { SensorType } from './SensorType';
5
5
  export interface ApiLightState extends ApiDeviceState {
6
6
  data: {
@@ -752,6 +752,306 @@ export interface CameraState extends DeviceState {
752
752
  };
753
753
  };
754
754
  }
755
+ export interface ApiThermostatState extends ApiDeviceState {
756
+ data: {
757
+ id: string;
758
+ type: RelationshipType.Thermostat;
759
+ attributes: {
760
+ requiresSetup: boolean;
761
+ forwardingAmbientTemp: number;
762
+ minHeatSetpoint: number;
763
+ maxHeatSetpoint: number;
764
+ minCoolSetpoint: number;
765
+ maxCoolSetpoint: number;
766
+ minAuxHeatSetpoint: number;
767
+ maxAuxHeatSetpoint: number;
768
+ heatSetpoint: number;
769
+ desiredHeatSetpoint: number;
770
+ coolSetpoint: number;
771
+ desiredCoolSetpoint: number;
772
+ homeHeatSetpoint: number;
773
+ homeCoolSetpoint: number;
774
+ awayHeatSetpoint: number;
775
+ awayCoolSetpoint: number;
776
+ sleepHeatSetpoint: number;
777
+ sleepCoolSetpoint: number;
778
+ setpointOffset: number;
779
+ autoSetpointBuffer: number;
780
+ thirdPartySettingsUrlDesc?: string;
781
+ thirdPartySettingsUrl?: string;
782
+ state: THERMOSTAT_STATES;
783
+ desiredState: THERMOSTAT_STATES;
784
+ inferredState: THERMOSTAT_STATES;
785
+ scheduleMode: number;
786
+ fanMode: number;
787
+ desiredFanMode: number;
788
+ fanDuration?: null;
789
+ localDisplayLockingMode: number;
790
+ desiredLocalDisplayLockingMode?: null;
791
+ hasRtsIssue: boolean;
792
+ isControlled: boolean;
793
+ supportsSetpoints: boolean;
794
+ isPoolController: boolean;
795
+ supportsOffMode: boolean;
796
+ supportsHeatMode: boolean;
797
+ supportsCoolMode: boolean;
798
+ supportsAutoMode: boolean;
799
+ supportsSmartSchedules: boolean;
800
+ supportsAuxHeatMode: boolean;
801
+ supportsSchedules: boolean;
802
+ supportsFanMode: boolean;
803
+ supportsIndefiniteFanOn: boolean;
804
+ supportedFanDurations: number[];
805
+ supportsCirculateFanModeAlways: boolean;
806
+ supportsCirculateFanModeWhenOff: boolean;
807
+ supportsRts?: boolean;
808
+ supportsLocalDisplayLocking: boolean;
809
+ supportsPartialLocalDisplayLocking: boolean;
810
+ supportsHvacAnalytics: boolean;
811
+ supportsThirdPartySettings: boolean;
812
+ hasPendingTempModeChange: boolean;
813
+ hasPendingSetpointChange: boolean;
814
+ hasPendingHeatSetpointChange: boolean;
815
+ hasPendingCoolSetpointChange: boolean;
816
+ ambientTemp: number;
817
+ isPaired: boolean;
818
+ supportsPairing: boolean;
819
+ tempForwardingActive: boolean;
820
+ supportsHumidity: boolean;
821
+ humidityLevel?: number;
822
+ managedDeviceType: number;
823
+ hasState: boolean;
824
+ canBeRenamed: boolean;
825
+ canBeDeleted: boolean;
826
+ canAccessWebSettings: boolean;
827
+ canAccessAppSettings: boolean;
828
+ webSettings: number;
829
+ canAccessTroubleshootingWizard: boolean;
830
+ troubleshootingWizard?: null;
831
+ canBeAssociatedToVideoDevice: boolean;
832
+ associatedCameraDeviceIds: {};
833
+ macAddress: string;
834
+ manufacturer: string;
835
+ isOAuth: boolean;
836
+ isZWave: boolean;
837
+ supportsCommandClassBasic: boolean;
838
+ isMalfunctioning: boolean;
839
+ canBeSaved: boolean;
840
+ canChangeDescription: boolean;
841
+ description: string;
842
+ deviceModelId: number;
843
+ canConfirmStateChange: boolean;
844
+ canReceiveCommands: boolean;
845
+ remoteCommandsEnabled: boolean;
846
+ hasPermissionToChangeState: boolean;
847
+ deviceIcon: {
848
+ icon: number;
849
+ };
850
+ batteryLevelNull: number;
851
+ lowBattery: boolean;
852
+ criticalBattery: boolean;
853
+ };
854
+ relationships: {
855
+ ruleSuggestions: {
856
+ data: Relationship[];
857
+ meta: {
858
+ count: string;
859
+ };
860
+ };
861
+ thermostatSettingsTemplate: {
862
+ data?: any;
863
+ };
864
+ remoteTemperatureSensors: {
865
+ data: [];
866
+ meta: {
867
+ count: string;
868
+ };
869
+ };
870
+ boilerControlSystem: {
871
+ data?: any;
872
+ };
873
+ valveSwitches: {
874
+ data: [];
875
+ meta: {
876
+ count: string;
877
+ };
878
+ };
879
+ peakProtect: {
880
+ data: {
881
+ id: string;
882
+ type: AutomationType.PeakProtect;
883
+ };
884
+ };
885
+ controlledThermostats: {
886
+ data: [];
887
+ meta: {
888
+ count: string;
889
+ };
890
+ };
891
+ system: {
892
+ data: {
893
+ id: string;
894
+ type: RelationshipType.System;
895
+ };
896
+ };
897
+ stateInfo: {
898
+ data?: {
899
+ id: string;
900
+ type: RelationshipType.State;
901
+ };
902
+ };
903
+ };
904
+ };
905
+ }
906
+ export interface ThermostatState extends DeviceState {
907
+ id: string;
908
+ type: RelationshipType.Thermostat;
909
+ attributes: {
910
+ requiresSetup: boolean;
911
+ forwardingAmbientTemp: number;
912
+ minHeatSetpoint: number;
913
+ maxHeatSetpoint: number;
914
+ minCoolSetpoint: number;
915
+ maxCoolSetpoint: number;
916
+ minAuxHeatSetpoint: number;
917
+ maxAuxHeatSetpoint: number;
918
+ heatSetpoint: number;
919
+ desiredHeatSetpoint: number;
920
+ coolSetpoint: number;
921
+ desiredCoolSetpoint: number;
922
+ homeHeatSetpoint: number;
923
+ homeCoolSetpoint: number;
924
+ awayHeatSetpoint: number;
925
+ awayCoolSetpoint: number;
926
+ sleepHeatSetpoint: number;
927
+ sleepCoolSetpoint: number;
928
+ setpointOffset: number;
929
+ autoSetpointBuffer: number;
930
+ thirdPartySettingsUrlDesc?: string;
931
+ thirdPartySettingsUrl?: string;
932
+ state: THERMOSTAT_STATES;
933
+ desiredState: THERMOSTAT_STATES;
934
+ inferredState: THERMOSTAT_STATES;
935
+ scheduleMode: number;
936
+ fanMode: number;
937
+ desiredFanMode: number;
938
+ fanDuration?: null;
939
+ localDisplayLockingMode: number;
940
+ desiredLocalDisplayLockingMode?: null;
941
+ hasRtsIssue: boolean;
942
+ isControlled: boolean;
943
+ supportsSetpoints: boolean;
944
+ isPoolController: boolean;
945
+ supportsOffMode: boolean;
946
+ supportsHeatMode: boolean;
947
+ supportsCoolMode: boolean;
948
+ supportsAutoMode: boolean;
949
+ supportsSmartSchedules: boolean;
950
+ supportsAuxHeatMode: boolean;
951
+ supportsSchedules: boolean;
952
+ supportsFanMode: boolean;
953
+ supportsIndefiniteFanOn: boolean;
954
+ supportedFanDurations: number[];
955
+ supportsCirculateFanModeAlways: boolean;
956
+ supportsCirculateFanModeWhenOff: boolean;
957
+ supportsRts?: boolean;
958
+ supportsLocalDisplayLocking: boolean;
959
+ supportsPartialLocalDisplayLocking: boolean;
960
+ supportsHvacAnalytics: boolean;
961
+ supportsThirdPartySettings: boolean;
962
+ hasPendingTempModeChange: boolean;
963
+ hasPendingSetpointChange: boolean;
964
+ hasPendingHeatSetpointChange: boolean;
965
+ hasPendingCoolSetpointChange: boolean;
966
+ ambientTemp: number;
967
+ isPaired: boolean;
968
+ supportsPairing: boolean;
969
+ tempForwardingActive: boolean;
970
+ supportsHumidity: boolean;
971
+ humidityLevel?: number;
972
+ managedDeviceType: number;
973
+ hasState: boolean;
974
+ canBeRenamed: boolean;
975
+ canBeDeleted: boolean;
976
+ canAccessWebSettings: boolean;
977
+ canAccessAppSettings: boolean;
978
+ webSettings: number;
979
+ canAccessTroubleshootingWizard: boolean;
980
+ troubleshootingWizard?: null;
981
+ canBeAssociatedToVideoDevice: boolean;
982
+ associatedCameraDeviceIds: {};
983
+ macAddress: string;
984
+ manufacturer: string;
985
+ isOAuth: boolean;
986
+ isZWave: boolean;
987
+ supportsCommandClassBasic: boolean;
988
+ isMalfunctioning: boolean;
989
+ canBeSaved: boolean;
990
+ canChangeDescription: boolean;
991
+ description: string;
992
+ deviceModelId: number;
993
+ canConfirmStateChange: boolean;
994
+ canReceiveCommands: boolean;
995
+ remoteCommandsEnabled: boolean;
996
+ hasPermissionToChangeState: boolean;
997
+ deviceIcon: {
998
+ icon: number;
999
+ };
1000
+ batteryLevelNull: number;
1001
+ lowBattery: boolean;
1002
+ criticalBattery: boolean;
1003
+ };
1004
+ relationships: {
1005
+ ruleSuggestions: {
1006
+ data: Relationship[];
1007
+ meta: {
1008
+ count: string;
1009
+ };
1010
+ };
1011
+ thermostatSettingsTemplate: {
1012
+ data?: any;
1013
+ };
1014
+ remoteTemperatureSensors: {
1015
+ data: [];
1016
+ meta: {
1017
+ count: string;
1018
+ };
1019
+ };
1020
+ boilerControlSystem: {
1021
+ data?: any;
1022
+ };
1023
+ valveSwitches: {
1024
+ data: [];
1025
+ meta: {
1026
+ count: string;
1027
+ };
1028
+ };
1029
+ peakProtect: {
1030
+ data: {
1031
+ id: string;
1032
+ type: AutomationType.PeakProtect;
1033
+ };
1034
+ };
1035
+ controlledThermostats: {
1036
+ data: [];
1037
+ meta: {
1038
+ count: string;
1039
+ };
1040
+ };
1041
+ system: {
1042
+ data: {
1043
+ id: string;
1044
+ type: RelationshipType.System;
1045
+ };
1046
+ };
1047
+ stateInfo: {
1048
+ data?: {
1049
+ id: string;
1050
+ type: RelationshipType.State;
1051
+ };
1052
+ };
1053
+ };
1054
+ }
755
1055
  /**
756
1056
  * Base interface for retrieving device state from Alarm.com's API
757
1057
  * All devices retrieved contain these properties.
@@ -8,6 +8,9 @@ export declare enum SensorType {
8
8
  CO_Detector = 6,
9
9
  Heat_Detector = 8,
10
10
  Fob = 9,
11
+ Keypad = 10,
11
12
  Water_Sensor = 17,
12
- Glass_Break = 19
13
+ Glass_Break = 19,
14
+ Panel_Camera = 68,
15
+ Panel_Glass_Break = 83
13
16
  }
@@ -12,6 +12,9 @@ var SensorType;
12
12
  SensorType[SensorType["CO_Detector"] = 6] = "CO_Detector";
13
13
  SensorType[SensorType["Heat_Detector"] = 8] = "Heat_Detector";
14
14
  SensorType[SensorType["Fob"] = 9] = "Fob";
15
+ SensorType[SensorType["Keypad"] = 10] = "Keypad";
15
16
  SensorType[SensorType["Water_Sensor"] = 17] = "Water_Sensor";
16
17
  SensorType[SensorType["Glass_Break"] = 19] = "Glass_Break";
18
+ SensorType[SensorType["Panel_Camera"] = 68] = "Panel_Camera";
19
+ SensorType[SensorType["Panel_Glass_Break"] = 83] = "Panel_Glass_Break";
17
20
  })(SensorType = exports.SensorType || (exports.SensorType = {}));
@@ -1,5 +1,7 @@
1
1
  /***
2
2
  * State of the partition as defined by Alarm.com
3
+ * @readonly
4
+ * @enum {number}
3
5
  */
4
6
  export declare enum SYSTEM_STATES {
5
7
  UNKNOWN = 0,
@@ -10,6 +12,8 @@ export declare enum SYSTEM_STATES {
10
12
  }
11
13
  /***
12
14
  * State of the sensor as defined by Alarm.com
15
+ * @readonly
16
+ * @enum {number}
13
17
  */
14
18
  export declare enum SENSOR_STATES {
15
19
  UNKNOWN = 0,
@@ -22,6 +26,8 @@ export declare enum SENSOR_STATES {
22
26
  }
23
27
  /***
24
28
  * State of the light as defined by Alarm.com
29
+ * @readonly
30
+ * @enum {number}
25
31
  */
26
32
  export declare enum LIGHT_STATES {
27
33
  ON = 2,
@@ -29,6 +35,8 @@ export declare enum LIGHT_STATES {
29
35
  }
30
36
  /***
31
37
  * State of the lock as defined by Alarm.com
38
+ * @readonly
39
+ * @enum {number}
32
40
  */
33
41
  export declare enum LOCK_STATES {
34
42
  SECURED = 1,
@@ -36,14 +44,28 @@ export declare enum LOCK_STATES {
36
44
  }
37
45
  /***
38
46
  * State of the garage as defined by Alarm.com
47
+ * @readonly
48
+ * @enum {number}
39
49
  */
40
50
  export declare enum GARAGE_STATES {
41
51
  OPEN = 1,
42
52
  CLOSED = 2
43
53
  }
54
+ /***
55
+ * State of the thermostat as defined by Alarm.com
56
+ * @readonly
57
+ * @enum {number}
58
+ */
59
+ export declare enum THERMOSTAT_STATES {
60
+ OFF = 1,
61
+ HEATING = 2,
62
+ COOLING = 3,
63
+ AUTO = 4
64
+ }
44
65
  /***
45
66
  * Relation types as defined by Alarm.com.
46
67
  * Relationship types tell you what object is being sent from the API.
68
+ * @readonly
47
69
  */
48
70
  export declare enum REL_TYPES {
49
71
  CONFIGURATION = "systems/configuration",
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.REL_TYPES = exports.GARAGE_STATES = exports.LOCK_STATES = exports.LIGHT_STATES = exports.SENSOR_STATES = exports.SYSTEM_STATES = void 0;
3
+ exports.REL_TYPES = exports.THERMOSTAT_STATES = exports.GARAGE_STATES = exports.LOCK_STATES = exports.LIGHT_STATES = exports.SENSOR_STATES = exports.SYSTEM_STATES = void 0;
4
4
  /***
5
5
  * State of the partition as defined by Alarm.com
6
+ * @readonly
7
+ * @enum {number}
6
8
  */
7
9
  var SYSTEM_STATES;
8
10
  (function (SYSTEM_STATES) {
@@ -14,6 +16,8 @@ var SYSTEM_STATES;
14
16
  })(SYSTEM_STATES = exports.SYSTEM_STATES || (exports.SYSTEM_STATES = {}));
15
17
  /***
16
18
  * State of the sensor as defined by Alarm.com
19
+ * @readonly
20
+ * @enum {number}
17
21
  */
18
22
  var SENSOR_STATES;
19
23
  (function (SENSOR_STATES) {
@@ -27,6 +31,8 @@ var SENSOR_STATES;
27
31
  })(SENSOR_STATES = exports.SENSOR_STATES || (exports.SENSOR_STATES = {}));
28
32
  /***
29
33
  * State of the light as defined by Alarm.com
34
+ * @readonly
35
+ * @enum {number}
30
36
  */
31
37
  var LIGHT_STATES;
32
38
  (function (LIGHT_STATES) {
@@ -35,6 +41,8 @@ var LIGHT_STATES;
35
41
  })(LIGHT_STATES = exports.LIGHT_STATES || (exports.LIGHT_STATES = {}));
36
42
  /***
37
43
  * State of the lock as defined by Alarm.com
44
+ * @readonly
45
+ * @enum {number}
38
46
  */
39
47
  var LOCK_STATES;
40
48
  (function (LOCK_STATES) {
@@ -43,6 +51,8 @@ var LOCK_STATES;
43
51
  })(LOCK_STATES = exports.LOCK_STATES || (exports.LOCK_STATES = {}));
44
52
  /***
45
53
  * State of the garage as defined by Alarm.com
54
+ * @readonly
55
+ * @enum {number}
46
56
  */
47
57
  var GARAGE_STATES;
48
58
  (function (GARAGE_STATES) {
@@ -50,9 +60,22 @@ var GARAGE_STATES;
50
60
  GARAGE_STATES[GARAGE_STATES["OPEN"] = 1] = "OPEN";
51
61
  GARAGE_STATES[GARAGE_STATES["CLOSED"] = 2] = "CLOSED"; //double check
52
62
  })(GARAGE_STATES = exports.GARAGE_STATES || (exports.GARAGE_STATES = {}));
63
+ /***
64
+ * State of the thermostat as defined by Alarm.com
65
+ * @readonly
66
+ * @enum {number}
67
+ */
68
+ var THERMOSTAT_STATES;
69
+ (function (THERMOSTAT_STATES) {
70
+ THERMOSTAT_STATES[THERMOSTAT_STATES["OFF"] = 1] = "OFF";
71
+ THERMOSTAT_STATES[THERMOSTAT_STATES["HEATING"] = 2] = "HEATING";
72
+ THERMOSTAT_STATES[THERMOSTAT_STATES["COOLING"] = 3] = "COOLING";
73
+ THERMOSTAT_STATES[THERMOSTAT_STATES["AUTO"] = 4] = "AUTO";
74
+ })(THERMOSTAT_STATES = exports.THERMOSTAT_STATES || (exports.THERMOSTAT_STATES = {}));
53
75
  /***
54
76
  * Relation types as defined by Alarm.com.
55
77
  * Relationship types tell you what object is being sent from the API.
78
+ * @readonly
56
79
  */
57
80
  var REL_TYPES;
58
81
  (function (REL_TYPES) {
@@ -204,4 +204,8 @@ export declare enum RelationshipType {
204
204
  System = "systems/system",
205
205
  State = "devices/state-info"
206
206
  }
207
+ export declare enum AutomationType {
208
+ PeakProtect = "automation/peak-protect",
209
+ RuleSuggestion = "automation/rules/ruleSuggestion"
210
+ }
207
211
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RelationshipType = void 0;
3
+ exports.AutomationType = exports.RelationshipType = void 0;
4
4
  var RelationshipType;
5
5
  (function (RelationshipType) {
6
6
  RelationshipType["Partition"] = "devices/partition";
@@ -17,3 +17,8 @@ var RelationshipType;
17
17
  RelationshipType["System"] = "systems/system";
18
18
  RelationshipType["State"] = "devices/state-info";
19
19
  })(RelationshipType = exports.RelationshipType || (exports.RelationshipType = {}));
20
+ var AutomationType;
21
+ (function (AutomationType) {
22
+ AutomationType["PeakProtect"] = "automation/peak-protect";
23
+ AutomationType["RuleSuggestion"] = "automation/rules/ruleSuggestion";
24
+ })(AutomationType = exports.AutomationType || (exports.AutomationType = {}));
package/dist/index.d.ts CHANGED
@@ -69,7 +69,7 @@ export declare function armStay(partitionID: string, authOpts: AuthOpts, opts: P
69
69
  * delay.
70
70
  * @returns {Promise}
71
71
  */
72
- export declare function armAway(partitionID: string, authOpts: AuthOpts, opts: any): Promise<any>;
72
+ export declare function armAway(partitionID: string, authOpts: AuthOpts, opts: PartitionActionOptions): Promise<any>;
73
73
  /**
74
74
  * Convenience Method:
75
75
  * Disarm a security system panel. NOTE: This call generally takes 20-30 seconds
package/dist/index.js CHANGED
@@ -35,7 +35,7 @@ const SENSORS_URL = 'https://www.alarm.com/web/api/devices/sensors';
35
35
  const LIGHTS_URL = 'https://www.alarm.com/web/api/devices/lights/';
36
36
  const GARAGE_URL = 'https://www.alarm.com/web/api/devices/garageDoors/';
37
37
  const LOCKS_URL = 'https://www.alarm.com/web/api/devices/locks/';
38
- const CT_JSON = 'application/json;charset=UTF-8';
38
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
39
39
  const UA = `node-alarm-dot-com/${require('../package.json').version}`;
40
40
  // Exported methods ////////////////////////////////////////////////////////////
41
41
  /**
@@ -54,6 +54,7 @@ async function login(username, password, existingMfaToken) {
54
54
  // load initial alarm.com page to gather required hidden form fields
55
55
  await get(ADCLOGIN_URL)
56
56
  .then(res => {
57
+ /* eslint-disable @typescript-eslint/naming-convention */
57
58
  const loginObj = {
58
59
  '__EVENTTARGET': null,
59
60
  '__EVENTARGUMENT': null,
@@ -66,6 +67,7 @@ async function login(username, password, existingMfaToken) {
66
67
  'ctl00$ContentPlaceHolder1$loginform$txtUserName': username,
67
68
  'txtPassword': password
68
69
  };
70
+ /* eslint-enable @typescript-eslint/naming-convention */
69
71
  // build login form body
70
72
  loginFormBody = Object.keys(loginObj).map(k => encodeURIComponent(k) + '=' + encodeURIComponent(loginObj[k])).join('&');
71
73
  })
@@ -74,11 +76,13 @@ async function login(username, password, existingMfaToken) {
74
76
  });
75
77
  await (0, node_fetch_1.default)(ADCFORMLOGIN_URL, {
76
78
  method: 'POST',
79
+ /* eslint-disable @typescript-eslint/naming-convention */
77
80
  headers: {
78
81
  'Content-Type': 'application/x-www-form-urlencoded',
79
82
  'User-Agent': UA,
80
83
  'Cookie': `twoFactorAuthenticationId=${existingMfaToken};`
81
84
  },
85
+ /* eslint-enable @typescript-eslint/naming-convention */
82
86
  body: loginFormBody,
83
87
  redirect: 'manual'
84
88
  })
@@ -95,6 +99,7 @@ async function login(username, password, existingMfaToken) {
95
99
  throw new Error(`POST ${ADCFORMLOGIN_URL} failed: ${err.message || err}`);
96
100
  });
97
101
  await get(IDENTITIES_URL, {
102
+ /* eslint-disable @typescript-eslint/naming-convention */
98
103
  headers: {
99
104
  'Accept': 'application/vnd.api+json',
100
105
  'Cookie': loginCookies,
@@ -102,6 +107,7 @@ async function login(username, password, existingMfaToken) {
102
107
  'Referer': 'https://www.alarm.com/web/system/home',
103
108
  'User-Agent': UA
104
109
  }
110
+ /* eslint-enable @typescript-eslint/naming-convention */
105
111
  })
106
112
  .then(res => {
107
113
  // gather identities and systems
@@ -176,12 +182,44 @@ exports.getCurrentState = getCurrentState;
176
182
  * @param {Object} authOpts Authentication object returned from the login.
177
183
  * @returns {Promise}
178
184
  */
179
- function getComponents(url, componentIDs, authOpts) {
185
+ async function getComponents(url, componentIDs, authOpts) {
180
186
  const IDs = Array.isArray(componentIDs) ? componentIDs : [componentIDs];
181
- let getUrl = `${url}?${IDs.map(id => `ids%5B%5D=${id}`).join('&')}`;
182
- return authenticatedGet(getUrl, authOpts);
187
+ let requests = [];
188
+ if (IDs.length <= 50) {
189
+ const getUrl = `${url}?${IDs.map(id => `ids%5B%5D=${id}`).join('&')}`;
190
+ requests.push(authenticatedGet(getUrl, authOpts));
191
+ }
192
+ else {
193
+ // We have found that the Alarm.com API will return a 404 error when there is an excessive number of query parameters.
194
+ // We get around this by breaking up our GET calls into shorter URIs.
195
+ const shortenedUrls = [];
196
+ while (IDs.length > 50) {
197
+ const currentArray = IDs.splice(0, 50);
198
+ shortenedUrls.push(`${url}?${currentArray.map(id => `ids%5B%5D=${id}`).join('&')}`);
199
+ }
200
+ shortenedUrls.push(`${url}?${IDs.map(id => `ids%5B%5D=${id}`).join('&')}`);
201
+ requests = shortenedUrls.map(u => authenticatedGet(u, authOpts));
202
+ }
203
+ return await combineAPIDeviceAPICalls(requests);
183
204
  }
184
205
  exports.getComponents = getComponents;
206
+ async function combineAPIDeviceAPICalls(apiCalls) {
207
+ const apiStateCalls = await Promise.all(apiCalls);
208
+ const stateToReturn = {
209
+ data: [],
210
+ included: []
211
+ };
212
+ for (const apiCall of apiStateCalls) {
213
+ for (const apiData of (apiCall.data)) {
214
+ stateToReturn.data.push(apiData);
215
+ }
216
+ for (const apiInclude of apiCall.included) {
217
+ stateToReturn.included.push(apiInclude);
218
+ }
219
+ }
220
+ stateToReturn.meta = apiStateCalls[0].meta;
221
+ return stateToReturn;
222
+ }
185
223
  // Partition methods ///////////////////////////////////////////////////////////
186
224
  /**
187
225
  * Perform partition actions, e.g., armAway, armStay, disarm.
@@ -379,7 +417,7 @@ exports.setLockUnsecure = setLockUnsecure;
379
417
  /**
380
418
  * Get information for one or more garages.
381
419
  *
382
- * @param {string[]} garageIDs Array of Gagage ID strings.
420
+ * @param {string[]} garageIDs Array of Garage ID strings.
383
421
  * @param {Object} authOpts Authentication object returned from the `login`
384
422
  * method.
385
423
  * @returns {Promise}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-alarm-dot-com",
3
- "version": "2.0.0-beta.3",
3
+ "version": "2.0.0-beta.5",
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": {
@@ -48,12 +48,15 @@
48
48
  "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
49
49
  },
50
50
  "dependencies": {
51
- "@types/node-fetch": "^3.0.2",
52
51
  "@types/node": "^17.0.16",
52
+ "@types/node-fetch": "^3.0.2",
53
53
  "node-fetch": "^2.6.1",
54
54
  "semver": "^7.3.5"
55
55
  },
56
56
  "devDependencies": {
57
+ "@typescript-eslint/eslint-plugin": "^5.11.0",
58
+ "@typescript-eslint/parser": "^5.11.0",
59
+ "eslint": "8.22.0",
57
60
  "rimraf": "^3.0.2",
58
61
  "ts-node": "^10.5.0",
59
62
  "typescript": "^4.5.5",