Skip to content

Commit 3606013

Browse files
committed
prettier
1 parent 78eab40 commit 3606013

14 files changed

+7600
-380
lines changed

.eslintrc.json

+69-49
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,71 @@
11
{
2-
"env": {
3-
"es6": true,
4-
"node": true
5-
},
6-
"extends": "eslint:recommended",
7-
"rules": {
8-
"indent": [
9-
"error",
10-
4,
11-
{
12-
"SwitchCase": 1
13-
}
14-
],
15-
"curly": "error",
16-
"brace-style": "error",
17-
"arrow-parens": ["error", "as-needed"],
18-
"no-console": "off",
19-
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
20-
"no-useless-escape": "warn",
21-
"no-constant-condition": "off",
22-
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 1 }],
23-
"no-var": "error",
24-
"prefer-const": "error",
25-
"no-throw-literal": "error",
26-
"prefer-promise-reject-errors": "error",
27-
"quotes": [
28-
"error",
29-
"single",
30-
{
31-
"avoidEscape": true,
32-
"allowTemplateLiterals": true
33-
}
34-
],
35-
"semi": [
36-
"error",
37-
"always"
38-
],
39-
"comma-dangle": ["error", {
40-
"arrays": "never",
41-
"objects": "never",
42-
"imports": "never",
43-
"exports": "never",
44-
"functions": "ignore"
45-
}],
46-
"no-trailing-spaces": "error"
47-
},
48-
"parserOptions": {
49-
"ecmaVersion": 2019
50-
}
2+
"env": {
3+
"es6": true,
4+
"node": true
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:prettier/recommended"
9+
],
10+
"rules": {
11+
"indent": [
12+
"error",
13+
4,
14+
{
15+
"SwitchCase": 1
16+
}
17+
],
18+
"curly": "error",
19+
"brace-style": "error",
20+
"arrow-parens": [
21+
"error",
22+
"as-needed"
23+
],
24+
"no-console": "off",
25+
"no-unused-vars": [
26+
"error",
27+
{
28+
"argsIgnorePattern": "^_"
29+
}
30+
],
31+
"no-useless-escape": "warn",
32+
"no-constant-condition": "off",
33+
"no-multiple-empty-lines": [
34+
"error",
35+
{
36+
"max": 1,
37+
"maxEOF": 1
38+
}
39+
],
40+
"no-var": "error",
41+
"prefer-const": "error",
42+
"no-throw-literal": "error",
43+
"prefer-promise-reject-errors": "error",
44+
"quotes": [
45+
"error",
46+
"single",
47+
{
48+
"avoidEscape": true,
49+
"allowTemplateLiterals": true
50+
}
51+
],
52+
"semi": [
53+
"error",
54+
"always"
55+
],
56+
"comma-dangle": [
57+
"error",
58+
{
59+
"arrays": "never",
60+
"objects": "never",
61+
"imports": "never",
62+
"exports": "never",
63+
"functions": "ignore"
64+
}
65+
],
66+
"no-trailing-spaces": "error"
67+
},
68+
"parserOptions": {
69+
"ecmaVersion": 2019
70+
}
5171
}

.npmignore

-14
This file was deleted.

.prettierrc.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"printWidth": 120,
3+
"semi": true,
4+
"tabWidth": 4,
5+
"useTabs": false,
6+
"trailingComma": "none",
7+
"singleQuote": true,
8+
"endOfLine": "lf",
9+
"bracketSpacing": true,
10+
"arrowParens": "avoid",
11+
"quoteProps": "as-needed"
12+
}

admin/words.js

+361-31
Large diffs are not rendered by default.

lib/enumNames.js

+39-21
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,41 @@
11
module.exports = {
2-
'funcLight': {en: 'Light', de: 'Licht', ru: 'Свет', fr: 'Lumière', nl: 'Licht'},
3-
'funcHeating': {en: 'Heating', de: 'Heizung', ru: 'Обогрев', fr: 'Chauffage', nl: 'Verwarming'},
4-
'funcClimateControl': {en: 'Climate сontrol', de: 'Klima-Steuerung', ru: 'Климатический контроль', fr: 'Climate control', nl: 'Climate сontrol'},
5-
'funcWeather': {en: 'Weather', de: 'Wetter', ru: 'Погода', fr: 'Météo', nl: 'Weer'},
6-
'funcEnvironment': {en: 'Environment', de: 'Umgebung', ru: 'Окружающая среда', fr: 'Environnement', nl: 'Milieu'},
7-
'funcSecurity': {en: 'Security', de: 'Sicherheit', ru: 'Безопасность', fr: 'Sécurité', nl: 'Veiligheid'},
8-
'funcLock': {en: 'Lock', de: 'Sperren', ru: 'Замок', fr: 'Fermer à clé', nl: 'Slot'},
9-
'funcButton': {en: 'Button', de: 'Taste', ru: 'Button', fr: 'Bouton', nl: 'Knop'},
10-
'funcCentral': {en: 'Central', de: 'Zentral', ru: 'Центральный', fr: 'Central', nl: 'Central'},
11-
'funcEnergy': {en: 'Energy', de: 'Energie', ru: 'Энергия', fr: 'Énergie', nl: 'Energie'},
12-
'roomLivingRoom': {en: 'LivingRoom', de: 'Wohnzimmer', ru: 'Гостиная', fr: 'Salon', nl: 'Woonkamer'},
13-
'roomKitchen': {en: 'Kitchen', de: 'Küche', ru: 'Кухня', fr: 'Cuisine', nl: 'Keuken'},
14-
'roomBedroom': {en: 'Bedroom', de: 'Schlafzimmer', ru: 'Спальня', fr: 'Chambre', nl: 'Slaapkamer'},
15-
'roomChildrensRoom1': {en: 'Childrens room 1', de: 'Kinderzimmer 1', ru: 'Детская комната 1', fr: 'Salle des enfants 1', nl: 'Kinderkamer 1'},
16-
'roomChildrensRoom2': {en: 'Childrens room 2', de: 'Kinderzimmer 2', ru: 'Детская комната 2', fr: 'Chambre des enfants 2', nl: 'Kinderkamer 2'},
17-
'roomOffice': {en: 'Office', de: 'Büro', ru: 'Офис', fr: 'Bureau', nl: 'Kantoor'},
18-
'roomBathroom': {en: 'Bathroom', de: 'Bad', ru: 'Ванная комната', fr: 'Salle de bains', nl: 'Badkamer'},
19-
'roomGarage': {en: 'Garage', de: 'Garage', ru: 'Гараж', fr: 'Garage', nl: 'Garage'},
20-
'roomHWR': {en: 'HWR', de: 'HWR', ru: 'HWR', fr: 'HWR', nl: 'HWR'},
21-
'roomGarden': {en: 'Garden', de: 'Garten', ru: 'Сад', fr: 'Jardin', nl: 'Tuin'},
22-
'roomTerrace': {en: 'Terrace', de: 'Terrasse', ru: 'Терраса', fr: 'Terrasse', nl: 'Terras'}
2+
funcLight: { en: 'Light', de: 'Licht', ru: 'Свет', fr: 'Lumière', nl: 'Licht' },
3+
funcHeating: { en: 'Heating', de: 'Heizung', ru: 'Обогрев', fr: 'Chauffage', nl: 'Verwarming' },
4+
funcClimateControl: {
5+
en: 'Climate сontrol',
6+
de: 'Klima-Steuerung',
7+
ru: 'Климатический контроль',
8+
fr: 'Climate control',
9+
nl: 'Climate сontrol'
10+
},
11+
funcWeather: { en: 'Weather', de: 'Wetter', ru: 'Погода', fr: 'Météo', nl: 'Weer' },
12+
funcEnvironment: { en: 'Environment', de: 'Umgebung', ru: 'Окружающая среда', fr: 'Environnement', nl: 'Milieu' },
13+
funcSecurity: { en: 'Security', de: 'Sicherheit', ru: 'Безопасность', fr: 'Sécurité', nl: 'Veiligheid' },
14+
funcLock: { en: 'Lock', de: 'Sperren', ru: 'Замок', fr: 'Fermer à clé', nl: 'Slot' },
15+
funcButton: { en: 'Button', de: 'Taste', ru: 'Button', fr: 'Bouton', nl: 'Knop' },
16+
funcCentral: { en: 'Central', de: 'Zentral', ru: 'Центральный', fr: 'Central', nl: 'Central' },
17+
funcEnergy: { en: 'Energy', de: 'Energie', ru: 'Энергия', fr: 'Énergie', nl: 'Energie' },
18+
roomLivingRoom: { en: 'LivingRoom', de: 'Wohnzimmer', ru: 'Гостиная', fr: 'Salon', nl: 'Woonkamer' },
19+
roomKitchen: { en: 'Kitchen', de: 'Küche', ru: 'Кухня', fr: 'Cuisine', nl: 'Keuken' },
20+
roomBedroom: { en: 'Bedroom', de: 'Schlafzimmer', ru: 'Спальня', fr: 'Chambre', nl: 'Slaapkamer' },
21+
roomChildrensRoom1: {
22+
en: 'Childrens room 1',
23+
de: 'Kinderzimmer 1',
24+
ru: 'Детская комната 1',
25+
fr: 'Salle des enfants 1',
26+
nl: 'Kinderkamer 1'
27+
},
28+
roomChildrensRoom2: {
29+
en: 'Childrens room 2',
30+
de: 'Kinderzimmer 2',
31+
ru: 'Детская комната 2',
32+
fr: 'Chambre des enfants 2',
33+
nl: 'Kinderkamer 2'
34+
},
35+
roomOffice: { en: 'Office', de: 'Büro', ru: 'Офис', fr: 'Bureau', nl: 'Kantoor' },
36+
roomBathroom: { en: 'Bathroom', de: 'Bad', ru: 'Ванная комната', fr: 'Salle de bains', nl: 'Badkamer' },
37+
roomGarage: { en: 'Garage', de: 'Garage', ru: 'Гараж', fr: 'Garage', nl: 'Garage' },
38+
roomHWR: { en: 'HWR', de: 'HWR', ru: 'HWR', fr: 'HWR', nl: 'HWR' },
39+
roomGarden: { en: 'Garden', de: 'Garten', ru: 'Сад', fr: 'Jardin', nl: 'Tuin' },
40+
roomTerrace: { en: 'Terrace', de: 'Terrasse', ru: 'Терраса', fr: 'Terrasse', nl: 'Terras' }
2341
};

lib/gulptools.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ function isObject(it) {
1919
* @returns {it is any[]}
2020
*/
2121
function isArray(it) {
22-
if (typeof Array.isArray === 'function') return Array.isArray(it);
22+
if (typeof Array.isArray === 'function') {
23+
return Array.isArray(it);
24+
}
2325
return Object.prototype.toString.call(it) === '[object Array]';
2426
}
2527

@@ -55,8 +57,10 @@ async function translateYandex(text, targetLang, apiKey) {
5557
targetLang = 'zh';
5658
}
5759
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+
const url = `https://translate.yandex.net/api/v1.5/tr.json/translate?key=${apiKey}&text=${encodeURIComponent(
61+
text
62+
)}&lang=en-${targetLang}`;
63+
const response = await axios({ url, timeout: 15000 });
6064
if (response.data && response.data.text && isArray(response.data.text)) {
6165
return response.data.text[0];
6266
}
@@ -74,18 +78,18 @@ async function translateYandex(text, targetLang, apiKey) {
7478
*/
7579
async function translateGoogle(text, targetLang) {
7680
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});
81+
const url = `http://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=${targetLang}&dt=t&q=${encodeURIComponent(
82+
text
83+
)}&ie=UTF-8&oe=UTF-8`;
84+
const response = await axios({ url, timeout: 15000 });
7985
if (isArray(response.data)) {
8086
// we got a valid response
8187
return response.data[0][0][0];
8288
}
8389
throw new Error('Invalid response for translate request');
8490
} catch (e) {
8591
if (e.response && e.response.status === 429) {
86-
throw new Error(
87-
`Could not translate to "${targetLang}": Rate-limited by Google Translate`
88-
);
92+
throw new Error(`Could not translate to "${targetLang}": Rate-limited by Google Translate`);
8993
} else {
9094
throw new Error(`Could not translate to "${targetLang}": ${e}`);
9195
}

lib/rega.js

+33-25
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ const https = require('https');
1414
const xml2js = require('xml2js');
1515
const iconv = require('iconv-lite');
1616
const request = require('request');
17-
const parser = new xml2js.Parser({explicitArray: false});
17+
const parser = new xml2js.Parser({ explicitArray: false });
1818

1919
class Rega {
20-
2120
constructor(options) {
2221
this.options = options || {};
2322
this.logger = this.options.logger;
@@ -44,27 +43,30 @@ class Rega {
4443

4544
if (this.options.ccuIp) {
4645
// if specific webinterface port provided use it, else use default https/http
47-
request({
48-
url: `${this.protocol + this.options.ccuIp}:${this.options.webinterfacePort}/ise/checkrega.cgi`,
49-
strictSSL: false
50-
}, (error, response, body) => {
51-
if (!error && response.statusCode === 200) {
52-
if (body === 'OK') {
53-
this.connected = true;
54-
this.options.ready();
46+
request(
47+
{
48+
url: `${this.protocol + this.options.ccuIp}:${this.options.webinterfacePort}/ise/checkrega.cgi`,
49+
strictSSL: false
50+
},
51+
(error, response, body) => {
52+
if (!error && response.statusCode === 200) {
53+
if (body === 'OK') {
54+
this.connected = true;
55+
this.options.ready();
56+
} else {
57+
this.connected = false;
58+
this.options.ready('ReGaHSS down');
59+
// try again in X seconds
60+
setTimeout(() => this.init(), this.options.reconnectionInterval * 1000);
61+
}
5562
} else {
5663
this.connected = false;
57-
this.options.ready('ReGaHSS down');
64+
this.options.ready('CCU unreachable');
5865
// try again in X seconds
5966
setTimeout(() => this.init(), this.options.reconnectionInterval * 1000);
6067
}
61-
} else {
62-
this.connected = false;
63-
this.options.ready('CCU unreachable');
64-
// try again in X seconds
65-
setTimeout(() => this.init(), this.options.reconnectionInterval * 1000);
6668
}
67-
});
69+
);
6870
} else {
6971
this.options.ready('No IP defined!');
7072
}
@@ -257,12 +259,14 @@ class Rega {
257259
if (script) {
258260
for (const pendingRequest of this.pendingRequests) {
259261
if (pendingRequest.script === script) {
260-
this.logger.warn(`Script "${script.slice(0, 80).replace(/\n/g, ' ')}" ignored, because still pending.`);
262+
this.logger.warn(
263+
`Script "${script.slice(0, 80).replace(/\n/g, ' ')}" ignored, because still pending.`
264+
);
261265
return;
262266
} // endIf
263267
} // endFor
264268

265-
this.pendingRequests.push({script: script, callback: callback});
269+
this.pendingRequests.push({ script: script, callback: callback });
266270

267271
if (this.pendingRequests.length > 1) {
268272
this.logger.debug(`${this.pendingRequests.length} pending requests`);
@@ -285,7 +289,7 @@ class Rega {
285289
headers: {
286290
'Content-Type': 'application/x-www-form-urlencoded',
287291
'Content-Length': this.pendingRequests[0].script.length,
288-
'Authorization': auth
292+
Authorization: auth
289293
},
290294
timeout: timeout,
291295
rejectUnauthorized: false
@@ -295,12 +299,12 @@ class Rega {
295299
let data = '';
296300
res.setEncoding('utf8');
297301

298-
res.on('data', chunk => data += chunk.toString());
302+
res.on('data', chunk => (data += chunk.toString()));
299303

300304
res.on('end', () => {
301305
const pos = data.lastIndexOf('<xml>');
302-
const stdout = (data.substring(0, pos));
303-
const xml = (data.substring(pos));
306+
const stdout = data.substring(0, pos);
307+
const xml = data.substring(pos);
304308

305309
this.logger.debug(`<-- ${stdout}`);
306310

@@ -313,7 +317,9 @@ class Rega {
313317
task.callback(stdout, result.xml);
314318
} else {
315319
if (!res.complete) {
316-
this.logger.error('The connection has been closed before fully receiving the response data');
320+
this.logger.error(
321+
'The connection has been closed before fully receiving the response data'
322+
);
317323
this.logger.error(`<-- Incomplete response: ${JSON.stringify(data)}`);
318324
} else {
319325
this.logger.error(`<-- invalid response: ${JSON.stringify(data)}`);
@@ -337,7 +343,9 @@ class Rega {
337343
});
338344

339345
post_req.on('timeout', () => {
340-
this.logger.warn(`"${this.pendingRequests[0].script.slice(0, 80)}" timed out after ${timeout / 1000} seconds`);
346+
this.logger.warn(
347+
`"${this.pendingRequests[0].script.slice(0, 80)}" timed out after ${timeout / 1000} seconds`
348+
);
341349
// timeout we abort request -> will emit error event
342350
post_req.destroy(new Error('Aborted due to timeout'));
343351
});

0 commit comments

Comments
 (0)