11 static const char *
const TAG =
"component";
13 namespace setup_priority {
15 const float BUS = 1000.0f;
16 const float IO = 900.0f;
27 const float LATE = -100.0f;
60 std::function<
RetryResult(uint8_t)> &&f,
float backoff_increase_factor) {
61 App.
scheduler.
set_retry(
this, name, initial_wait_time, max_attempts, std::move(f), backoff_increase_factor);
86 this->component_state_ &= ~COMPONENT_STATE_MASK;
92 this->component_state_ &= ~COMPONENT_STATE_MASK;
108 if (this->component_source_ ==
nullptr)
110 return this->component_source_;
113 ESP_LOGE(TAG,
"Component %s was marked as failed.", this->get_component_source());
114 this->component_state_ &= ~COMPONENT_STATE_MASK;
116 this->status_set_error();
134 float backoff_increase_factor) {
135 App.
scheduler.
set_retry(
this,
"", initial_wait_time, max_attempts, std::move(f), backoff_increase_factor);
139 return (this->component_state_ & COMPONENT_STATE_MASK) == COMPONENT_STATE_LOOP ||
156 this->status_set_warning();
157 this->set_timeout(name, length, [
this]() { this->status_clear_warning(); });
160 this->status_set_error();
161 this->set_timeout(name, length, [
this]() { this->status_clear_error(); });
165 if (std::isnan(this->setup_priority_override_))
166 return this->get_setup_priority();
167 return this->setup_priority_override_;
173 bool loop_overridden =
true;
174 bool call_loop_overridden =
true;
176 #pragma GCC diagnostic push 177 #pragma GCC diagnostic ignored "-Wpmf-conversions" 180 #pragma GCC diagnostic pop 182 return loop_overridden || call_loop_overridden;
209 : started_(
millis()), component_(component) {}
214 ESP_LOGW(TAG,
"Component %s took a long time for an operation (%.2f s).", src, (now -
started_) / 1e3f);
215 ESP_LOGW(TAG,
"Components should block for at most 20-30ms.");
const uint32_t COMPONENT_STATE_LOOP
const uint32_t COMPONENT_STATE_FAILED
uint32_t update_interval_
const float DATA
For components that import data from directly connected sensors like DHT.
virtual void loop()
This method will be called repeatedly.
void set_interval(const std::string &name, uint32_t interval, std::function< void()> &&f)
Set an interval function with a unique name.
const float BEFORE_CONNECTION
For components that should be initialized after WiFi and before API is connected. ...
const float AFTER_CONNECTION
For components that should be initialized after a data connection (API/MQTT) is connected.
virtual float get_loop_priority() const
priority of loop().
~WarnIfComponentBlockingGuard()
bool cancel_timeout(const std::string &name)
Cancel a timeout function.
const float AFTER_WIFI
For components that should be initialized after WiFi is connected.
bool cancel_timeout(Component *component, const std::string &name)
void status_momentary_warning(const std::string &name, uint32_t length=5000)
float get_actual_setup_priority() const
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
bool cancel_interval(const std::string &name)
Cancel an interval function.
const uint32_t STATUS_LED_OK
void set_setup_priority(float priority)
void defer(const std::string &name, std::function< void()> &&f)
Defer a callback to the next loop() call.
const float LATE
For components that should be initialized at the very end of the setup process.
bool has_overridden_loop() const
bool status_has_warning()
virtual void dump_config()
const float AFTER_BLUETOOTH
virtual void call_dump_config()
uint32_t IRAM_ATTR HOT millis()
void status_momentary_error(const std::string &name, uint32_t length=5000)
virtual void call_setup()
void set_retry(const std::string &name, uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> &&f, float backoff_increase_factor=1.0f)
Set an retry function with a unique name.
void set_retry(Component *component, const std::string &name, uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> func, float backoff_increase_factor=1.0f)
uint32_t get_component_state() const
const float BUS
For communication buses like i2c/spi.
virtual void setup()
Where the component's initialization should happen.
const uint32_t COMPONENT_STATE_SETUP
virtual float get_setup_priority() const
priority of setup().
void status_clear_warning()
const uint32_t COMPONENT_STATE_CONSTRUCTION
bool cancel_defer(const std::string &name)
Cancel a defer callback using the specified name, name must not be empty.
const float PROCESSOR
For components that use data from sensors like displays.
const char * get_component_source() const
Get the integration where this component was declared as a string.
Application App
Global storage of Application pointer - only one Application can exist.
virtual bool can_proceed()
bool cancel_retry(Component *component, const std::string &name)
WarnIfComponentBlockingGuard(Component *component)
void status_set_warning()
const uint32_t COMPONENT_STATE_MASK
bool cancel_retry(const std::string &name)
Cancel a retry function.
virtual uint32_t get_update_interval() const
Get the update interval in ms of this sensor.
const uint32_t STATUS_LED_WARNING
void status_clear_error()
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
void call_setup() override
virtual void mark_failed()
Mark this component as failed.
bool cancel_interval(Component *component, const std::string &name)
const float IO
For components that represent GPIO pins like PCF8573.
const uint32_t STATUS_LED_ERROR
void set_timeout(Component *component, const std::string &name, uint32_t timeout, std::function< void()> func)
Implementation of SPI Controller mode.
const uint32_t STATUS_LED_MASK
virtual void set_update_interval(uint32_t update_interval)
Manually set the update interval in ms for this polling object.
void set_interval(Component *component, const std::string &name, uint32_t interval, std::function< void()> func)