From aacf87a50cf7d44376271ae7bea76e6114e2d353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Hagelb=C3=A4ck?= Date: Fri, 23 Apr 2021 10:42:18 +0200 Subject: [PATCH] Revert mqtt v5 code since not supported by HassIO Mosquitto plugin --- plejd/MqttClient.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/plejd/MqttClient.js b/plejd/MqttClient.js index 6f42903..cddfec9 100644 --- a/plejd/MqttClient.js +++ b/plejd/MqttClient.js @@ -125,6 +125,7 @@ class MqttClient extends EventEmitter { this.client = mqtt.connect(this.config.mqttBroker, { clientId: `hassio-plejd_${Math.random().toString(16).substr(2, 8)}`, password: this.config.mqttPassword, + protocolVersion: 4, // v5 not supported by HassIO Mosquitto queueQoSZero: true, username: this.config.mqttUsername, }); @@ -136,13 +137,22 @@ class MqttClient extends EventEmitter { this.client.on('connect', () => { logger.info('Connected to MQTT.'); - this.client.subscribe(startTopics, (err) => { - if (err) { - logger.error('Unable to subscribe to status topics', err); - } + this.client.subscribe( + startTopics, + // Add below when mqtt v5 is supported in Mosquitto 1.6 or 2.0 and forward + // { + // qos: 1, + // nl: true, // don't echo back messages sent + // rap: true, // retain as published - don't force retain = 0 + // }, + (err) => { + if (err) { + logger.error('Unable to subscribe to status topics', err); + } - this.emit(MqttClient.EVENTS.connected); - }); + this.emit(MqttClient.EVENTS.connected); + }, + ); this.client.subscribe(getSubscribePath(), (err) => { if (err) { @@ -162,7 +172,7 @@ class MqttClient extends EventEmitter { logger.info('Home Assistant has started. lets do discovery.'); this.emit(MqttClient.EVENTS.connected); } else { - logger.verbose(`Mqtt command ${topic}`); + logger.verbose(`Received mqtt message on ${topic}`); const decodedTopic = decodeTopic(topic); if (decodedTopic) { /** @type {import('types/DeviceRegistry').OutputDevice} */