fix topic filter

This commit is contained in:
2024-08-14 17:44:12 +02:00
parent 06da8f5b97
commit 6a2c15500d

View File

@@ -38,26 +38,27 @@ class Lineplug extends DeviceBase {
// monitor queue // monitor queue
this.mqtt.on('message', (topic, message) => { this.mqtt.on('message', (topic, message) => {
// message is Buffer // message is Buffer
let payload = message.toString() if (topic == this.topic_set) { // verify that the topic is correct
this.logger.debug(`input ${topic}: ${payload}`) let payload = message.toString()
this.logger.debug(`input ${topic}: ${payload}`)
try { try {
const jsonpayload = JSON.parse(payload) const jsonpayload = JSON.parse(payload)
if (jsonpayload.value != undefined) { if (jsonpayload.value != undefined) {
this.logger.info(`Change status to ${jsonpayload.value}`) this.logger.info(`Change status to ${jsonpayload.value}`)
this.device.set({ set: jsonpayload.value }).then(el => { this.device.set({ set: jsonpayload.value }).then(el => {
this.device.refresh() this.device.refresh()
}) })
}
} catch (error) {
this.logger.warn(`Error parsing malformatted JSON message via mqtt`)
this.logger.trace(payload)
this.logger.trace(error)
} }
} catch (error) {
this.logger.warn(`Error parsing malformatted JSON message via mqtt`)
this.logger.trace(payload)
this.logger.trace(error)
} }
}) })
} }
stopWatcher(){ stopWatcher() {
clearInterval(this.timer) clearInterval(this.timer)
} }