Files
ewelink-api/src/mixins/getDevices.js
2020-10-21 20:12:50 -03:00

29 lines
651 B
JavaScript

const { _get } = require('../helpers/utilities');
const errors = require('../data/errors');
module.exports = {
/**
* Get all devices information
*
* @returns {Promise<{msg: string, error: number}|*>}
*/
async getDevices() {
const response = await this.makeRequest({
uri: `/v2/device/thing/`,
});
const error = _get(response, 'error', false);
const thingList = _get(response, 'thingList', false);
if (error) {
throw new Error(`[${error}] ${errors[error]}`);
}
if (!thingList) {
throw new Error(`${errors.noDevices}`);
}
return thingList.map((thing) => thing.itemData);
},
};