move config publishing inside Component

This commit is contained in:
Nicu Hodos 2024-05-15 10:33:09 +02:00
parent f2e3e1940e
commit 1b438fb141
2 changed files with 16 additions and 16 deletions

View File

@ -92,6 +92,20 @@ namespace Ha {
buildUniqueId(uniqueId);
jsonDoc["unique_id"] = uniqueId;
}
void publishConfig() {
StaticJsonDocument<JSON_SIZE> jsonDoc;
buildConfig(jsonDoc);
char message[JSON_SIZE];
serializeJson(jsonDoc, message);
publisher(configTopic, message);
}
void publishCleanupConfig() {
publisher(configTopic, "");
}
};
List<Component> Component::components;

View File

@ -50,31 +50,17 @@ namespace Mqtt {
OilSensorBuilder::build("7")
};
void publishComponentConfig(Component& component) {
StaticJsonDocument<JSON_SIZE> jsonDoc;
component.buildConfig(jsonDoc);
char message[JSON_SIZE];
serializeJson(jsonDoc, message);
publish(component.configTopic, message);
}
void publishCleanupComponentConfig(Component& component) {
publish(component.configTopic, "");
}
void publishInit() {
Ha::publisher = publish;
List<Component>::exec(Component::components, [](Component* c)
{ publishComponentConfig(*c); });
{ c->publishConfig(); });
AbstractBuilder::deleteAll();
ts.deleteTask(tPublishInit);
}
void publishCleanupConfig() {
List<Component>::exec(Component::components, [](Component* c)
{ publishCleanupComponentConfig(*c); });
{ c->publishCleanupConfig(); });
}
void onMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {