implement dedup for mqtt messages

This commit is contained in:
Johannes
2022-09-05 21:59:19 +02:00
parent 99c86331a9
commit cc3ed54cdc
2 changed files with 19 additions and 8 deletions

View File

@@ -59,3 +59,18 @@ class LuiMqttListener(object):
if msg[1] == "pageOpenDetail":
self._controller.detail_open(msg[2], msg[3])
class LuiMqttSender(object):
def __init__(self, api, mqttapi, topic_send):
self._ha_api = api
self._mqtt_api = mqttapi
self._topic_send = topic_send
self._prev_msg = ""
def send_mqtt_msg(self, msg, topic=None):
if self._prev_msg == msg:
return
self._prev_msg = msg
if topic is None:
topic = self._topic_send
self._ha_api.log(f"Sending MQTT Message: {msg}")
self._mqtt_api.mqtt_publish(topic, msg)

View File

@@ -2,7 +2,7 @@ import hassapi as hass
from luibackend.config import LuiBackendConfig
from luibackend.controller import LuiController
from luibackend.mqttListener import LuiMqttListener
from luibackend.mqtt import LuiMqttListener, LuiMqttSender
from luibackend.updater import Updater
class NsPanelLovelaceUIManager(hass.Hass):
@@ -13,16 +13,12 @@ class NsPanelLovelaceUIManager(hass.Hass):
cfg = self._cfg = LuiBackendConfig(self, self.args["config"])
topic_send = cfg.get("panelSendTopic")
def send_mqtt_msg(msg, topic=None):
if topic is None:
topic = topic_send
self.log(f"Sending MQTT Message: {msg}")
mqtt_api.mqtt_publish(topic, msg)
mqttsend = LuiMqttSender(self, mqtt_api, topic_send)
# Request Tasmota Driver Version
mqtt_api.mqtt_publish(topic_send.replace("CustomSend", "GetDriverVersion"), "x")
controller = LuiController(self, cfg, send_mqtt_msg)
controller = LuiController(self, cfg, mqttsend.send_mqtt_msg)
desired_display_firmware_version = 41
version = "v3.3.1"
@@ -43,7 +39,7 @@ class NsPanelLovelaceUIManager(hass.Hass):
mode = cfg.get("updateMode")
topic_send = cfg.get("panelSendTopic")
updater = Updater(self.log, send_mqtt_msg, topic_send, mode, desired_display_firmware_version, model, desired_display_firmware_url, desired_tasmota_driver_version, desired_tasmota_driver_url)
updater = Updater(self.log, mqttsend.send_mqtt_msg, topic_send, mode, desired_display_firmware_version, model, desired_display_firmware_url, desired_tasmota_driver_version, desired_tasmota_driver_url)
topic_recv = cfg.get("panelRecvTopic")
LuiMqttListener(mqtt_api, topic_recv, controller, updater)