node-alarm-dot-com 2.1.0-beta.3 → 2.1.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.
package/README.md CHANGED
@@ -24,6 +24,10 @@ Supported Features
24
24
  * Dimmer switch
25
25
  * Locks
26
26
  * Lock/Unlock switch
27
+ * Thermostats
28
+ * State (Off, Heat, Cool, Auto)
29
+ * Desired Heat setpoint
30
+ * Desired Cool setpoint
27
31
 
28
32
  Usage
29
33
  -----
@@ -83,6 +87,9 @@ Documentation
83
87
  * [~getLocks(lockIDs, authOpts)](#module_nodeADC..getLocks) ⇒ <code>Promise</code>
84
88
  * [~secureLock(lockID, authOpts)](#module_nodeADC..secureLock) ⇒ <code>Promise</code>
85
89
  * [~unsecureLock(lockID, authOpts)](#module_nodeADC..unsecureLock) ⇒ <code>Promise</code>
90
+ * [~setThermostatState(thermostatID, newState, authOpts)](#module_nodeADC..setThermostatState) ⇒ <code>Promise</code>
91
+ * [~setThermostatTargetHeatTemperature(thermostatID, newTemp, authOpts)](#module_nodeADC..setThermostatTargetHeatTemperature) ⇒ <code>Promise</code>
92
+ * [~setThermostatTargetCoolTemperature(thermostatID, newTemp, authOpts)](#module_nodeADC..setThermostatTargetCoolTemperature) ⇒ <code>Promise</code>
86
93
  * [~armStay(partitionID, authOpts, opts)](#module_nodeADC..armStay) ⇒ <code>Promise</code>
87
94
  * [~armAway(partitionID, authOpts, opts)](#module_nodeADC..armAway) ⇒ <code>Promise</code>
88
95
  * [~disarm(partitionID, authOpts)](#module_nodeADC..disarm) ⇒ <code>Promise</code>
@@ -209,6 +216,45 @@ Sets a lock to "unlocked" (UNSECURED).
209
216
  | lockID | <code>string</code> | Lock ID string. |
210
217
  | authOpts | <code>Object</code> | Authentication object returned from the `login` method. |
211
218
 
219
+ <a name="module_nodeADC..setThermostatState"></a>
220
+
221
+ ### nodeADC~setThermostatState(thermostatID, newState, authOpts) ⇒ <code>Promise</code>
222
+ Update Thermostat State (see `THERMOSTAT_STATES`)
223
+
224
+ **Kind**: inner method of [<code>nodeADC</code>](#module_nodeADC)
225
+
226
+ | Param | Type | Description |
227
+ |--------------|--------------------------------|-------------------------------------------------------------|
228
+ | thermostatID | <code>string</code> | Thermostat ID string. |
229
+ | newState | <code>THERMOSTAT_STATES</code> | Desired state, `THERMOSTAT_STATES.OFF`/`HEAT`/`COOL`/`AUTO` |
230
+ | authOpts | <code>Object</code> | Authentication object returned from the `login` method. |
231
+
232
+ <a name="module_nodeADC..setThermostatTargetHeatTemperature"></a>
233
+
234
+ ### nodeADC~setThermostatTargetHeatTemperature(thermostatID, newTemp, authOpts) ⇒ <code>Promise</code>
235
+ Set desired Heat setpoint temperature for Thermostat
236
+
237
+ **Kind**: inner method of [<code>nodeADC</code>](#module_nodeADC)
238
+
239
+ | Param | Type | Description |
240
+ |--------------|---------------------|---------------------------------------------------------|
241
+ | thermostatID | <code>string</code> | Thermostat ID string. |
242
+ | newTemp | <code>number</code> | Desired temperature |
243
+ | authOpts | <code>Object</code> | Authentication object returned from the `login` method. |
244
+
245
+ <a name="module_nodeADC..setThermostatTargetCoolTemperature"></a>
246
+
247
+ ### nodeADC~setThermostatTargetCoolTemperature(thermostatID, newTemp, authOpts) ⇒ <code>Promise</code>
248
+ Set desired Cool setpoint temperature for Thermostat
249
+
250
+ **Kind**: inner method of [<code>nodeADC</code>](#module_nodeADC)
251
+
252
+ | Param | Type | Description |
253
+ |--------------|---------------------|---------------------------------------------------------|
254
+ | thermostatID | <code>string</code> | Thermostat ID string. |
255
+ | newTemp | <code>number</code> | Desired temperature |
256
+ | authOpts | <code>Object</code> | Authentication object returned from the `login` method. |
257
+
212
258
  <a name="module_nodeADC..armStay"></a>
213
259
 
214
260
  ### nodeADC~armStay(partitionID, authOpts, opts) ⇒ <code>Promise</code>
@@ -1,4 +1,4 @@
1
- import { GarageState, LightState, LockState, PartitionState, SensorState } from './DeviceStates';
1
+ import { GarageState, LightState, LockState, PartitionState, SensorState, ThermostatState } from './DeviceStates';
2
2
  /**
3
3
  * Response information from
4
4
  * api/systems/systems/{id}
@@ -31,6 +31,7 @@ export interface FlattenedSystemState {
31
31
  lights: LightState[];
32
32
  locks: LockState[];
33
33
  garages: GarageState[];
34
+ thermostats: ThermostatState[];
34
35
  relationships: Relationships;
35
36
  }
36
37
  export interface Relationships {
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ import { AuthOpts } from './_models/AuthOpts';
5
5
  import { ApiDeviceState } from './_models/DeviceStates';
6
6
  import { PartitionActionOptions } from './_models/PartitionActionOptions';
7
7
  import { FlattenedSystemState } from './_models/SystemState';
8
+ import { THERMOSTAT_STATES } from "./_models/States";
8
9
  export * from './_models/AuthOpts';
9
10
  export * from './_models/DeviceStates';
10
11
  export * from './_models/IdentityResponse';
@@ -139,5 +140,35 @@ export declare function closeGarage(garageID: string, authOpts: AuthOpts): Promi
139
140
  * @returns {Promise}
140
141
  */
141
142
  export declare function openGarage(garageID: string, authOpts: AuthOpts): Promise<any>;
143
+ /**
144
+ * Update thermostat state
145
+ *
146
+ * @param {string} thermostatID Thermostat ID string.
147
+ * @param {Object} newState New desired state
148
+ * @param {Object} authOpts Authentication object returned from the `login`
149
+ * method.
150
+ * @returns {Promise}
151
+ */
152
+ export declare function setThermostatState(thermostatID: string, newState: THERMOSTAT_STATES, authOpts: AuthOpts): Promise<any>;
153
+ /**
154
+ * Sets a thermostat target heat temperature.
155
+ *
156
+ * @param {string} thermostatID ThermostatID ID string.
157
+ * @param {number} newTemp New target temperature
158
+ * @param {Object} authOpts Authentication object returned from the `login`
159
+ * method.
160
+ * @returns {Promise}
161
+ */
162
+ export declare function setThermostatTargetHeatTemperature(thermostatID: string, newTemp: number, authOpts: AuthOpts): Promise<any>;
163
+ /**
164
+ * Sets a thermostat target cool temperature.
165
+ *
166
+ * @param {string} thermostatID ThermostatID ID string.
167
+ * @param {number} newTemp New target temperature
168
+ * @param {Object} authOpts Authentication object returned from the `login`
169
+ * method.
170
+ * @returns {Promise}
171
+ */
172
+ export declare function setThermostatTargetCoolTemperature(thermostatID: string, newTemp: number, authOpts: AuthOpts): Promise<any>;
142
173
  export declare function authenticatedGet(url: string, opts: any): Promise<any>;
143
174
  export declare function authenticatedPost(url: string, opts: any): Promise<any>;
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
20
20
  return (mod && mod.__esModule) ? mod : { "default": mod };
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.authenticatedPost = exports.authenticatedGet = exports.openGarage = exports.closeGarage = exports.setLockUnsecure = exports.setLockSecure = exports.setLightOff = exports.setLightOn = exports.disarm = exports.armAway = exports.armStay = exports.getComponents = exports.getCurrentState = exports.login = void 0;
23
+ exports.authenticatedPost = exports.authenticatedGet = exports.setThermostatTargetCoolTemperature = exports.setThermostatTargetHeatTemperature = exports.setThermostatState = exports.openGarage = exports.closeGarage = exports.setLockUnsecure = exports.setLockSecure = exports.setLightOff = exports.setLightOn = exports.disarm = exports.armAway = exports.armStay = exports.getComponents = exports.getCurrentState = exports.login = void 0;
24
24
  const node_fetch_1 = __importDefault(require("node-fetch"));
25
25
  __exportStar(require("./_models/AuthOpts"), exports);
26
26
  __exportStar(require("./_models/DeviceStates"), exports);
@@ -38,6 +38,7 @@ const PARTITIONS_URL = 'https://www.alarm.com/web/api/devices/partitions/';
38
38
  const SENSORS_URL = 'https://www.alarm.com/web/api/devices/sensors';
39
39
  const LIGHTS_URL = 'https://www.alarm.com/web/api/devices/lights/';
40
40
  const GARAGE_URL = 'https://www.alarm.com/web/api/devices/garageDoors/';
41
+ const THERMOSTAT_URL = 'https://www.alarm.com/web/api/devices/thermostats/';
41
42
  const LOCKS_URL = 'https://www.alarm.com/web/api/devices/locks/';
42
43
  // eslint-disable-next-line @typescript-eslint/no-var-requires
43
44
  const UA = `node-alarm-dot-com/${require('../package.json').version}`;
@@ -170,6 +171,10 @@ async function getCurrentState(systemID, authOpts) {
170
171
  if (typeof garageIDs[0] !== 'undefined') {
171
172
  components.set('garages', await getComponents(GARAGE_URL, garageIDs, authOpts));
172
173
  }
174
+ const thermostatIDs = rels.thermostats.data.map(thermostat => thermostat.id);
175
+ if (typeof thermostatIDs[0] !== 'undefined') {
176
+ components.set('thermostats', await getComponents(THERMOSTAT_URL, thermostatIDs, authOpts));
177
+ }
173
178
  return {
174
179
  id: res.data.id,
175
180
  attributes: res.data.attributes,
@@ -180,6 +185,7 @@ async function getCurrentState(systemID, authOpts) {
180
185
  lights: components.has('lights') ? components.get('lights').data : [],
181
186
  locks: components.has('locks') ? components.get('locks').data : [],
182
187
  garages: components.has('garages') ? components.get('garages').data : [],
188
+ thermostats: components.has('thermostats') ? components.get('thermostats').data : [],
183
189
  relationships: rels
184
190
  };
185
191
  }
@@ -481,6 +487,67 @@ function openGarage(garageID, authOpts) {
481
487
  return authenticatedPost(url, postOpts);
482
488
  }
483
489
  exports.openGarage = openGarage;
490
+ // Thermostat methods ////////////////////////////////////////////////////////////////
491
+ /**
492
+ * Update thermostat state
493
+ *
494
+ * @param {string} thermostatID Thermostat ID string.
495
+ * @param {Object} newState New desired state
496
+ * @param {Object} authOpts Authentication object returned from the `login`
497
+ * method.
498
+ * @returns {Promise}
499
+ */
500
+ function setThermostatState(thermostatID, newState, authOpts) {
501
+ const url = `${THERMOSTAT_URL}${thermostatID}/setState`;
502
+ const postOpts = Object.assign({}, authOpts, {
503
+ body: {
504
+ desiredState: newState,
505
+ statePollOnly: false
506
+ }
507
+ });
508
+ return authenticatedPost(url, postOpts);
509
+ }
510
+ exports.setThermostatState = setThermostatState;
511
+ /**
512
+ * Sets a thermostat target heat temperature.
513
+ *
514
+ * @param {string} thermostatID ThermostatID ID string.
515
+ * @param {number} newTemp New target temperature
516
+ * @param {Object} authOpts Authentication object returned from the `login`
517
+ * method.
518
+ * @returns {Promise}
519
+ */
520
+ function setThermostatTargetHeatTemperature(thermostatID, newTemp, authOpts) {
521
+ const url = `${THERMOSTAT_URL}${thermostatID}/setState`;
522
+ const postOpts = Object.assign({}, authOpts, {
523
+ body: {
524
+ desiredHeatSetpoint: newTemp,
525
+ statePollOnly: false
526
+ }
527
+ });
528
+ return authenticatedPost(url, postOpts);
529
+ }
530
+ exports.setThermostatTargetHeatTemperature = setThermostatTargetHeatTemperature;
531
+ /**
532
+ * Sets a thermostat target cool temperature.
533
+ *
534
+ * @param {string} thermostatID ThermostatID ID string.
535
+ * @param {number} newTemp New target temperature
536
+ * @param {Object} authOpts Authentication object returned from the `login`
537
+ * method.
538
+ * @returns {Promise}
539
+ */
540
+ function setThermostatTargetCoolTemperature(thermostatID, newTemp, authOpts) {
541
+ const url = `${THERMOSTAT_URL}${thermostatID}/setState`;
542
+ const postOpts = Object.assign({}, authOpts, {
543
+ body: {
544
+ desiredCoolSetpoint: newTemp,
545
+ statePollOnly: false
546
+ }
547
+ });
548
+ return authenticatedPost(url, postOpts);
549
+ }
550
+ exports.setThermostatTargetCoolTemperature = setThermostatTargetCoolTemperature;
484
551
  // Helper methods //////////////////////////////////////////////////////////////
485
552
  function getValue(data, path) {
486
553
  if (typeof path === 'string') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-alarm-dot-com",
3
- "version": "2.1.0-beta.3",
3
+ "version": "2.1.0-beta.5",
4
4
  "betaVersion": "2.1.0",
5
5
  "description": "An interface module written in node.js to arm and disarm Alarm.com security systems.",
6
6
  "author": {