read initial state, after restart, from MQTT

simply by using retain, the client will get the latest state upon
subscribe
This commit is contained in:
Nicu Hodos 2023-10-30 17:09:26 +01:00
parent ffe4b91ac6
commit fe5552a0b1
2 changed files with 6 additions and 3 deletions

View File

@ -91,6 +91,11 @@ namespace Ha {
sprintf(commandTopic, "homeassistant/%s/esp_clock/%s/set", type, id);
}
void buildConfig(JsonDocument& jsonDoc) override {
Command::buildConfig(jsonDoc);
jsonDoc["retain"] = true;
}
};
struct Brightness : Command {
@ -102,6 +107,7 @@ namespace Ha {
void buildConfig(JsonDocument& jsonDoc) override {
Command::buildConfig(jsonDoc);
jsonDoc["retain"] = true;
jsonDoc["min"] = BRIGHTNESS_MIN;
jsonDoc["max"] = BRIGHTNESS_MAX;
jsonDoc["step"] = BRIGHTNESS_STEP;

View File

@ -116,9 +116,6 @@ namespace Mqtt {
for (Ha::Component* cmp : switches) {
publishComponentConfig(*cmp);
}
brightnessMqtt->publishState();
hourFormatMqtt->publishState();
ledMqtt->publishState();
ts.deleteTask(tPublishInit);
}