Skip to content

Commit

Permalink
### 1.4.15 (2020-05-11)
Browse files Browse the repository at this point in the history
* (bluefox) Better error output is implemented
  • Loading branch information
GermanBluefox committed May 11, 2020
1 parent b4824a8 commit d2c5a48
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 81 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ Following types are supported:
- `ifttt` - acting like IFTTT (actually not required, but for tests purposes)

## Changelog
### 1.4.15 (2020-05-11)
* (bluefox) Better error output is implemented

### 1.4.14 (2020-05-01)
* (bluefox) Fixed the problem if admin is not on 8081 port

Expand Down
14 changes: 13 additions & 1 deletion io-package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"common": {
"name": "iot",
"version": "1.4.14",
"version": "1.4.15",
"title": "IoT Assistants",
"titleLang": {
"en": "IoT cloud connection",
Expand All @@ -28,6 +28,18 @@
"zh-cn": "连接你的ioBroker服务器的ioBroker IoT云"
},
"news": {
"1.4.15": {
"en": "Better error output is implemented",
"de": "Eine bessere Fehlerausgabe ist implementiert",
"ru": "Улучшен вывод ошибок",
"pt": "Melhor saída de erro é implementada",
"nl": "Er wordt een betere foutuitvoer geïmplementeerd",
"fr": "Une meilleure sortie d'erreur est implémentée",
"it": "È stato implementato un migliore output degli errori",
"es": "Se implementa una mejor salida de error",
"pl": "Zaimplementowano lepsze wyjście błędu",
"zh-cn": "实现更好的错误输出"
},
"1.4.14": {
"en": "Fixed the problem if admin is not on 8081 port",
"de": "Das Problem wurde behoben, wenn sich der Administrator nicht am 8081-Port befindet",
Expand Down
2 changes: 1 addition & 1 deletion lib/alisa.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const {Types, ChannelDetector} = require('iobroker.type-detector');
const uuid = require('uuid/v1');
const uuid = require('uuid').v1;
const textsT = require('./texts');
const roomsT = require('./rooms');
const funcsT = require('./functions');
Expand Down
111 changes: 55 additions & 56 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,41 +414,40 @@ function readUrlKey() {

function createUrlKey(login, pass) {
return new Promise((resolve, reject) => {
let done = false;
let req;
let timeout = setTimeout(() => {
if (!done) {
done = true;
if (timeout) {
timeout = null;
req && req.abort();
reject('timeout');
}
req && req.abort();
}, 15000);

adapter.log.debug('Fetching URL key...');
req = request.get(`https://generate-key.iobroker.in/v1/generateUrlKey?user=${encodeURIComponent(login)}&pass=${encodeURIComponent(pass)}`, (error, response, body) => {
req = null;
clearTimeout(timeout);
if (error) {
if (!done) {
done = true;
if (timeout) {
clearTimeout(timeout);
timeout = null;
if (error) {
reject(error);
}
} else {
let data;
try {
data = JSON.parse(body)
} catch (e) {
return reject('Cannot parse URL key answer: ' + JSON.stringify(e));
}
if (data.error) {
adapter.log.error('Cannot fetch URL key: ' + JSON.stringify(data.error));
reject(data);
} else if (data.key) {
writeUrlKey(data.key)
.then(() => resolve(data.key));
} else {
adapter.log.error('Cannot fetch URL key: ' + JSON.stringify(data));
reject(data);
let data;
try {
data = JSON.parse(body)
} catch (e) {
return reject('Cannot parse URL key answer: ' + JSON.stringify(e));
}
if (data.error) {
adapter.log.error('Cannot fetch URL key: ' + JSON.stringify(data.error));
reject(data);
} else if (data.key) {
writeUrlKey(data.key)
.then(() => resolve(data.key));
} else {
adapter.log.error('Cannot fetch URL key: ' + JSON.stringify(data));
reject(data);
}
}
}
});
Expand Down Expand Up @@ -519,14 +518,13 @@ function fetchKeys(login, pass, _forceUserCreation) {
return new Promise((resolve, reject) => {
adapter.getState('certs.forceUserCreate', (err, state) => {
let forceUserCreation = state && state.val;
let done = false;
let req;
let timeout = setTimeout(() => {
if (!done) {
done = true;
if (!timeout) {
timeout = null;
req && req.abort();
reject('timeout');
}
req && req.abort();
}, 15000);

// erase flag, if user must be created anew, but remember the state
Expand All @@ -537,31 +535,31 @@ function fetchKeys(login, pass, _forceUserCreation) {
adapter.log.debug('Fetching keys...');
req = request.get(`https://create-user.iobroker.in/v1/createUser?user=${encodeURIComponent(login)}&pass=${encodeURIComponent(pass)}&forceRecreate=${forceUserCreation}`, (error, response, body) => {
req = null;
clearTimeout(timeout);
if (error) {
if (!done) {
done = true;
if (timeout) {
clearTimeout(timeout);
timeout = null;
if (error) {
reject(error);
}
} else {
let data;
try {
data = JSON.parse(body)
} catch (e) {
return reject('Cannot parse answer: ' + JSON.stringify(e));
}
if (data.error) {
adapter.log.error('Cannot fetch keys: ' + JSON.stringify(data.error));
reject(data);
} else if (data.certificates) {
writeKeys(data.certificates)
.then(() => resolve({
private: data.certificates.keyPair.PrivateKey,
certificate: data.certificates.certificatePem
}));
} else {
adapter.log.error('Cannot fetch keys: ' + JSON.stringify(data));
reject(data);
let data;
try {
data = JSON.parse(body)
} catch (e) {
return reject('Cannot parse answer: ' + JSON.stringify(e));
}
if (data.error) {
adapter.log.error('Cannot fetch keys: ' + JSON.stringify(data.error));
reject(data);
} else if (data.certificates) {
writeKeys(data.certificates)
.then(() => resolve({
private: data.certificates.keyPair.PrivateKey,
certificate: data.certificates.certificatePem
}));
} else {
adapter.log.error('Cannot fetch keys: ' + JSON.stringify(data));
reject(data);
}
}
}
});
Expand Down Expand Up @@ -771,7 +769,7 @@ function startDevice(clientId, login, password, retry) {
if (e === 'Not exists') {
return createUrlKey(login, password);
} else {
throw new Error(e);
throw new Error(e && e.error ? e.error : e);
}
})
.then(key => {
Expand Down Expand Up @@ -806,14 +804,15 @@ function startDevice(clientId, login, password, retry) {
}
});
}).catch(e => {
if (e && e.message) {
adapter.log.error('Cannot read keys: ' + JSON.stringify(e.message) + ' / ' + e.toString());
if (e && typeof e === 'object' && e.message) {
adapter.log.error('Cannot read keys: ' + e.message);
} else {
adapter.log.error('Cannot read keys: ' + JSON.stringify(e) + ' / ' + e.toString());
adapter.log.error('Cannot read keys: ' + JSON.stringify(e) + ' / ' + (e && e.toString()));
}

if (e === 'timeout' && retry < 10) {
setTimeout(() => startDevice(clientId, login, password, retry + 1), 10000);
setTimeout(() =>
startDevice(clientId, login, password, retry + 1), 10000);
}
});
}
Expand Down
39 changes: 22 additions & 17 deletions package-lock.json

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

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iobroker.iot",
"version": "1.4.14",
"version": "1.4.15",
"description": "This adapter allows to communicate Amazon Alexa and Google Home with ioBroker.",
"author": {
"name": "bluefox",
Expand All @@ -25,16 +25,16 @@
"dependencies": {
"echarts": "^4.7.0",
"jsdom": "^16.2.2",
"moment": "^2.24.0",
"moment": "^2.25.3",
"aws-iot-device-sdk": "^2.2.4",
"iobroker.type-detector": "^0.1.9",
"request": "^2.88.2",
"@iobroker/adapter-core": "^2.3.1",
"uuid": "^3.4.0"
"@iobroker/adapter-core": "^2.4.0",
"uuid": "^8.0.0"
},
"devDependencies": {
"@types/iobroker": "^3.0.6",
"@types/node": "^13.13.4",
"@types/iobroker": "^3.0.8",
"@types/node": "^13.13.5",
"axios": "^0.19.2",
"chai": "^4.2.0",
"del": "^5.1.0",
Expand Down

0 comments on commit d2c5a48

Please sign in to comment.