add support for setting retain
This commit is contained in:
parent
9b2e332587
commit
661eea9db8
@ -179,9 +179,16 @@ namespace Ha {
|
|||||||
cmp->mainDevice = deviceConfig;
|
cmp->mainDevice = deviceConfig;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Builder& withRetain(bool retain = true) {
|
||||||
|
cmp->retain = retain;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Command : Component {
|
struct Command : Component {
|
||||||
|
bool retain = false;
|
||||||
char commandTopic[TOPIC_SIZE];
|
char commandTopic[TOPIC_SIZE];
|
||||||
onMessage f;
|
onMessage f;
|
||||||
static unordered_map<string, Command*> mapCommands;
|
static unordered_map<string, Command*> mapCommands;
|
||||||
@ -198,6 +205,7 @@ namespace Ha {
|
|||||||
void buildConfig(JsonDocument& jsonDoc) override {
|
void buildConfig(JsonDocument& jsonDoc) override {
|
||||||
Component::buildConfig(jsonDoc);
|
Component::buildConfig(jsonDoc);
|
||||||
jsonDoc["command_topic"] = commandTopic;
|
jsonDoc["command_topic"] = commandTopic;
|
||||||
|
if (retain) jsonDoc["retain"] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user