empty list of components, it is not needed after the config has been

published on MQTT
This commit is contained in:
Nicu Hodos 2025-10-07 18:58:39 +02:00
parent 5bf3db20da
commit a23bf27c50
3 changed files with 8 additions and 4 deletions

View File

@ -13,7 +13,7 @@ struct List {
void add(T* t) {
Container* c = new Container{t};
first == nullptr ? first = c : last->next = c;
isEmpty() ? first = c : last->next = c;
last = c;
}
@ -33,4 +33,8 @@ struct List {
first = last = nullptr;
}
bool isEmpty() {
return first == nullptr;
}
};

View File

@ -27,11 +27,10 @@ namespace Mqtt {
}
void publishInit() {
static bool firstTime = true;
if (firstTime) {
if (!Component::components.isEmpty()) {
Component::components.forEach([](Component* c) { c->publishConfig(); });
Component::components.empty();
HaESP::enableSensors();
firstTime = false;
}
}

View File

@ -30,6 +30,7 @@ void test_empty(void) {
list.empty();
TEST_ASSERT_EQUAL_PTR(nullptr, list.first);
TEST_ASSERT_EQUAL_PTR(list.first, list.last);
TEST_ASSERT_TRUE(list.isEmpty());
}
int main(int argc, char **argv) {