unify execution of containers inside the list
This commit is contained in:
parent
ae525d7e15
commit
6a287007d7
@ -45,12 +45,12 @@ namespace Mqtt {
|
|||||||
(new PollinSwitch{"Train", "11111", 4, "Playroom"})->withStateTopic()
|
(new PollinSwitch{"Train", "11111", 4, "Playroom"})->withStateTopic()
|
||||||
};
|
};
|
||||||
|
|
||||||
Ha::Sensor* sensors[] = {
|
Sensor* sensors[] = {
|
||||||
OilTankRoomSensorBuilder::build("4"),
|
OilTankRoomSensorBuilder::build("4"),
|
||||||
OilSensorBuilder::build("7")
|
OilSensorBuilder::build("7")
|
||||||
};
|
};
|
||||||
|
|
||||||
void publishComponentConfig(Ha::Component& component) {
|
void publishComponentConfig(Component& component) {
|
||||||
StaticJsonDocument<JSON_SIZE> jsonDoc;
|
StaticJsonDocument<JSON_SIZE> jsonDoc;
|
||||||
component.buildConfig(jsonDoc);
|
component.buildConfig(jsonDoc);
|
||||||
|
|
||||||
@ -60,18 +60,20 @@ namespace Mqtt {
|
|||||||
publish(component.configTopic, message);
|
publish(component.configTopic, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void publishCleanupComponentConfig(Component& component) {
|
||||||
|
publish(component.configTopic, "");
|
||||||
|
}
|
||||||
|
|
||||||
void publishInit() {
|
void publishInit() {
|
||||||
Ha::publisher = publish;
|
Ha::publisher = publish;
|
||||||
for (List<Ha::Component>::Container* c = Ha::Component::components.first; c; c = c->next) {
|
List<Component>::exec(Component::components, [](Component* c)
|
||||||
publishComponentConfig(*c->t);
|
{ publishComponentConfig(*c); });
|
||||||
}
|
|
||||||
ts.deleteTask(tPublishInit);
|
ts.deleteTask(tPublishInit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishCleanupConfig() {
|
void publishCleanupConfig() {
|
||||||
for (List<Ha::Component>::Container* c = Ha::Component::components.first; c; c = c->next) {
|
List<Component>::exec(Component::components, [](Component* c)
|
||||||
publish(c->t->configTopic, "");
|
{ publishCleanupComponentConfig(*c); });
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
|||||||
@ -17,4 +17,10 @@ struct List {
|
|||||||
last = c;
|
last = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void exec(List list, void(*f)(T*)) {
|
||||||
|
for (List::Container *c = list.first; c; c = c->next) {
|
||||||
|
f(c->t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user