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>
102 lines
3.7 KiB
JavaScript
102 lines
3.7 KiB
JavaScript
const ewelink = require('../main');
|
|
|
|
const {
|
|
email,
|
|
password,
|
|
singleChannelDeviceId,
|
|
outdatedFirmwareDevice,
|
|
updatedFirmwareDevice,
|
|
} = require('./_setup/credentials.js');
|
|
|
|
const { firmwareExpectations } = require('./_setup/expectations');
|
|
|
|
describe.skip('firmware: get version methods', () => {
|
|
let connection;
|
|
|
|
beforeAll(() => {
|
|
connection = new ewelink({ email, password });
|
|
});
|
|
|
|
test('get firmware version', async () => {
|
|
const device = await connection.getDevice(singleChannelDeviceId);
|
|
const currentVersion = device.params.fwVersion;
|
|
const firmware = await connection.getFirmwareVersion(singleChannelDeviceId);
|
|
expect(typeof firmware).toBe('object');
|
|
expect(firmware.status).toBe('ok');
|
|
expect(firmware.fwVersion).toBe(currentVersion);
|
|
});
|
|
|
|
test('get device firmware version should be right message', async () => {
|
|
const credentials = await connection.getCredentials();
|
|
const accessToken = credentials.at;
|
|
const conn = new ewelink({ at: accessToken });
|
|
const device = await conn.getDevice(singleChannelDeviceId);
|
|
const currentVersion = device.params.fwVersion;
|
|
const firmware = await conn.getFirmwareVersion(singleChannelDeviceId);
|
|
expect(typeof firmware).toBe('object');
|
|
expect(firmware.status).toBe('ok');
|
|
expect(firmware.fwVersion).toBe(currentVersion);
|
|
});
|
|
|
|
test('get invalid device firmware version should fail', async () => {
|
|
const conn = new ewelink({ email, password });
|
|
const firmwareVersion = await conn.getFirmwareVersion('invalid deviceid');
|
|
expect(typeof firmwareVersion).toBe('object');
|
|
expect(firmwareVersion.msg).toBe('Device does not exist');
|
|
expect(firmwareVersion.error).toBe(500);
|
|
});
|
|
|
|
test('get device firmware version using invalid credentials should fail', async () => {
|
|
const conn = new ewelink({ email: 'invalid', password: 'credentials' });
|
|
const firmware = await conn.getFirmwareVersion(singleChannelDeviceId);
|
|
expect(typeof firmware).toBe('object');
|
|
expect(firmware.msg).toBe('Authentication error');
|
|
expect(firmware.error).toBe(401);
|
|
});
|
|
});
|
|
|
|
describe.skip('firmware: check updates methods', () => {
|
|
let connection;
|
|
|
|
beforeAll(() => {
|
|
connection = new ewelink({ email, password });
|
|
});
|
|
|
|
test.skip('outdated device firmware should return available version', async () => {
|
|
const status = await connection.checkDeviceUpdate(outdatedFirmwareDevice);
|
|
expect(typeof status).toBe('object');
|
|
expect(typeof status).toBe('object');
|
|
expect(status.status).toBe('ok');
|
|
expect(status.msg).toBe('Update available');
|
|
expect(typeof status.version).toBe('string');
|
|
});
|
|
|
|
test('updated device firmware should return right message', async () => {
|
|
const status = await connection.checkDeviceUpdate(updatedFirmwareDevice);
|
|
expect(typeof status).toBe('object');
|
|
expect(typeof status).toBe('object');
|
|
expect(status.status).toBe('ok');
|
|
expect(status.msg).toBe('No update available');
|
|
});
|
|
|
|
test('invalid device update check should return error', async () => {
|
|
const status = await connection.checkDeviceUpdate('invalid deviceid');
|
|
expect(typeof status).toBe('object');
|
|
expect(status.error).toBe(500);
|
|
});
|
|
|
|
test('get devices update check should be valid response', async () => {
|
|
const status = await connection.checkDevicesUpdates();
|
|
expect(typeof status).toBe('object');
|
|
expect(status[0]).toMatchObject(firmwareExpectations);
|
|
});
|
|
|
|
test('get devices update check with invalid credentials should fail', async () => {
|
|
const conn = new ewelink({ email: 'invalid', password: 'credentials' });
|
|
const status = await conn.checkDevicesUpdates();
|
|
expect(typeof status).toBe('object');
|
|
expect(status.msg).toBe('Authentication error');
|
|
expect(status.error).toBe(401);
|
|
});
|
|
});
|