mirror of
https://github.com/skydiver/ewelink-api.git
synced 2025-12-21 13:23:05 +01:00
* Added arpTableSolver (#18) * Added arpTableSolver * fix package import * linting class * changed arp library * refactor arp class * using arpping fork * refactor arpTableSolver class * Added Zero Conf functionality (LAN mode) (#46) * added crypto-js * zeroconf helper functions * zeroconf update payload * new method to save devices cache file * class renamed * refactor Zeroconf class * return cached device if exists * moved method to get local ip address * fix mac addresses without leading zeroes * refactor Zeroconf class * using new zeroconf functionality * zeroconf working with single and multichannel devices * save device mixin enhancement * working on zeroconf test cases * catch errors on filesystem methods * zeroconf: added extra test cases * better error handling * zeroconf: 100% code coverage * removed deprecated login method * updates on credentials file * version bump * Docs for v2.0 (#52) * added v1 docs * added zeroconf docs * updated readme * docs updated * removed zeroconf article warning * updated vscode config Co-authored-by: Luis Llamas <luisllamas@hotmail.com>
76 lines
2.3 KiB
JavaScript
76 lines
2.3 KiB
JavaScript
const delay = require('delay');
|
|
|
|
const ewelink = require('../main');
|
|
|
|
const {
|
|
email,
|
|
password,
|
|
deviceIdWithPower,
|
|
} = require('./_setup/credentials.js');
|
|
|
|
const {
|
|
rawPowerUsageExpectations,
|
|
currentMonthPowerUsageExpectations,
|
|
} = require('./_setup/expectations');
|
|
|
|
describe('power usage: node script', () => {
|
|
let conn;
|
|
|
|
beforeAll(async () => {
|
|
conn = new ewelink({ email, password });
|
|
await conn.getCredentials();
|
|
});
|
|
|
|
beforeEach(async () => {
|
|
await delay(1000);
|
|
});
|
|
|
|
test('should return raw power usage', async () => {
|
|
jest.setTimeout(30000);
|
|
const powerUsage = await conn.getDeviceRawPowerUsage(deviceIdWithPower);
|
|
expect(typeof powerUsage).toBe('object');
|
|
expect(powerUsage).toMatchObject(rawPowerUsageExpectations);
|
|
expect(powerUsage.data.hundredDaysKwhData.length).toBe(600);
|
|
});
|
|
|
|
test('should return current month power usage', async () => {
|
|
jest.setTimeout(30000);
|
|
const days = new Date().getDate();
|
|
const powerUsage = await conn.getDevicePowerUsage(deviceIdWithPower);
|
|
expect(typeof powerUsage).toBe('object');
|
|
expect(powerUsage).toMatchObject(currentMonthPowerUsageExpectations);
|
|
expect(powerUsage.daily.length).toBe(days);
|
|
});
|
|
});
|
|
|
|
describe('power usage: serverless', () => {
|
|
let accessToken;
|
|
let apiKey;
|
|
|
|
beforeAll(async () => {
|
|
const conn = new ewelink({ email, password });
|
|
const credentials = await conn.getCredentials();
|
|
accessToken = credentials.at;
|
|
apiKey = credentials.user.apikey;
|
|
});
|
|
|
|
test('should return raw power usage', async () => {
|
|
jest.setTimeout(30000);
|
|
const conn = new ewelink({ at: accessToken, apiKey });
|
|
const powerUsage = await conn.getDeviceRawPowerUsage(deviceIdWithPower);
|
|
expect(typeof powerUsage).toBe('object');
|
|
expect(powerUsage).toMatchObject(rawPowerUsageExpectations);
|
|
expect(powerUsage.data.hundredDaysKwhData.length).toBe(600);
|
|
});
|
|
|
|
test('should return current month power usage', async () => {
|
|
jest.setTimeout(30000);
|
|
const days = new Date().getDate();
|
|
const conn = new ewelink({ at: accessToken, apiKey });
|
|
const powerUsage = await conn.getDevicePowerUsage(deviceIdWithPower);
|
|
expect(typeof powerUsage).toBe('object');
|
|
expect(powerUsage).toMatchObject(currentMonthPowerUsageExpectations);
|
|
expect(powerUsage.daily.length).toBe(days);
|
|
});
|
|
});
|