empty list of components, it is not needed after the config has been
published on MQTT
This commit is contained in:
parent
5bf3db20da
commit
a23bf27c50
@ -13,7 +13,7 @@ struct List {
|
|||||||
|
|
||||||
void add(T* t) {
|
void add(T* t) {
|
||||||
Container* c = new Container{t};
|
Container* c = new Container{t};
|
||||||
first == nullptr ? first = c : last->next = c;
|
isEmpty() ? first = c : last->next = c;
|
||||||
last = c;
|
last = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,4 +33,8 @@ struct List {
|
|||||||
first = last = nullptr;
|
first = last = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isEmpty() {
|
||||||
|
return first == nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -27,11 +27,10 @@ namespace Mqtt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void publishInit() {
|
void publishInit() {
|
||||||
static bool firstTime = true;
|
if (!Component::components.isEmpty()) {
|
||||||
if (firstTime) {
|
|
||||||
Component::components.forEach([](Component* c) { c->publishConfig(); });
|
Component::components.forEach([](Component* c) { c->publishConfig(); });
|
||||||
|
Component::components.empty();
|
||||||
HaESP::enableSensors();
|
HaESP::enableSensors();
|
||||||
firstTime = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,7 @@ void test_empty(void) {
|
|||||||
list.empty();
|
list.empty();
|
||||||
TEST_ASSERT_EQUAL_PTR(nullptr, list.first);
|
TEST_ASSERT_EQUAL_PTR(nullptr, list.first);
|
||||||
TEST_ASSERT_EQUAL_PTR(list.first, list.last);
|
TEST_ASSERT_EQUAL_PTR(list.first, list.last);
|
||||||
|
TEST_ASSERT_TRUE(list.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user