mirror of
https://github.com/skydiver/ewelink-api.git
synced 2025-12-21 21:33:11 +01:00
Release v1.4.1 (#13)
* specific error when requested channel is bigger than total * fix for multi-channel devices * updated test expectations * fixes with uiid api changes * fix wrong error message * added new test cases * return expected error on wrong channel number * added more devices * version bump
This commit is contained in:
33
main.js
33
main.js
@@ -165,11 +165,18 @@ class eWeLink {
|
||||
async getDevicePowerState(deviceId, channel = 1) {
|
||||
const device = await this.getDevice(deviceId);
|
||||
const error = _get(device, 'error', false);
|
||||
const uiid = _get(device, 'extra.extra.uiid', false);
|
||||
|
||||
let state = _get(device, 'params.switch', false);
|
||||
const switches = _get(device, 'params.switches', false);
|
||||
const switchesAmount = getDeviceChannelCount(device.uiid);
|
||||
|
||||
if (error || switchesAmount < channel || (!state && !switches)) {
|
||||
const switchesAmount = getDeviceChannelCount(uiid);
|
||||
|
||||
if (switchesAmount > 0 && switchesAmount < channel) {
|
||||
return { error, msg: 'Device channel does not exist' };
|
||||
}
|
||||
|
||||
if (error || (!state && !switches)) {
|
||||
if (error && parseInt(error) === 401) {
|
||||
return device;
|
||||
}
|
||||
@@ -195,11 +202,18 @@ class eWeLink {
|
||||
async setDevicePowerState(deviceId, state, channel = 1) {
|
||||
const device = await this.getDevice(deviceId);
|
||||
const error = _get(device, 'error', false);
|
||||
const status = _get(device, 'params.switch', false);
|
||||
const switches = _get(device, 'params.switches', false);
|
||||
const switchesAmount = getDeviceChannelCount(device.uiid);
|
||||
const uiid = _get(device, 'extra.extra.uiid', false);
|
||||
|
||||
if (error || switchesAmount < channel || (!status && !switches)) {
|
||||
let status = _get(device, 'params.switch', false);
|
||||
const switches = _get(device, 'params.switches', false);
|
||||
|
||||
const switchesAmount = getDeviceChannelCount(uiid);
|
||||
|
||||
if (switchesAmount > 0 && switchesAmount < channel) {
|
||||
return { error, msg: 'Device channel does not exist' };
|
||||
}
|
||||
|
||||
if (error || (!status && !switches)) {
|
||||
if (error && parseInt(error) === 401) {
|
||||
return device;
|
||||
}
|
||||
@@ -207,13 +221,16 @@ class eWeLink {
|
||||
}
|
||||
|
||||
let stateToSwitch = state;
|
||||
const params = {};
|
||||
|
||||
if (switches) {
|
||||
status = switches[channel - 1].switch;
|
||||
}
|
||||
|
||||
if (state === 'toggle') {
|
||||
stateToSwitch = status === 'on' ? 'off' : 'on';
|
||||
}
|
||||
|
||||
const params = {};
|
||||
|
||||
if (switches) {
|
||||
params.switches = switches;
|
||||
params.switches[channel - 1].switch = stateToSwitch;
|
||||
|
||||
Reference in New Issue
Block a user