Skip to content
This repository was archived by the owner on Dec 28, 2022. It is now read-only.

Commit 7303d1b

Browse files
committed
fix lint issues
1 parent c9b6479 commit 7303d1b

File tree

6 files changed

+113
-94
lines changed

6 files changed

+113
-94
lines changed

nodes/converter.js

+37-29
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ module.exports = function (RED) {
3535
const getDevices = () => {
3636
this.trace('getDevices');
3737
const devices = this.herdsman.getDevices();
38-
devices.forEach(device => {
38+
for (const device of devices) {
3939
this.ieeeAddresses[device.ieeeAddr] = device;
4040
this.names[device.meta.name] = device;
41-
});
41+
}
42+
4243
this.groups = this.herdsman.getGroups();
4344
this.gotDevices = true;
4445
};
@@ -136,16 +137,17 @@ module.exports = function (RED) {
136137
}
137138

138139
// TODO understand postfix
139-
let endpoint = this.getEndPointFromDevice(model, device, isSet);
140-
let payload = this.getPayloadFromMsg(msg, attribute);
140+
const endpoint = this.getEndPointFromDevice(model, device, isSet);
141+
const payload = this.getPayloadFromMsg(msg, attribute);
141142

142143
// For each key in the JSON message find the matching converter.
143-
Object.keys(payload).sort(a => (['state', 'brightness'].includes(a) ? -1 : 1)).forEach(key => {
144+
for (const key of Object.keys(payload).sort(a => (['state', 'brightness'].includes(a) ? -1 : 1))) {
144145
const converter = converters.find(c => c.key.includes(key));
145146
if (!converter) {
146147
this.error(`No converter available for '${key}' (${payload[key]}) on modelID '${device.modelID}'`);
147-
return;
148+
continue;
148149
}
150+
149151
const meta = {
150152
options: {},
151153
message: payload,
@@ -160,16 +162,15 @@ module.exports = function (RED) {
160162
}
161163
};
162164
if (isSet) {
163-
if(isGroup) {
165+
if (isGroup) {
164166
this.setToGroup(converter, group, key, payload, meta, done);
165-
}
166-
else {
167+
} else {
167168
this.setToDevice(converter, endpoint, key, payload, meta, device, done);
168169
}
169170
} else { //get
170171
this.getFromDevice(converter, device, payload, endpoint, key, meta, done);
171172
}
172-
});
173+
}
173174
});
174175

175176
const messageHandler = data => {
@@ -189,7 +190,7 @@ module.exports = function (RED) {
189190
return;
190191
}
191192

192-
let model = this.getModelFromDevice(device);
193+
const model = this.getModelFromDevice(device);
193194
if (!model) {
194195
this.warn(`Received message from unsupported device with Zigbee model '${data.device.modelID}'`);
195196
this.warn('Please see: https://www.zigbee2mqtt.io/how_tos/how_to_support_new_devices.html.');
@@ -213,6 +214,7 @@ module.exports = function (RED) {
213214
);
214215
this.warn('Please see: https://www.zigbee2mqtt.io/how_tos/how_to_support_new_devices.html.');
215216
}
217+
216218
return;
217219
}
218220

@@ -235,27 +237,28 @@ module.exports = function (RED) {
235237
out.topic = this.topicReplace(config.topic, out);
236238
const publish = convertedPayload => {
237239
if (config.payload === 'plain') {
238-
Object.keys(convertedPayload).forEach(key => {
240+
for (const key of Object.keys(convertedPayload)) {
239241
if (config.attribute === '' || config.attribute === key) {
240242
const msg = {...out, topic: out.topic + '/' + key,
241243
payload: convertedPayload[key],
242244
retain: !['click', 'action', 'angle'].includes(key)};
243245
this.send(msg);
244246
}
245-
});
247+
}
246248
} else {
247249
// indicate out.payload has been "extended"
248250
// with converted data
249251
wait -= 1;
250252
Object.assign(out.payload, convertedPayload);
251253
}
252254
};
253-
converters.forEach(converter => {
255+
256+
for (const converter of converters) {
254257
const convertedPayload = converter.convert(model, data, publish, {}, device.meta);
255258
if (convertedPayload && Object.keys(convertedPayload).length > 0) {
256259
publish(convertedPayload);
257260
}
258-
});
261+
}
259262

260263
// if at least one converter produced out.payload data
261264
// send the combined result
@@ -295,18 +298,18 @@ module.exports = function (RED) {
295298
getModelFromDevice(device) {
296299
if (this.models.has(device.modelID)) {
297300
return this.models.get(device.modelID);
298-
} else {
299-
let model = herdsmanConverters.findByDevice(device);
300-
this.models.set(device.modelID, model);
301-
return model;
302301
}
302+
303+
const model = herdsmanConverters.findByDevice(device);
304+
this.models.set(device.modelID, model);
305+
return model;
303306
}
304307

305308
getPayloadFromMsg(msg, attribute) {
306309
if (typeof msg.payload === 'string' && msg.payload.startsWith('{')) {
307310
try {
308311
msg.payload = JSON.parse(msg.payload);
309-
} catch { }
312+
} catch {}
310313
}
311314

312315
let payload;
@@ -317,22 +320,25 @@ module.exports = function (RED) {
317320
payload = msg.payload;
318321
} else if (typeof msg.payload === 'string') {
319322
// No attribute supplied, payload not an object - assume state.
320-
payload = { state: msg.payload };
323+
payload = {state: msg.payload};
321324
} else {
322-
payload = { state: msg.payload ? 'ON' : 'OFF' };
325+
payload = {state: msg.payload ? 'ON' : 'OFF'};
323326
}
327+
324328
return payload;
325329
}
326330

327331
getEndPointFromDevice(model, device, isSet) {
328332
if (typeof model.endpoint === 'undefined') {
329333
return device.endpoints[0];
330334
}
335+
331336
const endpoints = model.endpoint(device);
332-
let endpoint = endpoints[isSet ? 'set' : 'get'];
333-
if((endpoint === null || typeof endpoint === 'undefined') && eps.default !== 'undefined') {
337+
const endpoint = endpoints[isSet ? 'set' : 'get'];
338+
if ((endpoint === null || typeof endpoint === 'undefined') && eps.default !== 'undefined') {
334339
return eps.default;
335340
}
341+
336342
return device.endpoints[0];
337343
}
338344

@@ -341,6 +347,7 @@ module.exports = function (RED) {
341347
this.error(`Converter can not read '${key}' (${payload[key]}) on modelID '${device.modelID}'`);
342348
return;
343349
}
350+
344351
converter.convertGet(endpoint, key, meta).then(result => {
345352
this.handleResult(device, result);
346353
done();
@@ -356,6 +363,7 @@ module.exports = function (RED) {
356363
if (result && typeof result.readAfterWriteTime === 'undefined' && !device.meta.reporting) {
357364
result.readAfterWriteTime = 0;
358365
}
366+
359367
if (result && typeof result.readAfterWriteTime !== 'undefined' && !device.meta.reporting) {
360368
setTimeout(() => {
361369
this.debug(`readAfterWrite ${device.ieeeAddr} ${device.meta.name}`);
@@ -395,23 +403,23 @@ module.exports = function (RED) {
395403
}
396404

397405
const msgLower = {};
398-
Object.keys(msg).forEach(k => {
406+
for (const k of Object.keys(msg)) {
399407
msgLower[k.toLowerCase()] = msg[k];
400-
});
408+
}
401409

402410
const match = topic.match(/\${[^}]+}/g);
403411
if (match) {
404-
match.forEach(v => {
412+
for (const v of match) {
405413
const key = v.substr(2, v.length - 3);
406414
const rx = new RegExp('\\${' + key + '}', 'g');
407415
const rkey = key.toLowerCase();
408416
topic = topic.replace(rx, msgLower[rkey] || '');
409-
});
417+
}
410418
}
411419

412420
return topic;
413421
}
414422
}
415423

416424
RED.nodes.registerType('zigbee-converter', ZigbeeConverter);
417-
};
425+
};

nodes/event.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module.exports = function (RED) {
5050

5151
});
5252
} else {
53-
Object.keys(message.data).forEach(attribute => {
53+
for (const attribute of Object.keys(message.data)) {
5454
topicAttrs.attribute = attribute;
5555
this.send({
5656
topic: this.topicReplace(config.topic, topicAttrs),
@@ -65,7 +65,7 @@ module.exports = function (RED) {
6565
profileID: message.endpoint.profileID,
6666
groupID: message.groupID
6767
});
68-
});
68+
}
6969
}
7070
}
7171
};
@@ -87,18 +87,18 @@ module.exports = function (RED) {
8787
}
8888

8989
const msgLower = {};
90-
Object.keys(msg).forEach(k => {
90+
for (const k of Object.keys(msg)) {
9191
msgLower[k.toLowerCase()] = msg[k];
92-
});
92+
}
9393

9494
const match = topic.match(/\${[^}]+}/g);
9595
if (match) {
96-
match.forEach(v => {
96+
for (const v of match) {
9797
const key = v.substr(2, v.length - 3);
9898
const rx = new RegExp('\\${' + key + '}', 'g');
9999
const rkey = key.toLowerCase();
100100
topic = topic.replace(rx, msgLower[rkey] || '');
101-
});
101+
}
102102
}
103103

104104
return topic.replace(/\/$/, '');

nodes/hue-device.js

+21-16
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ module.exports = function (RED) {
2828
this.trace('getDevices');
2929
this.devices = shepherdNode.herdsman.getDevices();
3030
this.groups = shepherdNode.herdsman.getGroups();
31-
this.devices.forEach(device => {
31+
for (const device of this.devices) {
3232
if (device.ieeeAddr === this.device) {
3333
this.initLight(device);
3434
}
35-
});
35+
}
36+
3637
this.gotDevices = true;
3738
};
3839

@@ -491,42 +492,46 @@ module.exports = function (RED) {
491492

492493
this.debug(`putLightState ${device.ieeeAddr} ${device.meta.name} ${JSON.stringify(msg.payload)}`);
493494

494-
cmds.forEach(cmd => {
495+
for (const cmd of cmds) {
495496
this.shepherdNode.command(device.ieeeAddr, device.endpoints[0].ID, cmd.cid, cmd.cmd, cmd.zclData, cmd.options)
496497
.then(() => {
497498
if (cmd.attributes) {
498499
const data = {};
499-
cmd.attributes.forEach(attr => {
500+
for (const attr of cmd.attributes) {
500501
data[attr] = msg.payload[attr];
501-
});
502+
}
503+
502504
update = update || oe.extend(device.meta.hue.state, data);
503505
}
504506
}).catch(() => {}).finally(() => {
505507
if (--todo === 0 && update) {
506508
this.publishLightState(device, send, done);
507509
}
508510
});
509-
});
511+
}
512+
510513
break;
511514

512515
case 'groups':
513516
this.debug(`putGroupState ${group.groupID} ${JSON.stringify(msg.payload)}`);
514-
cmds.forEach(cmd => {
517+
for (const cmd of cmds) {
515518
this.shepherdNode.groupCommand(group.groupID, cmd.cid, cmd.cmd, cmd.zclData, cmd.options)
516519
.then(() => {
517520
if (cmd.attributes) {
518521
const data = {};
519-
cmd.attributes.forEach(attr => {
522+
for (const attr of cmd.attributes) {
520523
data[attr] = msg.payload[attr];
521-
});
524+
}
525+
522526
update = update || oe.extend(device.meta.hue.state, data);
523527
}
524528
}).catch(() => {}).finally(() => {
525529
if (--todo === 0 && update) {
526530
//this.publishLightState(device);
527531
}
528532
});
529-
});
533+
}
534+
530535
break;
531536

532537
default:
@@ -567,7 +572,7 @@ module.exports = function (RED) {
567572
this.lastState[lightIndex].reachable = newState.reachable;
568573
}
569574

570-
Object.keys(newState).forEach(attr => {
575+
for (const attr of Object.keys(newState)) {
571576
if (attr === 'xy' && !this.lastState[lightIndex].xy) {
572577
this.lastState[lightIndex].xy = [];
573578
}
@@ -592,7 +597,7 @@ module.exports = function (RED) {
592597

593598
this.lastState[lightIndex][attr] = newState[attr];
594599
}
595-
});
600+
}
596601

597602
if (change && (this.config.payload.includes('mqttsh'))) {
598603
send({
@@ -626,18 +631,18 @@ module.exports = function (RED) {
626631
}
627632

628633
const msgLower = {};
629-
Object.keys(msg).forEach(k => {
634+
for (const k of Object.keys(msg)) {
630635
msgLower[k.toLowerCase()] = msg[k];
631-
});
636+
}
632637

633638
const match = topic.match(/\${[^}]+}/g);
634639
if (match) {
635-
match.forEach(v => {
640+
for (const v of match) {
636641
const key = v.substr(2, v.length - 3);
637642
const rx = new RegExp('\\${' + key + '}', 'g');
638643
const rkey = key.toLowerCase();
639644
topic = topic.replace(rx, msgLower[rkey] || '');
640-
});
645+
}
641646
}
642647

643648
return topic;

0 commit comments

Comments
 (0)