From c96762c7650f3d45b18174f3412ba854f3774d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=B6hm?= Date: Fri, 13 Sep 2024 17:26:30 +0200 Subject: [PATCH] Fix: don't republish MQTT powermeter data to MQTT (#1250) --- include/PowerMeterMqtt.h | 4 +++- src/PowerMeter.cpp | 3 +++ src/PowerMeterMqtt.cpp | 8 -------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/include/PowerMeterMqtt.h b/include/PowerMeterMqtt.h index e63309f67..b12e919bc 100644 --- a/include/PowerMeterMqtt.h +++ b/include/PowerMeterMqtt.h @@ -18,7 +18,6 @@ class PowerMeterMqtt : public PowerMeterProvider { bool init() final; void loop() final { } float getPowerTotal() const final; - void doMqttPublish() const final; private: using MsgProperties = espMqttClientTypes::MessageProperties; @@ -26,6 +25,9 @@ class PowerMeterMqtt : public PowerMeterProvider { uint8_t const* payload, size_t len, size_t index, size_t total, float* targetVariable, PowerMeterMqttValue const* cfg); + // we don't need to republish data received from MQTT + void doMqttPublish() const final { }; + PowerMeterMqttConfig const _cfg; using power_values_t = std::array; diff --git a/src/PowerMeter.cpp b/src/PowerMeter.cpp index 3787dfe75..b6041e34e 100644 --- a/src/PowerMeter.cpp +++ b/src/PowerMeter.cpp @@ -87,5 +87,8 @@ void PowerMeterClass::loop() std::lock_guard lock(_mutex); if (!_upProvider) { return; } _upProvider->loop(); + + auto const& pmcfg = Configuration.get().PowerMeter; + if (pmcfg.Source == static_cast(PowerMeterProvider::Type::MQTT)) { return; } _upProvider->mqttLoop(); } diff --git a/src/PowerMeterMqtt.cpp b/src/PowerMeterMqtt.cpp index 787973702..99a51a69e 100644 --- a/src/PowerMeterMqtt.cpp +++ b/src/PowerMeterMqtt.cpp @@ -80,11 +80,3 @@ float PowerMeterMqtt::getPowerTotal() const for (auto v: _powerValues) { sum += v; } return sum; } - -void PowerMeterMqtt::doMqttPublish() const -{ - std::lock_guard l(_mutex); - mqttPublish("power1", _powerValues[0]); - mqttPublish("power2", _powerValues[1]); - mqttPublish("power3", _powerValues[2]); -}