Release v1.8.0 (#23)

* new method to check for device firmware updates

* moved mixin

* generate firmware update payload

* new method to check for devices firmware updates

* removed unused function

* moved firmware tests to own file

* added firmware test cases

* return device id on response

* updated credentials list

* version bump
This commit is contained in:
Martin M
2019-11-02 22:42:55 -03:00
committed by GitHub
parent f883be49a6
commit e6f60724f1
15 changed files with 262 additions and 53 deletions

45
main.js
View File

@@ -28,6 +28,14 @@ class eWeLink {
return `https://${this.region}-api.coolkit.cc:8080/api`;
}
/**
* Generate eWeLink OTA API URL
* @returns {string}
*/
getOtaUrl() {
return `https://${this.region}-ota.coolkit.cc:8080/otaother`;
}
/**
* Generate eWeLink WebSocket URL
*
@@ -41,22 +49,29 @@ class eWeLink {
* Generate http requests helpers
*
* @param method
* @param url
* @param uri
* @param body
* @param qs
*
* @returns {Promise<{msg: string, error: *}>}
*/
async makeRequest({ method = 'GET', uri, body = {}, qs = {} }) {
async makeRequest({ method = 'GET', url, uri, body = {}, qs = {} }) {
const { at } = this;
if (!at) {
await this.login();
}
let apiUrl = this.getApiUrl();
if (url) {
apiUrl = url;
}
const response = await rp({
method,
uri: `${this.getApiUrl()}${uri}`,
uri: `${apiUrl}${uri}`,
headers: { Authorization: `Bearer ${this.at}` },
body,
qs,
@@ -111,16 +126,6 @@ class eWeLink {
return response;
}
/**
* Check if authentication credentials doesn't exists then perform a login
*
* @returns {Promise<void>}
*/
async logIfNeeded() {
if (!this.at) {
await this.login();
}
}
}
/* LOAD MIXINS: power state */
@@ -139,7 +144,11 @@ const getTHMixin = require('./mixins/temphumd/getTHMixin');
const getDevicesMixin = require('./mixins/devices/getDevicesMixin');
const getDeviceMixin = require('./mixins/devices/getDeviceMixin');
const getDeviceChannelCountMixin = require('./mixins/devices/getDeviceChannelCountMixin');
const getFirmwareVersionMixin = require('./mixins/devices/getFirmwareVersionMixin');
/* LOAD MIXINS: firmware */
const getFirmwareVersionMixin = require('./mixins/firmware/getFirmwareVersionMixin');
const checkDeviceUpdateMixin = require('./mixins/firmware/checkDeviceUpdateMixin');
const checkDevicesUpdatesMixin = require('./mixins/firmware/checkDevicesUpdatesMixin');
/* LOAD MIXINS: websocket */
const openWebSocketMixin = require('./mixins/websocket/openWebSocketMixin');
@@ -163,8 +172,14 @@ Object.assign(
eWeLink.prototype,
getDevicesMixin,
getDeviceMixin,
getDeviceChannelCountMixin,
getFirmwareVersionMixin
getDeviceChannelCountMixin
);
Object.assign(
eWeLink.prototype,
getFirmwareVersionMixin,
checkDeviceUpdateMixin,
checkDevicesUpdatesMixin
);
Object.assign(eWeLink.prototype, openWebSocketMixin);