Skip to content

Commit c11b3a8

Browse files
authored
Release v3.0.0 (#85)
* updated dependencies * code linting * added new app id & app secret * cleanup requests payloads * remove unused function * update test cases * enabled firmware tests * refactor getDevice to use right api endpoint * error messages improvements * error messages improvements * error messages improvements * error messages improvements * error messages improvements * payload cleanup * refactor setDevicePowerState to use right api endpoint * update test exepectation * removed deprecated class * updated tests to reflect new error codes * error messages improvements * refactoring project structure: devices methods refactoring project sturcture * refactoring project structure: firmware methods * refactoring project structure: temperature/humidity * refactoring project structure: credentials methods * refactoring project structure: power usage methods * refactoring project structure: power state methods * refactoring project structure: websocket methods * removed deprecated login method from docs * refactoring project structure: power usage methods * refactoring project structure: zeroconf classes * refactoring project structure: websocket classes * refactoring project structure: zeroconf classes * refactor and cleanup * refactoring project structure: firmware methods * moved parsers to own directory * update tests with methods renames * export missing temperature/humidity methods * removed unused package * refactor and cleanup * fix test expectation * refactoring project structure: moved data files * refactoring project structure: moved data files * refactoring project structure: moved helpers files * refactoring project structure: moved helpers files * refactoring project structure: moved payload files * refactor and cleanup * refactor getDevicePowerState * setDevicePowerState returns channel * convert error 400 to 404 for clarity * updated test cases * remove console.log * cache path for zeroconf cache files * installed nock * using nock to simulate server requests during testing * moved credentials file to config folder * update request url when using nock * refactor nock helper file * move cooldown delay to setupTests file * updating testing instructions * restored delete code block * fix wrong error code * accept phone number to login to ewelink * added test cases for initialize main class * improvements on class initialization parameters * allow login using phone number * rename test file * updated test case * fixed regression bug * Release v3.0.0 - use node-fetch (#87) * replaced deprecated request library with node-fetch * refactor: moved makeRequest to own mixin file * refactor to use node-fetch * fixes * update config * created helper method * constant rename * ignore files from final package * version bump
1 parent 04ba4a1 commit c11b3a8

File tree

79 files changed

+6007
-3249
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+6007
-3249
lines changed

.npmignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.idea/
2+
.vscode/
3+
docs/
4+
test/
5+
.editorconfig
6+
.eslintrc
7+
arp-table.json
8+
demo.js
9+
devices-cache.json

classes/PowerState/ChangeState.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

classes/PowerState/index.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

classes/PowerUsage/CurrentMonth.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

classes/PowerUsage/index.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@
2222
* [getRegion](available-methods/getregion.md)
2323
* [getFirmwareVersion](available-methods/getfirmwareversion.md)
2424
* [saveDevicesCache](available-methods/savedevicescache.md)
25-
* [login](available-methods/login.md) <sup>_*deprecated_</sup>
2625
* [Zeroconf (LAN mode)](zeroconf.md)
2726
* [Testing](testing.md)

docs/available-methods/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Here is the list of available methods.
1717
* [getRegion](getregion.md)
1818
* [getFirmwareVersion](getfirmwareversion.md)
1919
* [saveDevicesCache](savedevicescache.md)
20-
* [login](login.md) <sup>_*deprecated_</sup>
2120

2221
Remember to instantiate class before usage.
2322

docs/available-methods/getdevicepowerstate.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Query for specified device power status.
2222
```js
2323
{
2424
status: 'ok',
25-
state: 'off'
25+
state: 'off',
26+
channel: 1
2627
}
2728
```

docs/available-methods/login.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

docs/available-methods/openwebsocket.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const connection = new ewelink({
1919
});
2020

2121
// login into eWeLink
22-
await connection.login();
22+
await connection.getCredentials();
2323

2424
// call openWebSocket method with a callback as argument
2525
const socket = await connection.openWebSocket(async data => {

docs/available-methods/setdevicepowerstate.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Possible states: `on`, `off`, `toggle`.
2424
```js
2525
{
2626
status: 'ok',
27-
state: 'on'
27+
state: 'on',
28+
channel: 1
2829
}
2930
```

docs/class-instantiation.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
});
1212
```
1313

14+
**_Using phone number and password_**
15+
```
16+
const connection = new ewelink({
17+
phoneNumber: '<your phone number>',
18+
password: '<your ewelink password>',
19+
region: '<your ewelink region>',
20+
});
21+
```
22+
1423
**_Using access token and api key_**
1524
```
1625
const connection = new ewelink({
@@ -20,5 +29,8 @@
2029
});
2130
```
2231

32+
**_Using devices and arp table cache files_**
33+
Check [ZeroConf](zeroconf.md) docs for detailed information.
34+
2335
> * If you don't know your region, use [getRegion](available-methods/getregion) method
2436
> * To get your access token and api key, use [getCredentials](available-methods/getcredentials) method

docs/demos/serverless.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ So, instead of using email and password on every api call, you can login the fir
1717
region: '<your ewelink region>',
1818
});
1919

20-
const login = await connection.login();
20+
const credentials = await connection.getCredentials();
2121

22-
const accessToken = login.at;
23-
const apiKey = login.user.apikey
24-
const region = login.region;
22+
const accessToken = credentials.at;
23+
const apiKey = credentials.user.apikey
24+
const region = credentials.region;
2525

2626
})();
2727
```

docs/testing.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
11
# Testing
22

3-
Open `test/_setup/credentials.json` and update parameters.
3+
## Run test suite
4+
Copy `test/_setup/config/credentials.example.js` to `test/_setup/config/credentials.js` and update parameters with yours.
45

56
In a terminal, `npm run test` or `npm run coverage`.
67

8+
Tests needs to be performed serially to prevent flooding eWeLink servers, so if run jest manually, add `--runInBand` parameter.
79

8-
> tests needs to be performed serially, so if run jest manually, add `--runInBand` parameter.
10+
> All devices needs to be connected before running test suite.
11+
12+
13+
## Using nock
14+
Running tests can take some time because there is many requests to eWeLink servers.
15+
16+
To speedup this process, you need to enable nock "record & play" feature by opening `test/_setup/setupTests.js` and change `nockAction` to `record` or `play`.
17+
18+
The first time you need to record all your requests then you can keep testing by "playing" recorded data.
19+
20+
Recorded data will be stored on `test/_setup/tapes` and you can delete folder content anytime.
21+
22+
Set `nockAction` to `false` to disable all nock functionality.
23+
24+
25+
## ZeroConf cache
26+
While testing ZeroConf functionalty, two temporary files will be created: `test/_setup/cache/arp-table.json` and `test/_setup/cache devices-cache.json`. These files can be safely deleted once tests finished.

docs/zeroconf.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ A file named `devices-cache.json` will be created.
3535
## 2. Generate arp table cache file
3636

3737
```js
38-
const Zeroconf = require('ewelink-api/classes/Zeroconf');
38+
const Zeroconf = require('ewelink-api/src/classes/Zeroconf');
3939

4040
await Zeroconf.saveArpTable({
4141
ip: '<your network addres, ex: 192.168.5.1>'
@@ -49,7 +49,7 @@ A file named `arp-table.json` will be created.
4949

5050
```js
5151
const ewelink = require('ewelink-api');
52-
const Zeroconf = require('ewelink-api/classes/Zeroconf');
52+
const Zeroconf = require('ewelink-api/src/classes/Zeroconf');
5353

5454
/* load cache files */
5555
const devicesCache = await Zeroconf.loadCachedDevices();

lib/helpers.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

lib/payloads/credentialsPayload.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

lib/payloads/index.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

lib/payloads/wssLoginPayload.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)