Release v3.1.0 (#93)

* 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
This commit is contained in:
Martin M
2020-10-12 19:01:57 -03:00
committed by GitHub
parent c11b3a8ab7
commit b87d092a71
28 changed files with 2329 additions and 2061 deletions

View File

@@ -13,6 +13,8 @@
* [getDevices](available-methods/getdevices.md)
* [getDevicePowerState](available-methods/getdevicepowerstate.md)
* [setDevicePowerState](available-methods/setdevicepowerstate.md)
* [getWSDevicePowerState](available-methods/getwsdevicepowerstate.md)
* [setWSDevicePowerState](available-methods/setwsdevicepowerstate.md)
* [toggleDevice](available-methods/toggledevice.md)
* [getDevicePowerUsage](available-methods/getdevicepowerusage.md)
* [getDeviceCurrentTH](available-methods/getdevicecurrentth.md)

View File

@@ -8,6 +8,8 @@ Here is the list of available methods.
* [getDevices](getdevices.md)
* [getDevicePowerState](getdevicepowerstate.md)
* [setDevicePowerState](setdevicepowerstate.md)
* [getWSDevicePowerState](getwsdevicepowerstate.md)
* [setWSDevicePowerState](setwsdevicepowerstate.md)
* [toggleDevice](toggledevice.md)
* [getDevicePowerUsage](getdevicepowerusage.md)
* [getDeviceCurrentTH](getdevicecurrentth.md)

View File

@@ -0,0 +1,60 @@
# getWSDevicePowerState
Query for specified device power status using WebSockets.
### Usage
```js
// get device power status
const status = await connection.getWSDevicePowerState('<your device id>');
console.log(status);
```
```js
// get device power status using a secondary account
const status = await connection.getWSDevicePowerState('<your device id>', {
shared: true,
});
console.log(status);
```
```js
// get channel 3 power status on multi-channel device
const status = await connection.getWSDevicePowerState('<your device id>', {
channel: 3,
});
console.log(status);
```
```js
// get all channels power status on multi-channel device
const status = await connection.getWSDevicePowerState('<your device id>', {
allChannels: true,
});
console.log(status);
```
<sup>* _Remember to instantiate class before use_</sup>
### Response example
```js
{
status: 'ok',
state: 'off',
channel: 1
}
```
```js
{
status: 'ok',
state: [
{ channel: 1, state: 'off' },
{ channel: 2, state: 'off' },
{ channel: 3, state: 'off' },
{ channel: 4, state: 'off' }
]
}
```

View File

@@ -0,0 +1,50 @@
# 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
}
```

View File

@@ -1,8 +1,12 @@
# Class Instantiation
> Default region of this library is `us`. If your are in a different one, **you must** specify region parameter or error 400/401 will be returned.
* Default region of this library is `us`. If your are in a different one, **you must** specify region parameter or error 400/401 will be returned.
**_Using email and password_**
* If you don't know your region, use [getRegion](available-methods/getregion) method
* To get your access token and api key, use [getCredentials](available-methods/getcredentials) method
## Using email and password
```
const connection = new ewelink({
email: '<your ewelink email>',
@@ -11,7 +15,7 @@
});
```
**_Using phone number and password_**
## Using phone number and password
```
const connection = new ewelink({
phoneNumber: '<your phone number>',
@@ -20,7 +24,7 @@
});
```
**_Using access token and api key_**
## Using access token and api key
```
const connection = new ewelink({
at: '<valid access token>',
@@ -29,8 +33,17 @@
});
```
**_Using devices and arp table cache files_**
Check [ZeroConf](zeroconf.md) docs for detailed information.
## Custom APP_ID and APP_SECRET
This library uses an APP ID and APP Secret provided by Sonoff team.
If you want to specify another pair of settings, just pass in the class constructor:
```
const connection = new ewelink({
email: '<your ewelink email>',
password: '<your ewelink password>',
APP_ID: 'CUSTOM APP ID',
APP_SECRET: 'CUSTOM APP SECRET',
});
```
> * If you don't know your region, use [getRegion](available-methods/getregion) method
> * To get your access token and api key, use [getCredentials](available-methods/getcredentials) method
## Using devices and arp table cache files
Check [ZeroConf](zeroconf.md) docs for detailed information.