From 661eea9db8a6264db398557e870ac26c7d05d78e Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Wed, 29 May 2024 16:09:54 +0200 Subject: [PATCH] add support for setting retain --- gateway/include/ha.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gateway/include/ha.h b/gateway/include/ha.h index c280d02..4a16eb8 100644 --- a/gateway/include/ha.h +++ b/gateway/include/ha.h @@ -179,9 +179,16 @@ namespace Ha { cmp->mainDevice = deviceConfig; return *this; } + + Builder& withRetain(bool retain = true) { + cmp->retain = retain; + return *this; + } + }; struct Command : Component { + bool retain = false; char commandTopic[TOPIC_SIZE]; onMessage f; static unordered_map mapCommands; @@ -198,6 +205,7 @@ namespace Ha { void buildConfig(JsonDocument& jsonDoc) override { Component::buildConfig(jsonDoc); jsonDoc["command_topic"] = commandTopic; + if (retain) jsonDoc["retain"] = true; } };