12static const char *
const TAG =
"component";
14namespace setup_priority {
16const float BUS = 1000.0f;
17const float IO = 900.0f;
64 std::function<
RetryResult(uint8_t)> &&f,
float backoff_increase_factor) {
65 App.
scheduler.
set_retry(
this, name, initial_wait_time, max_attempts, std::move(f), backoff_increase_factor);
150 float backoff_increase_factor) {
151 App.
scheduler.
set_retry(
this,
"", initial_wait_time, max_attempts, std::move(f), backoff_increase_factor);
175 if (strcmp(message,
"unspecified") != 0)
207#if defined(USE_HOST) || defined(CLANG_TIDY)
208 bool loop_overridden =
true;
209 bool call_loop_overridden =
true;
211#pragma GCC diagnostic push
212#pragma GCC diagnostic ignored "-Wpmf-conversions"
215#pragma GCC diagnostic pop
217 return loop_overridden || call_loop_overridden;
244 : started_(start_time), component_(component) {}
246 uint32_t curr_time =
millis();
248 uint32_t blocking_time = curr_time - this->
started_;
257 ESP_LOGW(TAG,
"Component %s took a long time for an operation (%" PRIu32
" ms).", src, blocking_time);
258 ESP_LOGW(TAG,
"Components should block for at most 30 ms.");
virtual void mark_failed()
Mark this component as failed.
virtual void call_dump_config()
virtual float get_setup_priority() const
priority of setup().
virtual void setup()
Where the component's initialization should happen.
float get_actual_setup_priority() const
bool has_overridden_loop() const
uint32_t warn_if_blocking_over_
void set_interval(const std::string &name, uint32_t interval, std::function< void()> &&f)
Set an interval function with a unique name.
bool should_warn_of_blocking(uint32_t blocking_time)
virtual bool can_proceed()
bool cancel_timeout(const std::string &name)
Cancel a timeout function.
virtual float get_loop_priority() const
priority of loop().
void status_clear_error()
void status_momentary_error(const std::string &name, uint32_t length=5000)
const char * get_component_source() const
Get the integration where this component was declared as a string.
bool cancel_retry(const std::string &name)
Cancel a retry function.
void status_momentary_warning(const std::string &name, uint32_t length=5000)
virtual void dump_config()
bool status_has_warning() const
bool status_has_error() const
bool cancel_interval(const std::string &name)
Cancel an interval function.
void status_set_warning(const char *message="unspecified")
bool cancel_defer(const std::string &name)
Cancel a defer callback using the specified name, name must not be empty.
virtual void loop()
This method will be called repeatedly.
void status_set_error(const char *message="unspecified")
uint32_t get_component_state() const
uint32_t component_state_
State of this component.
const char * component_source_
void set_setup_priority(float priority)
void defer(const std::string &name, std::function< void()> &&f)
Defer a callback to the next loop() call.
float setup_priority_override_
void status_clear_warning()
virtual void call_setup()
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
std::string error_message_
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.
virtual uint32_t get_update_interval() const
Get the update interval in ms of this sensor.
void call_setup() override
virtual void set_update_interval(uint32_t update_interval)
Manually set the update interval in ms for this polling object.
uint32_t update_interval_
bool cancel_retry(Component *component, const std::string &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)
bool cancel_timeout(Component *component, const std::string &name)
bool cancel_interval(Component *component, const std::string &name)
void set_timeout(Component *component, const std::string &name, uint32_t timeout, std::function< void()> func)
void set_interval(Component *component, const std::string &name, uint32_t interval, std::function< void()> func)
~WarnIfComponentBlockingGuard()
WarnIfComponentBlockingGuard(Component *component, uint32_t start_time)
const float BUS
For communication buses like i2c/spi.
const float AFTER_CONNECTION
For components that should be initialized after a data connection (API/MQTT) is connected.
const float DATA
For components that import data from directly connected sensors like DHT.
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
const float BEFORE_CONNECTION
For components that should be initialized after WiFi and before API is connected.
const float IO
For components that represent GPIO pins like PCF8573.
const float LATE
For components that should be initialized at the very end of the setup process.
const float AFTER_WIFI
For components that should be initialized after WiFi is connected.
const float PROCESSOR
For components that use data from sensors like displays.
const float AFTER_BLUETOOTH
Providing packet encoding functions for exchanging data with a remote host.
const uint32_t STATUS_LED_OK
const uint32_t COMPONENT_STATE_FAILED
const uint32_t WARN_IF_BLOCKING_INCREMENT_MS
How long the blocking time must be larger to warn again.
const uint32_t COMPONENT_STATE_MASK
const uint32_t COMPONENT_STATE_LOOP
const uint32_t COMPONENT_STATE_SETUP
const uint32_t STATUS_LED_ERROR
const uint32_t COMPONENT_STATE_CONSTRUCTION
const uint32_t STATUS_LED_MASK
uint32_t IRAM_ATTR HOT millis()
Application App
Global storage of Application pointer - only one Application can exist.
const uint32_t STATUS_LED_WARNING
const uint32_t WARN_IF_BLOCKING_OVER_MS
Initial blocking time allowed without warning.