move config publishing inside Component
This commit is contained in:
parent
f2e3e1940e
commit
1b438fb141
@ -92,6 +92,20 @@ namespace Ha {
|
|||||||
buildUniqueId(uniqueId);
|
buildUniqueId(uniqueId);
|
||||||
jsonDoc["unique_id"] = 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;
|
List<Component> Component::components;
|
||||||
|
|||||||
@ -50,31 +50,17 @@ namespace Mqtt {
|
|||||||
OilSensorBuilder::build("7")
|
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() {
|
void publishInit() {
|
||||||
Ha::publisher = publish;
|
Ha::publisher = publish;
|
||||||
List<Component>::exec(Component::components, [](Component* c)
|
List<Component>::exec(Component::components, [](Component* c)
|
||||||
{ publishComponentConfig(*c); });
|
{ c->publishConfig(); });
|
||||||
AbstractBuilder::deleteAll();
|
AbstractBuilder::deleteAll();
|
||||||
ts.deleteTask(tPublishInit);
|
ts.deleteTask(tPublishInit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishCleanupConfig() {
|
void publishCleanupConfig() {
|
||||||
List<Component>::exec(Component::components, [](Component* c)
|
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) {
|
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