iobroker.ebus 3.2.4 → 3.2.6
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/.eslintrc.json +34 -34
- package/.releaseconfig.json +3 -0
- package/LICENSE +20 -20
- package/README.md +147 -130
- package/admin/index_m.html +419 -419
- package/admin/style.css +18 -18
- package/admin/words.js +27 -27
- package/io-package.json +218 -192
- package/lib/support_tools.js +370 -370
- package/lib/tools.js +99 -99
- package/main.js +1232 -1232
- package/package.json +13 -11
- package/widgets/ebus/lib/js/flot/jquery.canvaswrapper.js +549 -549
- package/widgets/ebus/lib/js/flot/jquery.colorhelpers.js +199 -199
- package/widgets/ebus/lib/js/flot/jquery.flot.axislabels.js +212 -212
- package/widgets/ebus/lib/js/flot/jquery.flot.browser.js +98 -98
- package/widgets/ebus/lib/js/flot/jquery.flot.categories.js +202 -202
- package/widgets/ebus/lib/js/flot/jquery.flot.composeImages.js +330 -330
- package/widgets/ebus/lib/js/flot/jquery.flot.crosshair.js +202 -202
- package/widgets/ebus/lib/js/flot/jquery.flot.drawSeries.js +662 -662
- package/widgets/ebus/lib/js/flot/jquery.flot.errorbars.js +375 -375
- package/widgets/ebus/lib/js/flot/jquery.flot.fillbetween.js +254 -254
- package/widgets/ebus/lib/js/flot/jquery.flot.flatdata.js +47 -47
- package/widgets/ebus/lib/js/flot/jquery.flot.hover.js +361 -361
- package/widgets/ebus/lib/js/flot/jquery.flot.image.js +249 -249
- package/widgets/ebus/lib/js/flot/jquery.flot.js +2953 -2953
- package/widgets/ebus/lib/js/flot/jquery.flot.legend.js +437 -437
- package/widgets/ebus/lib/js/flot/jquery.flot.logaxis.js +298 -298
- package/widgets/ebus/lib/js/flot/jquery.flot.navigate.js +834 -834
- package/widgets/ebus/lib/js/flot/jquery.flot.pie.js +794 -794
- package/widgets/ebus/lib/js/flot/jquery.flot.resize.js +60 -60
- package/widgets/ebus/lib/js/flot/jquery.flot.saturated.js +43 -43
- package/widgets/ebus/lib/js/flot/jquery.flot.selection.js +527 -527
- package/widgets/ebus/lib/js/flot/jquery.flot.stack.js +220 -220
- package/widgets/ebus/lib/js/flot/jquery.flot.symbol.js +98 -98
- package/widgets/ebus/lib/js/flot/jquery.flot.threshold.js +143 -143
- package/widgets/ebus/lib/js/flot/jquery.flot.time.js +586 -586
- package/widgets/ebus/lib/js/flot/jquery.flot.touch.js +320 -320
- package/widgets/ebus/lib/js/flot/jquery.flot.touchNavigate.js +360 -360
- package/widgets/ebus/lib/js/flot/jquery.flot.uiConstants.js +10 -10
- package/widgets/ebus/lib/js/flot/jquery.js +9473 -9473
- package/widgets/ebus/lib/js/lib/globalize.culture.en-US.js +33 -33
- package/widgets/ebus/lib/js/lib/globalize.js +1601 -1601
- package/widgets/ebus/lib/js/lib/jquery.event.drag.js +145 -145
- package/widgets/ebus/lib/js/lib/jquery.mousewheel.js +86 -86
- package/widgets/ebus.html +2395 -2395
- package/readme.txt +0 -297
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
|
+
};
|