Skip to content

Commit 3cd9b98

Browse files
committed
getDevice: use v2 API
1 parent 1f7edc0 commit 3cd9b98

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/data/errors.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const errors = {
1111
const customErrors = {
1212
ch404: 'Device channel does not exist',
1313
unknown: 'An unknown error occurred',
14+
noDevice: 'No device found',
1415
noDevices: 'No devices found',
1516
noPower: 'No power usage data found',
1617
noSensor: "Can't read sensor data from device",

src/mixins/getDevice.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { nonce, timestamp, _get } = require('../helpers/utilities');
1+
const { _get } = require('../helpers/utilities');
22
const errors = require('../data/errors');
33

44
module.exports = {
@@ -16,13 +16,12 @@ module.exports = {
1616
const { APP_ID } = this;
1717

1818
const device = await this.makeRequest({
19-
uri: `/user/device/${deviceId}`,
20-
qs: {
21-
deviceid: deviceId,
22-
appid: APP_ID,
23-
nonce,
24-
ts: timestamp,
25-
version: 8,
19+
method: 'post',
20+
uri: `/v2/device/thing/`,
21+
body: {
22+
thingList: [
23+
{ id: deviceId, itemType: 1 }
24+
]
2625
},
2726
});
2827

@@ -32,6 +31,10 @@ module.exports = {
3231
return { error, msg: errors[error] };
3332
}
3433

35-
return device;
34+
if (device.thingList.length === 0) {
35+
throw new Error(`${errors.noDevice}`);
36+
}
37+
38+
return device.thingList.shift().itemData;
3639
},
3740
};

0 commit comments

Comments
 (0)