Skip to content

Commit

Permalink
Merge pull request #96 from Grizzelbee/Devg_0.9.0
Browse files Browse the repository at this point in the history
Devg 0.9.0
  • Loading branch information
Grizzelbee authored Apr 21, 2021
2 parents e8e89b9 + eee8a89 commit ae30ad5
Show file tree
Hide file tree
Showing 8 changed files with 796 additions and 218 deletions.
6 changes: 5 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ package-lock.json
admin/i18n

# maintenance scripts
maintenance/**
maintenance/**

# CorelDraw files
*.cdr
*.bak
47 changes: 27 additions & 20 deletions dyson-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@

const _ = require('lodash');
const crypto = require('crypto');
const {stringify} = require('flatted');
const dysonConstants = require('./dysonConstants.js');
const axios = require('axios');
const path = require('path');
const https = require('https');
const rootCas = require('ssl-root-cas').create();
const {stringify} = require('flatted');
const httpsAgent = new https.Agent({ca: rootCas});
const supportedProductTypes = ['358', '438', '455', '469', '475', '520', '527'];
const apiUri = 'https://appapi.cp.dyson.com';
rootCas.addFile(path.resolve(__dirname, 'certificates/intermediate.pem'));

// class DysonUtils {
// DysonUtils() {}
// }

/*
module.exports.getDyson2faMail(email, passwd, country, locale){
adapter.log.error('getDyson2faMail - Here we Go!');
}
*/
/**
* Function zeroFill
*
* Formats a number as a string with leading zeros
*
* @param number {number} Value thats needs to be filled up with leading zeros
* @param number {string} Value thats needs to be filled up with leading zeros
* @param width {number} width of the complete new string incl. number and zeros
*
* @returns The given number filled up with leading zeros to a given width (excluding the negative sign), returns empty string if number is not an actual number.
Expand All @@ -46,11 +48,11 @@ module.exports.zeroFill = function (number, width) {
* resolves if the config is valid
* rejects if the config is invalid
*
* @param config {Adapter} ioBroker adapter which contains the configuration that should be checked
* @param adapter {object} ioBroker adapter which contains the configuration that should be checked
*/
module.exports.checkAdapterConfig = async function (adapter) {
const config = adapter.config;
// Prepare masked Config for debuggging
// Prepare masked Config for debugging
const logConfig = JSON.stringify(this.maskConfig(config));

return new Promise(
Expand Down Expand Up @@ -116,8 +118,8 @@ module.exports.getDevices = async function(myAccount, adapter) {
const devices = [];
for (const thisDevice in response.data) {
adapter.log.debug('Data received from dyson API: ' + JSON.stringify(response.data[thisDevice]));
// TODO Try to switch from supportedProductTypes-array to products-object
if (!supportedProductTypes.some(function (t) {
// TODO Try to switch from SUPPORTED_PRODUCT_TYPES-array to PRODUCTS-object
if (!dysonConstants.SUPPORTED_PRODUCT_TYPES.some(function (t) {
return t === response.data[thisDevice].ProductType;
})) {
adapter.log.warn('Device with serial number [' + response.data[thisDevice].Serial + '] not added, hence it is not supported by this adapter. Product type: [' + response.data[thisDevice].ProductType + ']');
Expand Down Expand Up @@ -159,26 +161,30 @@ module.exports.dysonAPILogIn = async function(adapter) {
'Email': adapter.config.email,
'Password': adapter.config.Password
};
const config = {
httpsAgent,
headers : headers,
json:true
};

const response = await axios.get(apiUri + `/v1/userregistration/userstatus?country=${adapter.config.country}&email=${adapter.config.email}`,
{ httpsAgent,
headers: headers,
json: true
});
const response = await axios.get(dysonConstants.API_URI + `/v1/userregistration/userstatus?country=${adapter.config.country}&email=${adapter.config.email}`,
config);
if (response.data.accountStatus === 'ACTIVE') {
adapter.log.info(`Result from API-Status request -> Account is: ${response.data.accountStatus}`);
} else {
adapter.log.warn(`Result from API-Status request -> Account is: ${response.data.accountStatus}`);
}
// Sends the login request to the API
return await axios.post(apiUri + '/v1/userregistration/authenticate?country=' + adapter.config.country,
return await axios.post(dysonConstants.API_URI + '/v1/userregistration/authenticate?country=' + adapter.config.country,
payload,
{ httpsAgent,
headers: headers,
json : true
});
};



/**
* dysonGetDevicesFromApi
*
Expand All @@ -189,7 +195,7 @@ module.exports.dysonAPILogIn = async function(adapter) {
* rejects on any http error.
*/module.exports.dysonGetDevicesFromApi = async function(auth) {
// Sends a request to the API to get all devices of the user
return await axios.get(apiUri + '/v2/provisioningservice/manifest',
return await axios.get(dysonConstants.API_URI + '/v2/provisioningservice/manifest',
{
httpsAgent,
headers: { 'Authorization': auth },
Expand Down Expand Up @@ -226,7 +232,8 @@ module.exports.getMqttCredentials = function(adapter) {
adapter.log.error(`Credentials used for login: User:[${adapter.config.email}] - Password:[${adapter.config.Password}] - Country:[${adapter.config.country}]`);
break;
case 429: // endpoint currently not available
adapter.log.error('Error: Endpoint: ' + apiUri + '/v1/userregistration/authenticate?country=' + adapter.config.country);
adapter.log.error('Error: Endpoint: ' + dysonConstants.API_URI + '/v1/userregistration/authenticate?country=' + adapter.config.country);
break;
default:
adapter.log.error('[error.response.data]: ' + ((typeof error.response.data === 'object') ? stringify(error.response.data) : error.response.data));
adapter.log.error('[error.response.status]: ' + ((typeof error.response.status === 'object') ? stringify(error.response.status) : error.response.status));
Expand Down Expand Up @@ -264,7 +271,7 @@ module.exports.maskConfig = function (unmaskedConfig) {
* @param msg Incoming JSON message
*/
module.exports.parseDysonMessage = function (msg) {
if (null == msg || '' == msg) return;
if (null == msg || '' === msg) return;

// TODO incomplete

Expand Down
69 changes: 69 additions & 0 deletions dysonConstants.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions io-package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
{
"common": {
"name": "dysonairpurifier",
"version": "0.8.1",
"version": "0.8.2",
"news": {
"0.8.2": {
"en": "Support for new dyson login procedure and bugfixes.",
"de": "Unterstützung für neue Dyson-Anmeldeverfahren und Bugfixes.",
"ru": "Поддержка новой процедуры входа в систему dyson и исправления.",
"pt": "Suporte para novo procedimento de login dyson e correções de bugs.",
"nl": "Ondersteuning voor nieuwe dyson-inlogprocedure en bugfixes.",
"fr": "Prise en charge de la nouvelle procédure de connexion dyson et corrections de bogues.",
"it": "Supporto per la nuova procedura di accesso a Dyson e correzioni di bug.",
"es": "Soporte para el nuevo procedimiento de inicio de sesión de Dyson y correcciones de errores.",
"pl": "Wsparcie dla nowej procedury logowania dyson i poprawek błędów.",
"zh-cn": "支持新的dyson登录过程和错误修正。"
},
"0.8.0": {
"en": "Improved humidifier support and bugfixes.",
"de": "Verbesserte Luftbefeuchterunterstützung und Bugfixes.",
Expand Down Expand Up @@ -210,7 +222,7 @@
"zh-cn": "将戴森空气净化器和风扇集成到ioBroker中"
},
"authors": [
"Hanjo Hingsen <hanjo@hingsen.de>"
"Hanjo Hingsen <open.source@hingsen.de>"
],
"keywords": [
"ioBroker",
Expand All @@ -224,7 +236,6 @@
],
"license": "MIT",
"platform": "Javascript/Node.js",
"main": "main.js",
"icon": "dyson_logo.svg",
"enabled": true,
"extIcon": "https://github.com/Grizzelbee/ioBroker.dysonairpurifier/blob/master/admin/dyson_logo.svg",
Expand All @@ -236,7 +247,7 @@
"materialize": true,
"supportCustoms": false,
"connectionType": "local",
"dataSource": "pull",
"dataSource": "poll",
"dependencies": [
{
"js-controller": ">=3.0.0",
Expand Down
Loading

0 comments on commit ae30ad5

Please sign in to comment.