Skip to content

Cannot toggleDevice (or getPowerState) #89

@JabLuszko

Description

@JabLuszko

I 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions