mirror of
https://github.com/skydiver/ewelink-api.git
synced 2025-12-21 21:33:11 +01:00
29 lines
651 B
JavaScript
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);
|
|
},
|
|
};
|