Skip to content

Commit b25c816

Browse files
authored
Merge pull request #297 from tim-hellhake/fix-zigbee2mqtt-logs
Fix zigbee2mqtt logs
2 parents 2e28332 + 606d6c5 commit b25c816

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/zigbee2mqtt/zigbee2mqtt-adapter.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import mqtt from 'mqtt';
1313
import { Zigbee2MqttDevice } from './zigbee2mqtt-device';
1414
import DEBUG_FLAG from '../zb-debug';
1515

16-
const debug = DEBUG_FLAG.DEBUG_zigbee2mqtt;
16+
function debug(): boolean {
17+
return DEBUG_FLAG.DEBUG_zigbee2mqtt;
18+
}
1719

1820
import manifest from '../manifest.json';
1921

@@ -87,7 +89,7 @@ export class Zigbee2MqttAdapter extends Adapter {
8789
client.on('message', (topic, message) => {
8890
const raw = message.toString();
8991

90-
if (debug) {
92+
if (debug()) {
9193
console.log(`Received on ${topic}: ${raw}`);
9294
}
9395

@@ -179,7 +181,7 @@ export class Zigbee2MqttAdapter extends Adapter {
179181
if (!existingDevice) {
180182
const device = new Zigbee2MqttDevice(this, id, deviceDefinition, client, this.prefix);
181183
this.handleDeviceAdded(device);
182-
} else if (debug) {
184+
} else if (debug()) {
183185
console.log(`Device ${id} already exists`);
184186
}
185187
} else {
@@ -210,7 +212,7 @@ export class Zigbee2MqttAdapter extends Adapter {
210212
}
211213

212214
private publish(topic: string, payload: string): void {
213-
if (debug) {
215+
if (debug()) {
214216
console.log(`Sending ${payload} to ${topic}`);
215217
}
216218

src/zigbee2mqtt/zigbee2mqtt-device.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import {
2323
import mqtt from 'mqtt';
2424
import DEBUG_FLAG from '../zb-debug';
2525

26-
const debug = DEBUG_FLAG.DEBUG_zigbee2mqtt;
26+
function debug(): boolean {
27+
return DEBUG_FLAG.DEBUG_zigbee2mqtt;
28+
}
2729

2830
const IGNORED_PROPERTIES = ['linkquality', 'local_temperature_calibration', 'running_state'];
2931

@@ -371,7 +373,7 @@ export class Zigbee2MqttDevice extends Device {
371373
);
372374

373375
if (!exists) {
374-
if (debug) {
376+
if (debug()) {
375377
console.log(`Event '${value}' does not exist on ${this.getTitle()} (${this.getId()})`);
376378
}
377379
continue;
@@ -384,7 +386,7 @@ export class Zigbee2MqttDevice extends Device {
384386

385387
if (property) {
386388
property.update(value, update);
387-
} else if (debug) {
389+
} else if (debug()) {
388390
console.log(`Property '${key}' does not exist on ${this.getTitle()} (${this.getId()})`);
389391
}
390392
}
@@ -400,7 +402,7 @@ export class Zigbee2MqttDevice extends Device {
400402
const writeTopic = `${this.deviceTopic}/set`;
401403
const json = { [name]: input };
402404

403-
if (debug) {
405+
if (debug()) {
404406
console.log(`Sending ${JSON.stringify(json)} to ${writeTopic}`);
405407
}
406408

src/zigbee2mqtt/zigbee2mqtt-property.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import { Zigbee2MqttDevice } from './zigbee2mqtt-device';
1919
import mqtt from 'mqtt';
2020
import DEBUG_FLAG from '../zb-debug';
2121

22-
const debug = DEBUG_FLAG.DEBUG_zigbee2mqtt;
22+
function debug(): boolean {
23+
return DEBUG_FLAG.DEBUG_zigbee2mqtt;
24+
}
2325

2426
export const WRITE_BIT = 0b010;
2527
export const READ_BIT = 0b100;
@@ -135,7 +137,7 @@ export class Zigbee2MqttProperty<T extends PropertyValue> extends Property<T> {
135137
const writeTopic = `${this.deviceTopic}/set`;
136138
const json = { [this.getName()]: value };
137139

138-
if (debug) {
140+
if (debug()) {
139141
console.log(`Sending ${JSON.stringify(json)} to ${writeTopic}`);
140142
}
141143

0 commit comments

Comments
 (0)