|
| 1 | +class DeloreanES { |
| 2 | + /** |
| 3 | + * @param {String} url |
| 4 | + * @param {typeof Auth} Auth |
| 5 | + */ |
| 6 | + constructor(url, Auth) { |
| 7 | + this.service = DeloreanES.name; |
| 8 | + this.url = url; |
| 9 | + this.auth = Auth; |
| 10 | + } |
| 11 | + |
| 12 | + /** |
| 13 | + * get latest checkin timestamp of deviceId |
| 14 | + * sensors - get sensors or not |
| 15 | + * |
| 16 | + * @param {String} userId |
| 17 | + * @param {String} deviceId |
| 18 | + * @param {boolean} getSensors |
| 19 | + * @param {Array} channels |
| 20 | + */ |
| 21 | + getDeviceCheckIn(userId, deviceId, needSensors, channels) { |
| 22 | + const url = `${this.url}/devices/${deviceId}/checkin`; |
| 23 | + const query = { user_id: userId, sensors: needSensors, channels: channels }; |
| 24 | + return this.auth.send(this.service, 'GET', url, { query }); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * @param {String} userId |
| 29 | + * @param {String} deviceId |
| 30 | + * @param {Object} query |
| 31 | + * @param {String} query.type |
| 32 | + * @param {String} query.units |
| 33 | + */ |
| 34 | + getDeviceState(userId, deviceId, query) { |
| 35 | + const url = `${this.url}/devices/${deviceId}/state`; |
| 36 | + query = { ...query, user_id: userId }; |
| 37 | + return this.auth.send(this.service, 'GET', url, { query }); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * @param {String} userId |
| 42 | + * @param {String} deviceIds |
| 43 | + * @param {Object} query |
| 44 | + */ |
| 45 | + getDevicesState(userId, deviceIds, query) { |
| 46 | + const url = `${this.url}/devices/state`; |
| 47 | + query = { ...query, user_id: userId, devices: deviceIds }; |
| 48 | + return this.auth.send(this.service, 'GET', url, { query }); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @param {String} userId |
| 53 | + * @param {String} deviceId |
| 54 | + * @param {Object} query |
| 55 | + */ |
| 56 | + getDeviceTotals(userId, deviceId, query) { |
| 57 | + const url = `${this.url}/devices/${deviceId}/totals`; |
| 58 | + query = { ...query, user_id: userId }; |
| 59 | + return this.auth.send(this.service, 'GET', url, { query }); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @param {String} userId |
| 64 | + * @param {String} deviceId |
| 65 | + * @param {Object} query |
| 66 | + */ |
| 67 | + getDeviceAggregations(userId, deviceId, query) { |
| 68 | + const url = `${this.url}/devices/${deviceId}/aggregations`; |
| 69 | + query = { ...query, user_id: userId }; |
| 70 | + return this.auth.send(this.service, 'GET', url, { query }); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * @param {String} userId |
| 75 | + * @param {String} deviceId |
| 76 | + * @param {Object} query |
| 77 | + */ |
| 78 | + getDeviceReadings(userId, deviceId, query) { |
| 79 | + const url = `${this.url}/devices/${deviceId}/readings`; |
| 80 | + query = { ...query, user_id: userId }; |
| 81 | + return this.auth.send(this.service, 'GET', url, { query }); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * @param {String} userId |
| 86 | + * @param {String} deviceId |
| 87 | + * @param {Object} query |
| 88 | + */ |
| 89 | + getDeviceReportReadings(userId, deviceId, query) { |
| 90 | + const url = `${this.url}/devices/${deviceId}/readings/report`; |
| 91 | + query = { ...query, user_id: userId }; |
| 92 | + return this.auth.send(this.service, 'GET', url, { query }); |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +module.exports = DeloreanES; |
0 commit comments