Cannot toggleDevice (or getPowerState)
See original GitHub issueI can login, get device list for more info, however I cannot toggleDevice - the ewelink API returns HTTP 500, however payload/URL seems correct according to theirs docs in https://github.com/CoolKit-Technologies/apiDocs/blob/master/en/APICenter.md#http-update-device-status Sample code:
const ewelink = require('ewelink-api');
(async () => {
const connection = new ewelink({
email: 'validemail@in.valid.domain',
password: 'validpassword',
region: 'eu',
});
/* get all devices */
const devices = await connection.getDevices();
console.log(devices);
for (device in devices) {
console.log("Name: " + devices[device]["name"]);
console.log("DeviceID: " + devices[device]["deviceid"]);
console.log("ProductModel: " + devices[device]["productModel"]);
const device_info = await connection.getDevice(devices[device]["deviceid"]);
console.log(device_info["productModel"]);
if (device_info["productModel"] === "BASICR2") {
console.log("Toggling this one")
const status = await connection.toggleDevice(devices[device]["deviceid"]);
console.log(status);
}
}
})();
Iβve added some console.log to see what is happening and when calling toggleDevice I can see itβs successfully asking for device state (via const device = await this.getDevice(deviceId);
) and correctly resolving the switch state (on/off), but when actually trying to turn it off/on the ewelink API ends with HTTP 500.
URL: https://eu-api.coolkit.cc:8080/api/user/device/status
PAYLOAD:
{ method: 'post',
headers:
{ Authorization: 'Bearer <validauthorizationthatwasusedfewtimesalready>',
'Content-Type': 'application/json' },
body:
'{"deviceid":"<validdeviceidfromloop>","params":{"switch":"off"},"appid":"YzfeftUVcZ6twZw1OoVKPRFYTrGEg01Q","nonce":"itj22djr","ts":1590686206,"version":8}' }
SERVER_RESP: <h2>Internal Server Error, real status: 500</h2>
(node:23243) UnhandledPromiseRejectionWarning: FetchError: invalid json response body at https://eu-api.coolkit.cc:8080/api/user/device/status reason: Unexpected token < in JSON at position 0
at node_modules/node-fetch/lib/index.js:273:32
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:23243) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:23243) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
It could be (somehow?) worth noticing that this device is shared to this ewelink account. I also see a lot of strange things with ewelink API - βfd is nullβ or βdevice not foundβ when asking for getDevice (however they were just successfully listed via getDevices). However after few fails if I open original ewelink app it starts to report correct data for getDevice (I guess normal apps calls something more and populate (?) theirs cache)
EDIT Just tested on βmainβ (not shared to) ewelink account - same behavior - HTTP 500. So I would assume βsharedβ device is not an issue here.
$ npm list
βββ¬ ewelink-api@3.0.0
βββ¬ arpping@0.3.1 (github:skydiver/arpping#ae65410343bdcbddb64b37ac9f674c65af1fe92c)
β βββ child_process@1.0.2
β βββ os@0.1.1
βββ crypto-js@4.0.0
βββ delay@4.3.0
βββ node-fetch@2.6.0
βββ¬ random@2.2.0
β βββ¬ babel-runtime@6.26.0
β β βββ core-js@2.6.11
β β βββ regenerator-runtime@0.11.1
β βββ ow@0.4.0
β βββ ow-lite@0.0.2
β βββ seedrandom@3.0.5
βββ¬ websocket@1.0.31
β βββ¬ debug@2.6.9
β β βββ ms@2.0.0
β βββ¬ es5-ext@0.10.53
β β βββ¬ es6-iterator@2.0.3
β β β βββ¬ d@1.0.1
β β β β βββ es5-ext@0.10.53 deduped
β β β β βββ type@1.2.0
β β β βββ es5-ext@0.10.53 deduped
β β β βββ es6-symbol@3.1.3 deduped
β β βββ¬ es6-symbol@3.1.3
β β β βββ d@1.0.1 deduped
β β β βββ¬ ext@1.4.0
β β β βββ type@2.0.0
β β βββ next-tick@1.0.0
β βββ nan@2.14.1
β βββ¬ typedarray-to-buffer@3.1.5
β β βββ is-typedarray@1.0.0
β βββ yaeti@0.0.6
βββ¬ websocket-as-promised@1.0.1
βββ chnl@1.2.0
βββ promise-controller@1.0.0
βββ¬ promise.prototype.finally@3.1.2
βββ¬ define-properties@1.1.3
β βββ object-keys@1.1.1
βββ¬ es-abstract@1.17.5
β βββ¬ es-to-primitive@1.2.1
β β βββ is-callable@1.1.5 deduped
β β βββ is-date-object@1.0.2
β β βββ¬ is-symbol@1.0.3
β β βββ has-symbols@1.0.1 deduped
β βββ function-bind@1.1.1 deduped
β βββ¬ has@1.0.3
β β βββ function-bind@1.1.1 deduped
β βββ has-symbols@1.0.1
β βββ is-callable@1.1.5
β βββ¬ is-regex@1.0.5
β β βββ has@1.0.3 deduped
β βββ object-inspect@1.7.0
β βββ object-keys@1.1.1 deduped
β βββ¬ object.assign@4.1.0
β β βββ define-properties@1.1.3 deduped
β β βββ function-bind@1.1.1 deduped
β β βββ has-symbols@1.0.1 deduped
β β βββ object-keys@1.1.1 deduped
β βββ¬ string.prototype.trimleft@2.1.2
β β βββ define-properties@1.1.3 deduped
β β βββ es-abstract@1.17.5 deduped
β β βββ¬ string.prototype.trimstart@1.0.1
β β βββ define-properties@1.1.3 deduped
β β βββ es-abstract@1.17.5 deduped
β βββ¬ string.prototype.trimright@2.1.2
β βββ define-properties@1.1.3 deduped
β βββ es-abstract@1.17.5 deduped
β βββ¬ string.prototype.trimend@1.0.1
β βββ define-properties@1.1.3 deduped
β βββ es-abstract@1.17.5 deduped
βββ function-bind@1.1.1
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:21 (12 by maintainers)
Top GitHub Comments
@skydiver getDevicePowerState fails with:
{"error":401,"errmsg":"no authorization"}
Will you be implementing a websocket version, ie: getWSDevicePowerState() ?
Thanks @skydiver , I tried the fix but, unfortunately, the same error still happen