node-alarm-dot-com 2.1.0-beta.2 → 2.1.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,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,3 +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>;
173
+ export declare function authenticatedGet(url: string, opts: any): Promise<any>;
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.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') {
@@ -502,6 +569,7 @@ async function authenticatedGet(url, opts) {
502
569
  const res = await get(url, opts);
503
570
  return res.body;
504
571
  }
572
+ exports.authenticatedGet = authenticatedGet;
505
573
  async function authenticatedPost(url, opts) {
506
574
  opts = opts || {};
507
575
  opts.headers = opts.headers || {};
@@ -514,6 +582,7 @@ async function authenticatedPost(url, opts) {
514
582
  const res = await post(url, opts);
515
583
  return res.body;
516
584
  }
585
+ exports.authenticatedPost = authenticatedPost;
517
586
  async function get(url, opts) {
518
587
  opts = opts || {};
519
588
  let status;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-alarm-dot-com",
3
- "version": "2.1.0-beta.2",
3
+ "version": "2.1.0-beta.4",
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": {