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>
110 lines
3.8 KiB
JavaScript
110 lines
3.8 KiB
JavaScript
const delay = require('delay');
|
|
|
|
const ewelink = require('../main');
|
|
|
|
const {
|
|
email,
|
|
password,
|
|
singleChannelDeviceId,
|
|
fourChannelsDevice,
|
|
} = require('./_setup/credentials.js');
|
|
|
|
const {
|
|
credentialsExpectations,
|
|
allDevicesExpectations,
|
|
specificDeviceExpectations,
|
|
} = require('./_setup/expectations');
|
|
|
|
describe('env: serverless', () => {
|
|
let accessToken;
|
|
let apiKey;
|
|
|
|
beforeEach(async () => {
|
|
await delay(1000);
|
|
});
|
|
|
|
test('get ewelink credentials', async () => {
|
|
const conn = new ewelink({ email, password });
|
|
const credentials = await conn.getCredentials();
|
|
accessToken = credentials.at;
|
|
apiKey = credentials.user.apikey;
|
|
expect(typeof credentials).toBe('object');
|
|
expect(credentials).toMatchObject(credentialsExpectations);
|
|
});
|
|
|
|
test('get all devices', async () => {
|
|
const conn = new ewelink({ at: accessToken });
|
|
const devices = await conn.getDevices();
|
|
expect(Array.isArray(devices)).toBe(true);
|
|
expect(devices[0]).toMatchObject(allDevicesExpectations);
|
|
});
|
|
|
|
test('get specific device', async () => {
|
|
const conn = new ewelink({ at: accessToken });
|
|
const device = await conn.getDevice(singleChannelDeviceId);
|
|
expect(typeof device).toBe('object');
|
|
expect(device.deviceid).toBe(singleChannelDeviceId);
|
|
expect(device).toMatchObject(specificDeviceExpectations);
|
|
});
|
|
|
|
test('get device power state', async () => {
|
|
const conn = new ewelink({ at: accessToken });
|
|
const device = await conn.getDevice(singleChannelDeviceId);
|
|
const currentState = device.params.switch;
|
|
const powerState = await conn.getDevicePowerState(singleChannelDeviceId);
|
|
expect(typeof powerState).toBe('object');
|
|
expect(powerState.status).toBe('ok');
|
|
expect(powerState.state).toBe(currentState);
|
|
});
|
|
|
|
test('set device power state', async () => {
|
|
jest.setTimeout(30000);
|
|
const conn = new ewelink({ at: accessToken, apiKey });
|
|
const device = await conn.getDevice(singleChannelDeviceId);
|
|
const currentState = device.params.switch;
|
|
const newState = currentState === 'on' ? 'off' : 'on';
|
|
const powerState = await conn.setDevicePowerState(
|
|
singleChannelDeviceId,
|
|
newState
|
|
);
|
|
expect(typeof powerState).toBe('object');
|
|
expect(powerState.status).toBe('ok');
|
|
expect(powerState.state).toBe(newState);
|
|
const deviceVerify = await conn.getDevice(singleChannelDeviceId);
|
|
const currentStateVerify = deviceVerify.params.switch;
|
|
expect(newState).toBe(currentStateVerify);
|
|
});
|
|
|
|
test('toggle device power state', async () => {
|
|
jest.setTimeout(30000);
|
|
const conn = new ewelink({ at: accessToken, apiKey });
|
|
const device = await conn.getDevice(singleChannelDeviceId);
|
|
const currentState = device.params.switch;
|
|
const newState = currentState === 'on' ? 'off' : 'on';
|
|
await conn.toggleDevice(singleChannelDeviceId);
|
|
const deviceVerify = await conn.getDevice(singleChannelDeviceId);
|
|
const currentStateVerify = deviceVerify.params.switch;
|
|
expect(newState).toBe(currentStateVerify);
|
|
await conn.toggleDevice(singleChannelDeviceId);
|
|
const deviceVerifyAgain = await conn.getDevice(singleChannelDeviceId);
|
|
const currentStateVerifyAgain = deviceVerifyAgain.params.switch;
|
|
expect(currentState).toBe(currentStateVerifyAgain);
|
|
});
|
|
|
|
test('get channel count 1', async () => {
|
|
const conn = new ewelink({ at: accessToken });
|
|
const result = await conn.getDeviceChannelCount(singleChannelDeviceId);
|
|
expect(typeof result).toBe('object');
|
|
expect(result.status).toBe('ok');
|
|
expect(result.switchesAmount).toBe(1);
|
|
});
|
|
|
|
test('get channel count 4', async () => {
|
|
const conn = new ewelink({ at: accessToken });
|
|
const result = await conn.getDeviceChannelCount(fourChannelsDevice);
|
|
expect(typeof result).toBe('object');
|
|
expect(result.status).toBe('ok');
|
|
expect(result.switchesAmount).toBe(4);
|
|
});
|
|
});
|