mirror of
https://github.com/skydiver/ewelink-api.git
synced 2025-12-24 22:39:26 +01:00
Release v1.8.1 (#28)
* new method to get user region * added new test * version bump
This commit is contained in:
5
main.js
5
main.js
@@ -150,6 +150,9 @@ const getFirmwareVersionMixin = require('./mixins/firmware/getFirmwareVersionMix
|
||||
const checkDeviceUpdateMixin = require('./mixins/firmware/checkDeviceUpdateMixin');
|
||||
const checkDevicesUpdatesMixin = require('./mixins/firmware/checkDevicesUpdatesMixin');
|
||||
|
||||
/* LOAD MIXINS: user */
|
||||
const regionMixin = require('./mixins/user/regionMixin');
|
||||
|
||||
/* LOAD MIXINS: websocket */
|
||||
const openWebSocketMixin = require('./mixins/websocket/openWebSocketMixin');
|
||||
|
||||
@@ -182,6 +185,8 @@ Object.assign(
|
||||
checkDevicesUpdatesMixin
|
||||
);
|
||||
|
||||
Object.assign(eWeLink.prototype, regionMixin);
|
||||
|
||||
Object.assign(eWeLink.prototype, openWebSocketMixin);
|
||||
|
||||
module.exports = eWeLink;
|
||||
|
||||
27
mixins/user/regionMixin.js
Normal file
27
mixins/user/regionMixin.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const { _get } = require('../../lib/helpers');
|
||||
|
||||
const regionMixin = {
|
||||
async getRegion() {
|
||||
if (!this.email || !this.password) {
|
||||
return {
|
||||
error: 406,
|
||||
msg: 'Library needs to be initialized using email and password',
|
||||
};
|
||||
}
|
||||
|
||||
const login = await this.login();
|
||||
|
||||
const error = _get(login, 'error', false);
|
||||
|
||||
if (error) {
|
||||
return login;
|
||||
}
|
||||
|
||||
return {
|
||||
email: login.user.email,
|
||||
region: login.region,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = regionMixin;
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ewelink-api",
|
||||
"version": "1.8.0",
|
||||
"version": "1.8.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ewelink-api",
|
||||
"version": "1.8.0",
|
||||
"version": "1.8.1",
|
||||
"description": "eWeLink API for Node.js",
|
||||
"author": "Martín M.",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"email": "<your ewelink email>",
|
||||
"password": "<your ewelink password>",
|
||||
"region": "<your ewelink region>",
|
||||
"singleChannelDeviceId": "<your device id>",
|
||||
"deviceIdWithPower": "<your device id>",
|
||||
"deviceIdWithoutPower": "<your device id>",
|
||||
|
||||
@@ -50,6 +50,11 @@ const firmwareExpectations = {
|
||||
msg: expect.any(String),
|
||||
};
|
||||
|
||||
const regionExpectations = {
|
||||
email: expect.any(String),
|
||||
region: expect.any(String),
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
loginExpectations,
|
||||
allDevicesExpectations,
|
||||
@@ -57,4 +62,5 @@ module.exports = {
|
||||
rawPowerUsageExpectations,
|
||||
currentMonthPowerUsageExpectations,
|
||||
firmwareExpectations,
|
||||
regionExpectations,
|
||||
};
|
||||
|
||||
21
test/user.spec.js
Normal file
21
test/user.spec.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const ewelink = require('../main');
|
||||
|
||||
const { email, password, region } = require('./_setup/credentials.json');
|
||||
|
||||
const { regionExpectations } = require('./_setup/expectations');
|
||||
|
||||
describe('check user information', () => {
|
||||
let connection;
|
||||
|
||||
beforeAll(() => {
|
||||
connection = new ewelink({ email, password });
|
||||
});
|
||||
|
||||
test('region should be returned', async () => {
|
||||
const response = await connection.getRegion();
|
||||
expect(response).toMatchObject(regionExpectations);
|
||||
expect(typeof response).toBe('object');
|
||||
expect(response.email).toBe(email);
|
||||
expect(response.region).toBe(region);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user