getDeviceChannelCount: use v2 API

This commit is contained in:
Martín M
2020-10-21 21:24:17 -03:00
parent ad2d72f4ce
commit 894aa6f5ca

View File

@@ -1,7 +1,4 @@
const { _get } = require('../helpers/utilities');
const errors = require('../data/errors');
const { getDeviceChannelCount } = require('../helpers/ewelink');
module.exports = {
/**
@@ -13,12 +10,18 @@ module.exports = {
*/
async getDeviceChannelCount(deviceId) {
const device = await this.getDevice(deviceId);
const error = _get(device, 'error', false);
const uiid = _get(device, 'extra.extra.uiid', false);
const switchesAmount = getDeviceChannelCount(uiid);
if (error) {
return { error, msg: errors[error] };
const paramSwitch = _get(device, 'params.switch', false);
const paramSwitches = _get(device, 'params.switches', false);
let switchesAmount;
if (paramSwitches) {
switchesAmount = paramSwitches.length;
}
if (!paramSwitches && paramSwitch) {
switchesAmount = 1;
}
return { status: 'ok', switchesAmount };