Skip to content

Commit

Permalink
Merge pull request #63 from Grizzelbee/Dev_0.7.3
Browse files Browse the repository at this point in the history
Dev 0.7.3
  • Loading branch information
Grizzelbee authored Feb 10, 2021
2 parents 0cd003a + e09ff5a commit 743099c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
11 changes: 8 additions & 3 deletions dyson-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ module.exports.dysonAPILogIn = async function(adapter) {
Email: adapter.config.email,
Password: adapter.config.Password
},
{ httpsAgent });
{ httpsAgent,
headers: { 'User-Agent': 'android client' },
json: true,
rejectUnauthorized: false
});
};

/**
Expand Down Expand Up @@ -204,6 +208,7 @@ module.exports.getMqttCredentials = function(adapter) {
switch (error.response.status) {
case 401 : // unauthorized
adapter.log.error('Error: Unable to authenticate user! Your credentials are invalid. Please double check and fix them.');
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);
Expand Down Expand Up @@ -235,8 +240,8 @@ module.exports.maskConfig = function (unmaskedConfig) {
// Masking sensitive fields (password) for logging configuration (creating a deep copy of the config)
const maskedConfig = JSON.parse(JSON.stringify(unmaskedConfig));
maskedConfig.Password = '(***)';
return maskedConfig
}
return maskedConfig;
};

/**
* Parse an incoming JSON message payload from the Dyson device
Expand Down
17 changes: 16 additions & 1 deletion io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
},
"native": {
"email": "",
"Password": "",
"country": "de",
"pollInterval": 30,
"temperatureUnit": "C"
Expand All @@ -221,5 +222,19 @@
"Password"
],
"objects": [],
"instanceObjects": []
"instanceObjects": [
{
"_id": "info.connection",
"type": "state",
"common": {
"role": "indicator.connected",
"name": "If connected to dyson device",
"type": "boolean",
"read": true,
"write": false,
"def": false
},
"native": {}
}
]
}
33 changes: 16 additions & 17 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ class dysonAirPurifier extends utils.Adapter {
this.terminate('Terminating Adapter due to error with the mqtt credentials.', 11);
}
} catch (error) {
this.setState('info.connection', false);
adapterLog.error(`[main()] error: ${error.message}, stack: ${error.stack}`);
}
}
Expand All @@ -750,25 +751,23 @@ class dysonAirPurifier extends utils.Adapter {
// Terminate adapter after first start because configuration is not yet received
// Adapter is restarted automatically when config page is closed
adapter = this; // preserve adapter reference to address functions etc. correctly later
dysonUtils.checkAdapterConfig(adapter)
.then(() => {
adapter.getForeignObject('system.config', (err, obj) => {
if (adapter.supportsFeature && adapter.supportsFeature('ADAPTER_AUTO_DECRYPT_NATIVE')) {
if (obj && obj.native && obj.native.secret) {
//noinspection JSUnresolvedVariable
adapter.config.Password = this.decrypt(obj.native.secret, adapter.config.Password);
}
this.main();
} else {
throw new Error('This adapter requires at least js-controller V3.0.0. Your system is not compatible. Please update.');
const configIsValid = await dysonUtils.checkAdapterConfig(adapter);
if (configIsValid) {
adapter.getForeignObject('system.config', (err, obj) => {
if (adapter.supportsFeature && adapter.supportsFeature('ADAPTER_AUTO_DECRYPT_NATIVE')) {
if (obj && obj.native && obj.native.secret) {
//noinspection JSUnresolvedVariable
adapter.config.Password = this.decrypt(obj.native.secret, adapter.config.Password);
}
});
})
.catch( (error) => {
this.setState('info.connection', false);
this.log.error(`[onReady] error: ${error.message}, stack: ${error.stack}`);
this.terminate('Terminating adapter until configuration is fixed.', 11);
this.main();
} else {
throw new Error('This adapter requires at least js-controller V3.0.0. Your system is not compatible. Please update.');
}
});
} else {
this.setState('info.connection', false);
this.terminate('Terminating adapter until configuration is fixed.', 11);
}
}
/***********************************************
* Misc helper functions *
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ Which is what the dyson app does also.

## Changelog

### 0.7.4 (2021-02-10) (Human)
* (grizzelbee) Fix: fixed adapter traffic light for info.connection
* (grizzelbee) Fix: Minor fixes

### 0.7.3 (2021-02-10) (When angels fall)
* (theimo1221) Fix: [#59](https://github.com/Grizzelbee/ioBroker.dysonairpurifier/issues/59) added default country
* (theimo1221) New: added function to mask password to dyson-utils.js
Expand Down

0 comments on commit 743099c

Please sign in to comment.