mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-27 21:20:03 +00:00
codemod: object-shorthand
Also fixed `new (` and `formatter` by hand.
This commit is contained in:
@@ -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}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ class DevicePublish {
|
||||
|
||||
const ID = topic;
|
||||
|
||||
return {type: type, ID: ID, postfix: postfix};
|
||||
return {type, ID, postfix};
|
||||
}
|
||||
|
||||
handlePublishError(entity, message, error) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
@@ -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
@@ -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) : '',
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
@@ -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
@@ -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}]};
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user