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>
1.6 KiB
1.6 KiB
serverless
On a serverless scenario you need to instantiate the class on every request.
So, instead of using email and password on every api call, you can login the first time then use auth credentials for future requests.
Default region of this library is
us. If your are in a different one, you must specify region parameter or error 400/401 will be returned.
/* first request: get access token and api key */
(async () => {
const connection = new ewelink({
email: '<your ewelink email>',
password: '<your ewelink password>',
region: '<your ewelink region>',
});
const login = await connection.login();
const accessToken = login.at;
const apiKey = login.user.apikey
const region = login.region;
})();
/* second request: use access token to request devices */
(async () => {
const newConnection = new ewelink({
at: accessToken,
region: region
});
const devices = await newConnection.getDevices();
console.log(devices);
})();
/* third request: use access token to request specific device info */
(async () => {
const thirdConnection = new ewelink({
at: accessToken,
region: region
});
const device = await thirdConnection.getDevice('<your device id>');
console.log(device);
})();
/* fourth request: use access token and api key to toggle specific device info */
(async () => {
const anotherNewConnection = new ewelink({
at: accessToken,
region: region
});
await anotherNewConnection.toggleDevice('<your device id>');
})();
If you don't know your region, use getRegion method