From a93838be1525f17ee7fb49ee5ad96a0c27fcd134 Mon Sep 17 00:00:00 2001 From: qm3ster Date: Fri, 8 Mar 2019 18:39:47 +0200 Subject: [PATCH] codemod: object-shorthand Also fixed `new (` and `formatter` by hand. --- lib/extension/deviceBind.js | 4 ++-- lib/extension/devicePublish.js | 2 +- lib/extension/groups.js | 2 +- lib/extension/livolo.js | 6 +++--- lib/mqtt.js | 2 +- lib/util/logger.js | 17 ++++++++--------- lib/util/settings.js | 2 +- test/utils.js | 2 +- 8 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/extension/deviceBind.js b/lib/extension/deviceBind.js index 1f86f7479..829d43d10 100644 --- a/lib/extension/deviceBind.js +++ b/lib/extension/deviceBind.js @@ -43,7 +43,7 @@ class DeviceBind { // Remove type from topic topic = topic.replace(`${type}/`, ''); - return {ID: topic, type: type}; + return {ID: topic, type}; } onMQTTMessage(topic, message) { @@ -111,7 +111,7 @@ class DeviceBind { this.mqtt.log( `device_${topic.type}`, - {from: sourceEntity.ID, to: targetEntity.ID, cluster: cluster} + {from: sourceEntity.ID, to: targetEntity.ID, cluster} ); } diff --git a/lib/extension/devicePublish.js b/lib/extension/devicePublish.js index 2afa5e549..69c2f2327 100644 --- a/lib/extension/devicePublish.js +++ b/lib/extension/devicePublish.js @@ -88,7 +88,7 @@ class DevicePublish { const ID = topic; - return {type: type, ID: ID, postfix: postfix}; + return {type, ID, postfix}; } handlePublishError(entity, message, error) { diff --git a/lib/extension/groups.js b/lib/extension/groups.js index 3f1c073bd..e543cb498 100644 --- a/lib/extension/groups.js +++ b/lib/extension/groups.js @@ -31,7 +31,7 @@ class Groups { // Remove type from topic topic = topic.replace(`/${type}`, ''); - return {friendly_name: topic, type: type}; + return {friendly_name: topic, type}; } onMQTTMessage(topic, message) { diff --git a/lib/extension/livolo.js b/lib/extension/livolo.js index d81bfb715..ed09600d2 100644 --- a/lib/extension/livolo.js +++ b/lib/extension/livolo.js @@ -107,7 +107,7 @@ class Livolo { ep.functional('genOnOff', 'toggle', [cfg], foundationCfg, this._handleCommandRespSimple.bind({ device: zdev, - ieeeAddr: ieeeAddr, + ieeeAddr, cid: 'genOnOff', ctype: 'toggle', ext: this, @@ -123,8 +123,8 @@ class Livolo { attrId: 0, // onOff }], this._handleCommandRespWithData.bind({ device: zdev, - ieeeAddr: ieeeAddr, - ep: ep, + ieeeAddr, + ep, cid: 'genOnOff', ctype: 'read', ext: this, diff --git a/lib/mqtt.js b/lib/mqtt.js index 1e303dd07..0e72b9436 100644 --- a/lib/mqtt.js +++ b/lib/mqtt.js @@ -96,7 +96,7 @@ class MQTT { } log(type, message, meta=null) { - const payload = {type: type, message: message}; + const payload = {type, message}; if (meta) { payload.meta = meta; diff --git a/lib/util/logger.js b/lib/util/logger.js index 0f504e1f5..6c1a7a080 100644 --- a/lib/util/logger.js +++ b/lib/util/logger.js @@ -17,23 +17,22 @@ const directory = settings.get().advanced.log_directory.replace('%TIMESTAMP%', t fx.mkdirSync(directory); // Create logger -const logger = new (winston.Logger)({ +const logger = new winston.Logger({ transports: [ - new (winston.transports.File)({ + new winston.transports.File({ filename: path.join(directory, 'log.txt'), json: false, - level: level, + level, maxFiles: 3, // Keep last 3 files maxsize: 10000000, // 10MB timestamp: () => new Date().toLocaleString(), }), - new (winston.transports.Console)({ + new winston.transports.Console({ timestamp: () => new Date().toLocaleString(), - formatter: function(options) { - return winston.config.colorize(options.level, ' zigbee2mqtt:' + options.level.toLowerCase()) + ' ' + - options.timestamp() + ' ' + (options.message ? options.message : '') + - (options.meta && Object.keys(options.meta).length ? '\n\t'+ JSON.stringify(options.meta) : '' ); - }, + formatter: (options) => + winston.config.colorize(options.level, ` zigbee2mqtt:${options.level.toLowerCase()}`) + + ` ${options.timestamp()} ${options.message || ''}` + + options.meta && Object.keys(options.meta).length ? '\n\t'+ JSON.stringify(options.meta) : '', }), ], }); diff --git a/lib/util/settings.js b/lib/util/settings.js index 3ae0ddfa9..65442959b 100644 --- a/lib/util/settings.js +++ b/lib/util/settings.js @@ -240,7 +240,7 @@ function resolveEntity(ID) { friendlyName = device ? device.friendly_name : ID; } - return {ID: ID, type: type, friendlyName: friendlyName}; + return {ID, type, friendlyName}; } module.exports = { diff --git a/test/utils.js b/test/utils.js index 086ce58b4..9f7fefd1b 100644 --- a/test/utils.js +++ b/test/utils.js @@ -8,6 +8,6 @@ module.exports = { sandbox.stub(logger, 'error').callsFake(() => {}); }, zigbeeMessage: (device, cid, type, data, epId) => { - return {data: {cid: cid, data: data}, type: type, endpoints: [{device: device, epId: epId}]}; + return {data: {cid, data}, type, endpoints: [{device, epId}]}; }, };