diff --git a/src/data/errors.js b/src/data/errors.js index 60030a6..d5926bd 100644 --- a/src/data/errors.js +++ b/src/data/errors.js @@ -11,6 +11,7 @@ const errors = { const customErrors = { ch404: 'Device channel does not exist', unknown: 'An unknown error occurred', + noDevice: 'No device found', noDevices: 'No devices found', noPower: 'No power usage data found', noSensor: "Can't read sensor data from device", diff --git a/src/mixins/getDevice.js b/src/mixins/getDevice.js index f3910a8..be08375 100644 --- a/src/mixins/getDevice.js +++ b/src/mixins/getDevice.js @@ -1,4 +1,4 @@ -const { nonce, timestamp, _get } = require('../helpers/utilities'); +const { _get } = require('../helpers/utilities'); const errors = require('../data/errors'); module.exports = { @@ -16,13 +16,12 @@ module.exports = { const { APP_ID } = this; const device = await this.makeRequest({ - uri: `/user/device/${deviceId}`, - qs: { - deviceid: deviceId, - appid: APP_ID, - nonce, - ts: timestamp, - version: 8, + method: 'post', + uri: `/v2/device/thing/`, + body: { + thingList: [ + { id: deviceId, itemType: 1 } + ] }, }); @@ -32,6 +31,10 @@ module.exports = { return { error, msg: errors[error] }; } - return device; + if (device.thingList.length === 0) { + throw new Error(`${errors.noDevice}`); + } + + return device.thingList.shift().itemData; }, };