Introduce call_dump_config() indirection (#2325)

This commit is contained in:
Oxan van Leeuwen 2021-09-20 11:16:31 +02:00 committed by GitHub
parent 2d7f8b3bdf
commit 1e8e471dec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 2 deletions

View file

@ -186,6 +186,12 @@ void MQTTComponent::call_loop() {
this->schedule_resend_state();
}
}
void MQTTComponent::call_dump_config() {
if (this->is_internal())
return;
this->dump_config();
}
void MQTTComponent::schedule_resend_state() { this->resend_state_ = true; }
std::string MQTTComponent::unique_id() { return ""; }
bool MQTTComponent::is_connected_() const { return global_mqtt_client->is_connected(); }

View file

@ -62,6 +62,8 @@ class MQTTComponent : public Component {
void call_loop() override;
void call_dump_config() override;
/// Send discovery info the Home Assistant, override this.
virtual void send_discovery(JsonObject &root, SendDiscoveryConfig &config) = 0;

View file

@ -105,7 +105,7 @@ void Application::loop() {
#endif
}
this->components_[this->dump_config_at_]->dump_config();
this->components_[this->dump_config_at_]->call_dump_config();
this->dump_config_at_++;
}
}

View file

@ -64,8 +64,9 @@ bool Component::cancel_timeout(const std::string &name) { // NOLINT
}
void Component::call_loop() { this->loop(); }
void Component::call_setup() { this->setup(); }
void Component::call_dump_config() { this->dump_config(); }
uint32_t Component::get_component_state() const { return this->component_state_; }
void Component::call() {
uint32_t state = this->component_state_ & COMPONENT_STATE_MASK;

View file

@ -148,8 +148,12 @@ class Component {
const char *get_component_source() const;
protected:
friend class Application;
virtual void call_loop();
virtual void call_setup();
virtual void call_dump_config();
/** Set an interval function with a unique name. Empty name means no cancelling possible.
*
* This will call f every interval ms. Can be cancelled via CancelInterval().