mirror of
https://github.com/skydiver/ewelink-api.git
synced 2025-12-26 23:21:37 +01:00
* set APP_ID and APP_SECRET from main class * add APP_ID and APP_SECRET as class constructor parameters * updated test case * updated test case * added new test case * docs updated * Release v3.1.0 - "setWSDevicePowerState" (#96) * new mixing to control devices using websocket * switch status on single channel devices * working on deviceControl mixin * better error handling * working on fix for shared devices * refactor/cleanup * added helper function * added docs for new method * return device new status * added test cases * properly close websocket connection and clean used properties * added test cases * error detection enhancements * added test cases * error detection enhancements * added new test file to jest setup * method renamed * fix for closing websocket connection * new getWSDevicePowerState method * added test cases * re-arrange tests * added new test cases * extract helpers methods * added test case * close WebSocket connection on auth error * updated docs * updated dependencies * fix for "forbidden" error * updated dependencies
50 lines
1.0 KiB
Markdown
50 lines
1.0 KiB
Markdown
# setWSDevicePowerState
|
|
|
|
Change specified device power state using WebSockets.
|
|
|
|
Possible states: `on`, `off`, `toggle`.
|
|
|
|
### Usage
|
|
```js
|
|
const status = await connection.setWSDevicePowerState('<your device id>', 'on');
|
|
console.log(status);
|
|
```
|
|
|
|
```js
|
|
// multi-channel devices like Sonoff 4CH
|
|
// example will toggle power state on channel 3
|
|
const status = await connection.setWSDevicePowerState('<your device id>', 'toggle', {
|
|
channel: 3,
|
|
});
|
|
console.log(status);
|
|
```
|
|
|
|
```js
|
|
// to control a shared device using a second account, add "shared" setting
|
|
const status = await connection.setWSDevicePowerState('<your device id>', 'off', {
|
|
shared: true
|
|
});
|
|
console.log(status);
|
|
```
|
|
|
|
```js
|
|
// turn on channel 2 on a shared multi-channel device
|
|
const status = await connection.setWSDevicePowerState('<your device id>', 'on', {
|
|
channel: 2,
|
|
shared: true
|
|
});
|
|
console.log(status);
|
|
```
|
|
|
|
|
|
<sup>* _Remember to instantiate class before use_</sup>
|
|
|
|
|
|
### Response example
|
|
```js
|
|
{
|
|
status: 'ok',
|
|
state: 'on',
|
|
channel: 1
|
|
}
|
|
``` |