mirror of
https://github.com/skydiver/ewelink-api.git
synced 2025-12-24 06:28:30 +01:00
getDevice: use v2 API
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user