move config publishing inside Component
This commit is contained in:
parent
5ffe88ee82
commit
e9e30ae025
@ -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;
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user