add support for setting retain

This commit is contained in:
Nicu Hodos 2024-05-29 16:09:54 +02:00
parent b4daba4cb2
commit 1fe24a5b7f

View File

@ -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<string, Command*> mapCommands;
@ -198,6 +205,7 @@ namespace Ha {
void buildConfig(JsonDocument& jsonDoc) override {
Component::buildConfig(jsonDoc);
jsonDoc["command_topic"] = commandTopic;
if (retain) jsonDoc["retain"] = true;
}
};