codemod: object-shorthand

Also fixed `new (` and `formatter` by hand.
This commit is contained in:
qm3ster
2019-03-09 16:30:05 +01:00
committed by Koen Kanters
parent 044e8466ed
commit a93838be15
8 changed files with 18 additions and 19 deletions
+2 -2
View File
@@ -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}
);
}
+1 -1
View File
@@ -88,7 +88,7 @@ class DevicePublish {
const ID = topic;
return {type: type, ID: ID, postfix: postfix};
return {type, ID, postfix};
}
handlePublishError(entity, message, error) {
+1 -1
View File
@@ -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) {
+3 -3
View File
@@ -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,
+1 -1
View File
@@ -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;
+8 -9
View File
@@ -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) : '',
}),
],
});
+1 -1
View File
@@ -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 = {
+1 -1
View File
@@ -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}]};
},
};