From b5affda9605a1e8244b8c323660a5b08de1f35c3 Mon Sep 17 00:00:00 2001 From: LaboDJ Date: Fri, 15 May 2020 09:44:19 +0200 Subject: [PATCH 1/3] Add option to set retained config to /set topic It's useful when you have a device that doesn't need to restore it's state after a power loss or a reboot. It's even more useful when you use this library in a device used as a "forwarder" for another device state. --- src/SendingPromise.cpp | 9 ++++++++- src/SendingPromise.hpp | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/SendingPromise.cpp b/src/SendingPromise.cpp index 46b7afc3..302641b7 100644 --- a/src/SendingPromise.cpp +++ b/src/SendingPromise.cpp @@ -7,6 +7,7 @@ SendingPromise::SendingPromise() , _property(nullptr) , _qos(0) , _retained(false) +, _setRetained(true) , _overwriteSetter(false) , _range { .isRange = false, .index = 0 } { } @@ -21,6 +22,12 @@ SendingPromise& SendingPromise::setRetained(bool retained) { return *this; } +SendingPromise &SendingPromise::setSetRetained(bool retained) +{ + _setRetained = retained; + return *this; +} + SendingPromise& SendingPromise::overwriteSetter(bool overwrite) { _overwriteSetter = overwrite; return *this; @@ -66,7 +73,7 @@ uint16_t SendingPromise::send(const String& value) { if (_overwriteSetter) { strcat_P(topic, PSTR("/set")); - Interface::get().getMqttClient().publish(topic, 1, true, value.c_str()); + Interface::get().getMqttClient().publish(topic, 1, _setRetained, value.c_str()); } delete[] topic; diff --git a/src/SendingPromise.hpp b/src/SendingPromise.hpp index 353d9144..350765d9 100644 --- a/src/SendingPromise.hpp +++ b/src/SendingPromise.hpp @@ -15,6 +15,7 @@ class SendingPromise { SendingPromise(); SendingPromise& setQos(uint8_t qos); SendingPromise& setRetained(bool retained); + SendingPromise& setSetRetained(bool retained); SendingPromise& overwriteSetter(bool overwrite); SendingPromise& setRange(const HomieRange& range); SendingPromise& setRange(uint16_t rangeIndex); @@ -34,6 +35,7 @@ class SendingPromise { const String* _property; uint8_t _qos; bool _retained; + bool _setRetained; bool _overwriteSetter; HomieRange _range; }; From ec936e8659c637aad1c67a919742f1ab0efe7d00 Mon Sep 17 00:00:00 2001 From: LaboDJ Date: Fri, 15 May 2020 09:56:13 +0200 Subject: [PATCH 2/3] Fix for CircleCI lint. --- src/SendingPromise.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/SendingPromise.cpp b/src/SendingPromise.cpp index 302641b7..857fbaae 100644 --- a/src/SendingPromise.cpp +++ b/src/SendingPromise.cpp @@ -22,8 +22,7 @@ SendingPromise& SendingPromise::setRetained(bool retained) { return *this; } -SendingPromise &SendingPromise::setSetRetained(bool retained) -{ +SendingPromise &SendingPromise::setSetRetained(bool retained) { _setRetained = retained; return *this; } From 4bbe3e47f4cb1f75c68ab6601efafc9fc80758ec Mon Sep 17 00:00:00 2001 From: LaboDJ Date: Fri, 25 Dec 2020 10:49:21 +0100 Subject: [PATCH 3/3] Use MQTT qos 2 when /set topic is updated --- src/SendingPromise.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SendingPromise.cpp b/src/SendingPromise.cpp index 857fbaae..e0a893f2 100644 --- a/src/SendingPromise.cpp +++ b/src/SendingPromise.cpp @@ -72,7 +72,7 @@ uint16_t SendingPromise::send(const String& value) { if (_overwriteSetter) { strcat_P(topic, PSTR("/set")); - Interface::get().getMqttClient().publish(topic, 1, _setRetained, value.c_str()); + Interface::get().getMqttClient().publish(topic, 2, _setRetained, value.c_str()); } delete[] topic;