iobroker.sonoff 2.5.3 → 2.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -22
- package/README.md +209 -204
- package/admin/i18n/de/translations.json +54 -52
- package/admin/i18n/en/translations.json +53 -51
- package/admin/i18n/es/translations.json +54 -52
- package/admin/i18n/fr/translations.json +54 -52
- package/admin/i18n/it/translations.json +54 -52
- package/admin/i18n/nl/translations.json +54 -52
- package/admin/i18n/pl/translations.json +54 -52
- package/admin/i18n/pt/translations.json +54 -52
- package/admin/i18n/ru/translations.json +54 -52
- package/admin/i18n/zh-cn/translations.json +54 -52
- package/admin/index.html +177 -177
- package/admin/index_m.html +218 -218
- package/admin/jsonConfig.json +112 -0
- package/admin/words.js +54 -54
- package/io-package.json +17 -13
- package/lib/datapoints.js +193 -193
- package/lib/server.js +1761 -1765
- package/lib/tools.js +99 -99
- package/main.js +88 -93
- package/package.json +7 -6
package/lib/tools.js
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
const axios = require('axios').default;
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Tests whether the given variable is a real object and not an Array
|
|
5
|
-
* @param {any} it The variable to test
|
|
6
|
-
* @returns {it is Record<string, any>}
|
|
7
|
-
*/
|
|
8
|
-
function isObject(it) {
|
|
9
|
-
// This is necessary because:
|
|
10
|
-
// typeof null === 'object'
|
|
11
|
-
// typeof [] === 'object'
|
|
12
|
-
// [] instanceof Object === true
|
|
13
|
-
return Object.prototype.toString.call(it) === '[object Object]';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Tests whether the given variable is really an Array
|
|
18
|
-
* @param {any} it The variable to test
|
|
19
|
-
* @returns {it is any[]}
|
|
20
|
-
*/
|
|
21
|
-
function isArray(it) {
|
|
22
|
-
if (typeof Array.isArray === 'function') return Array.isArray(it);
|
|
23
|
-
return Object.prototype.toString.call(it) === '[object Array]';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Translates text to the target language. Automatically chooses the right translation API.
|
|
28
|
-
* @param {string} text The text to translate
|
|
29
|
-
* @param {string} targetLang The target languate
|
|
30
|
-
* @param {string} [yandexApiKey] The yandex API key. You can create one for free at https://translate.yandex.com/developers
|
|
31
|
-
* @returns {Promise<string>}
|
|
32
|
-
*/
|
|
33
|
-
async function translateText(text, targetLang, yandexApiKey) {
|
|
34
|
-
if (targetLang === 'en') {
|
|
35
|
-
return text;
|
|
36
|
-
} else if (!text) {
|
|
37
|
-
return '';
|
|
38
|
-
}
|
|
39
|
-
if (yandexApiKey) {
|
|
40
|
-
return translateYandex(text, targetLang, yandexApiKey);
|
|
41
|
-
} else {
|
|
42
|
-
return translateGoogle(text, targetLang);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Translates text with Yandex API
|
|
48
|
-
* @param {string} text The text to translate
|
|
49
|
-
* @param {string} targetLang The target languate
|
|
50
|
-
* @param {string} apiKey The yandex API key. You can create one for free at https://translate.yandex.com/developers
|
|
51
|
-
* @returns {Promise<string>}
|
|
52
|
-
*/
|
|
53
|
-
async function translateYandex(text, targetLang, apiKey) {
|
|
54
|
-
if (targetLang === 'zh-cn') {
|
|
55
|
-
targetLang = 'zh';
|
|
56
|
-
}
|
|
57
|
-
try {
|
|
58
|
-
const url = `https://translate.yandex.net/api/v1.5/tr.json/translate?key=${apiKey}&text=${encodeURIComponent(text)}&lang=en-${targetLang}`;
|
|
59
|
-
const response = await axios({url, timeout: 15000});
|
|
60
|
-
if (response.data && response.data.text && isArray(response.data.text)) {
|
|
61
|
-
return response.data.text[0];
|
|
62
|
-
}
|
|
63
|
-
throw new Error('Invalid response for translate request');
|
|
64
|
-
} catch (e) {
|
|
65
|
-
throw new Error(`Could not translate to "${targetLang}": ${e}`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Translates text with Google API
|
|
71
|
-
* @param {string} text The text to translate
|
|
72
|
-
* @param {string} targetLang The target languate
|
|
73
|
-
* @returns {Promise<string>}
|
|
74
|
-
*/
|
|
75
|
-
async function translateGoogle(text, targetLang) {
|
|
76
|
-
try {
|
|
77
|
-
const url = `http://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=${targetLang}&dt=t&q=${encodeURIComponent(text)}&ie=UTF-8&oe=UTF-8`;
|
|
78
|
-
const response = await axios({url, timeout: 15000});
|
|
79
|
-
if (isArray(response.data)) {
|
|
80
|
-
// we got a valid response
|
|
81
|
-
return response.data[0][0][0];
|
|
82
|
-
}
|
|
83
|
-
throw new Error('Invalid response for translate request');
|
|
84
|
-
} catch (e) {
|
|
85
|
-
if (e.response && e.response.status === 429) {
|
|
86
|
-
throw new Error(
|
|
87
|
-
`Could not translate to "${targetLang}": Rate-limited by Google Translate`
|
|
88
|
-
);
|
|
89
|
-
} else {
|
|
90
|
-
throw new Error(`Could not translate to "${targetLang}": ${e}`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
module.exports = {
|
|
96
|
-
isArray,
|
|
97
|
-
isObject,
|
|
98
|
-
translateText
|
|
99
|
-
};
|
|
1
|
+
const axios = require('axios').default;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Tests whether the given variable is a real object and not an Array
|
|
5
|
+
* @param {any} it The variable to test
|
|
6
|
+
* @returns {it is Record<string, any>}
|
|
7
|
+
*/
|
|
8
|
+
function isObject(it) {
|
|
9
|
+
// This is necessary because:
|
|
10
|
+
// typeof null === 'object'
|
|
11
|
+
// typeof [] === 'object'
|
|
12
|
+
// [] instanceof Object === true
|
|
13
|
+
return Object.prototype.toString.call(it) === '[object Object]';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Tests whether the given variable is really an Array
|
|
18
|
+
* @param {any} it The variable to test
|
|
19
|
+
* @returns {it is any[]}
|
|
20
|
+
*/
|
|
21
|
+
function isArray(it) {
|
|
22
|
+
if (typeof Array.isArray === 'function') return Array.isArray(it);
|
|
23
|
+
return Object.prototype.toString.call(it) === '[object Array]';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Translates text to the target language. Automatically chooses the right translation API.
|
|
28
|
+
* @param {string} text The text to translate
|
|
29
|
+
* @param {string} targetLang The target languate
|
|
30
|
+
* @param {string} [yandexApiKey] The yandex API key. You can create one for free at https://translate.yandex.com/developers
|
|
31
|
+
* @returns {Promise<string>}
|
|
32
|
+
*/
|
|
33
|
+
async function translateText(text, targetLang, yandexApiKey) {
|
|
34
|
+
if (targetLang === 'en') {
|
|
35
|
+
return text;
|
|
36
|
+
} else if (!text) {
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
if (yandexApiKey) {
|
|
40
|
+
return translateYandex(text, targetLang, yandexApiKey);
|
|
41
|
+
} else {
|
|
42
|
+
return translateGoogle(text, targetLang);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Translates text with Yandex API
|
|
48
|
+
* @param {string} text The text to translate
|
|
49
|
+
* @param {string} targetLang The target languate
|
|
50
|
+
* @param {string} apiKey The yandex API key. You can create one for free at https://translate.yandex.com/developers
|
|
51
|
+
* @returns {Promise<string>}
|
|
52
|
+
*/
|
|
53
|
+
async function translateYandex(text, targetLang, apiKey) {
|
|
54
|
+
if (targetLang === 'zh-cn') {
|
|
55
|
+
targetLang = 'zh';
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const url = `https://translate.yandex.net/api/v1.5/tr.json/translate?key=${apiKey}&text=${encodeURIComponent(text)}&lang=en-${targetLang}`;
|
|
59
|
+
const response = await axios({url, timeout: 15000});
|
|
60
|
+
if (response.data && response.data.text && isArray(response.data.text)) {
|
|
61
|
+
return response.data.text[0];
|
|
62
|
+
}
|
|
63
|
+
throw new Error('Invalid response for translate request');
|
|
64
|
+
} catch (e) {
|
|
65
|
+
throw new Error(`Could not translate to "${targetLang}": ${e}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Translates text with Google API
|
|
71
|
+
* @param {string} text The text to translate
|
|
72
|
+
* @param {string} targetLang The target languate
|
|
73
|
+
* @returns {Promise<string>}
|
|
74
|
+
*/
|
|
75
|
+
async function translateGoogle(text, targetLang) {
|
|
76
|
+
try {
|
|
77
|
+
const url = `http://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=${targetLang}&dt=t&q=${encodeURIComponent(text)}&ie=UTF-8&oe=UTF-8`;
|
|
78
|
+
const response = await axios({url, timeout: 15000});
|
|
79
|
+
if (isArray(response.data)) {
|
|
80
|
+
// we got a valid response
|
|
81
|
+
return response.data[0][0][0];
|
|
82
|
+
}
|
|
83
|
+
throw new Error('Invalid response for translate request');
|
|
84
|
+
} catch (e) {
|
|
85
|
+
if (e.response && e.response.status === 429) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
`Could not translate to "${targetLang}": Rate-limited by Google Translate`
|
|
88
|
+
);
|
|
89
|
+
} else {
|
|
90
|
+
throw new Error(`Could not translate to "${targetLang}": ${e}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
module.exports = {
|
|
96
|
+
isArray,
|
|
97
|
+
isObject,
|
|
98
|
+
translateText
|
|
99
|
+
};
|
package/main.js
CHANGED
|
@@ -1,93 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
adapter
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
adapter.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
module.exports = startAdapter;
|
|
90
|
-
} else {
|
|
91
|
-
// or start the instance directly
|
|
92
|
-
startAdapter();
|
|
93
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* ioBroker sonoff Adapter
|
|
4
|
+
*
|
|
5
|
+
* (c) 2017-2023 bluefox
|
|
6
|
+
*
|
|
7
|
+
* MIT License
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
const utils = require('@iobroker/adapter-core'); // Get common adapter utils
|
|
13
|
+
const adapterName = require('./package.json').name.split('.').pop();
|
|
14
|
+
const Server = require('./lib/server');
|
|
15
|
+
let server = null;
|
|
16
|
+
let adapter;
|
|
17
|
+
|
|
18
|
+
function decrypt(key, value) {
|
|
19
|
+
let result = '';
|
|
20
|
+
for (let i = 0; i < value.length; ++i) {
|
|
21
|
+
result += String.fromCharCode(key[i % key.length].charCodeAt(0) ^ value.charCodeAt(i));
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function startAdapter(options) {
|
|
27
|
+
options = options || {};
|
|
28
|
+
Object.assign(options, {name: adapterName});
|
|
29
|
+
|
|
30
|
+
adapter = new utils.Adapter(options);
|
|
31
|
+
|
|
32
|
+
adapter.on('ready', () => {
|
|
33
|
+
// it must be like this
|
|
34
|
+
|
|
35
|
+
adapter.getForeignObject('system.config', (err, obj) => {
|
|
36
|
+
if (obj && obj.native && obj.native.secret) {
|
|
37
|
+
//noinspection JSUnresolvedVariable
|
|
38
|
+
adapter.config.pass = decrypt(obj.native.secret, adapter.config.pass);
|
|
39
|
+
} else {
|
|
40
|
+
//noinspection JSUnresolvedVariable
|
|
41
|
+
adapter.config.pass = decrypt('Zgfr56gFe87jJOM', adapter.config.pass);
|
|
42
|
+
}
|
|
43
|
+
main();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
adapter.on('unload', cb => {
|
|
48
|
+
if (server) {
|
|
49
|
+
server.destroy(cb);
|
|
50
|
+
server = null;
|
|
51
|
+
} else if (typeof cb === 'function') {
|
|
52
|
+
cb();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// is called if a subscribed state changes
|
|
57
|
+
adapter.on('stateChange', (id, state) => {
|
|
58
|
+
adapter.log.debug(`stateChange ${id}: ${JSON.stringify(state)}`);
|
|
59
|
+
// you can use the ack flag to detect if state is desired or acknowledged
|
|
60
|
+
state && !state.ack && server && server.onStateChange(id, state);
|
|
61
|
+
});
|
|
62
|
+
return adapter;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function main() {
|
|
66
|
+
adapter.config.TELE_SENSOR = adapter.config.TELE_SENSOR === true || adapter.config.TELE_SENSOR === 'true';
|
|
67
|
+
adapter.config.TELE_STATE = adapter.config.TELE_STATE === true || adapter.config.TELE_STATE === 'true';
|
|
68
|
+
adapter.config.STAT_RESULT = adapter.config.STAT_RESULT === true || adapter.config.STAT_RESULT === 'true';
|
|
69
|
+
adapter.config.OBJ_TREE = adapter.config.OBJ_TREE === true || adapter.config.OBJ_TREE === 'true';
|
|
70
|
+
|
|
71
|
+
// subscribe for all own variables
|
|
72
|
+
adapter.subscribeStates('*');
|
|
73
|
+
|
|
74
|
+
// read all states and set alive to false
|
|
75
|
+
adapter.getStatesOf('', '', (err, states) =>
|
|
76
|
+
states && states.length && states.forEach(state =>
|
|
77
|
+
state._id.match(/\.alive$/) && adapter.setForeignState(state._id, false, true)));
|
|
78
|
+
|
|
79
|
+
server = new Server(adapter);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// If started as allInOne/compact mode => return function to create instance
|
|
83
|
+
if (module && module.parent) {
|
|
84
|
+
module.exports = startAdapter;
|
|
85
|
+
} else {
|
|
86
|
+
// or start the instance directly
|
|
87
|
+
startAdapter();
|
|
88
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iobroker.sonoff",
|
|
3
3
|
"description": "The adapter allows to send and receive MQTT messages from ioBroker and to be a broker.",
|
|
4
|
-
"version": "2.5.
|
|
4
|
+
"version": "2.5.7",
|
|
5
5
|
"author": "bluefox <dogafox@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/ioBroker/ioBroker.sonoff",
|
|
7
7
|
"repository": {
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"@iobroker/adapter-core": "^2.6.8"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@alcalzone/release-script": "^3.
|
|
24
|
-
"@alcalzone/release-script-plugin-iobroker": "^3.
|
|
23
|
+
"@alcalzone/release-script": "^3.6.0",
|
|
24
|
+
"@alcalzone/release-script-plugin-iobroker": "^3.6.0",
|
|
25
25
|
"@alcalzone/release-script-plugin-license": "^3.5.9",
|
|
26
|
-
"@iobroker/legacy-testing": "^0.
|
|
27
|
-
"axios": "^1.
|
|
26
|
+
"@iobroker/legacy-testing": "^0.3.6",
|
|
27
|
+
"axios": "^1.4.0",
|
|
28
28
|
"mqtt": "^4.3.7",
|
|
29
29
|
"gulp": "^4.0.2",
|
|
30
30
|
"mocha": "^10.2.0",
|
|
@@ -46,7 +46,8 @@
|
|
|
46
46
|
"release": "release-script",
|
|
47
47
|
"release-patch": "release-script patch --yes",
|
|
48
48
|
"release-minor": "release-script minor --yes",
|
|
49
|
-
"release-major": "release-script major --yes"
|
|
49
|
+
"release-major": "release-script major --yes",
|
|
50
|
+
"update-packages": "ncu --upgrade"
|
|
50
51
|
},
|
|
51
52
|
"engines": {
|
|
52
53
|
"node": ">=4.0.0"
|