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; } };