add support for setting retain
This commit is contained in:
parent
b4daba4cb2
commit
1fe24a5b7f
@ -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;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user