From 894aa6f5ca76ae53f7ae852f949b4e4cf7c43e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marti=CC=81n=20M?= Date: Wed, 21 Oct 2020 21:24:17 -0300 Subject: [PATCH] getDeviceChannelCount: use v2 API --- src/mixins/getDeviceChannelCount.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/mixins/getDeviceChannelCount.js b/src/mixins/getDeviceChannelCount.js index e52d0c9..412b628 100644 --- a/src/mixins/getDeviceChannelCount.js +++ b/src/mixins/getDeviceChannelCount.js @@ -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 };