16 namespace setup_priority {
19 extern const float BUS;
21 extern const float IO;
25 extern const float DATA;
32 extern const float WIFI;
41 extern const float LATE;
45 static const uint32_t SCHEDULER_DONT_RUN = 4294967295UL;
47 #define LOG_UPDATE_INTERVAL(this) \ 48 if (this->get_update_interval() == SCHEDULER_DONT_RUN) { \ 49 ESP_LOGCONFIG(TAG, " Update Interval: never"); \ 50 } else if (this->get_update_interval() < 100) { \ 51 ESP_LOGCONFIG(TAG, " Update Interval: %.3fs", this->get_update_interval() / 1000.0f); \ 53 ESP_LOGCONFIG(TAG, " Update Interval: %.1fs", this->get_update_interval() / 1000.0f); \ 84 virtual void dump_config();
92 virtual float get_setup_priority()
const;
94 float get_actual_setup_priority()
const;
96 void set_setup_priority(
float priority);
104 virtual float get_loop_priority()
const;
111 uint32_t get_component_state()
const;
119 virtual void mark_failed();
121 bool is_failed()
const;
123 bool is_ready()
const;
125 virtual bool can_proceed();
127 bool status_has_warning()
const;
129 bool status_has_error()
const;
131 void status_set_warning(
const char *message =
"unspecified");
133 void status_set_error(
const char *message =
"unspecified");
135 void status_clear_warning();
137 void status_clear_error();
139 void status_momentary_warning(
const std::string &
name, uint32_t
length = 5000);
141 void status_momentary_error(
const std::string &name, uint32_t
length = 5000);
143 bool has_overridden_loop()
const;
154 const char *get_component_source()
const;
159 virtual void call_loop();
160 virtual void call_setup();
161 virtual void call_dump_config();
178 void set_interval(
const std::string &name, uint32_t interval, std::function<
void()> &&f);
180 void set_interval(uint32_t interval, std::function<
void()> &&f);
187 bool cancel_interval(
const std::string &name);
219 void set_retry(
const std::string &name, uint32_t initial_wait_time, uint8_t max_attempts,
220 std::function<
RetryResult(uint8_t)> &&f,
float backoff_increase_factor = 1.0f);
222 void set_retry(uint32_t initial_wait_time, uint8_t max_attempts, std::function<
RetryResult(uint8_t)> &&f,
223 float backoff_increase_factor = 1.0f);
230 bool cancel_retry(
const std::string &name);
246 void set_timeout(
const std::string &name, uint32_t timeout, std::function<
void()> &&f);
248 void set_timeout(uint32_t timeout, std::function<
void()> &&f);
255 bool cancel_timeout(
const std::string &name);
264 void defer(
const std::string &name, std::function<
void()> &&f);
267 void defer(std::function<
void()> &&f);
270 bool cancel_defer(
const std::string &name);
272 uint32_t component_state_{0x0000};
273 float setup_priority_override_{NAN};
274 const char *component_source_{
nullptr};
299 virtual void set_update_interval(uint32_t update_interval);
303 virtual void update() = 0;
307 void call_setup()
override;
310 virtual uint32_t get_update_interval()
const;
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.
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.
const float AFTER_WIFI
For components that should be initialized after WiFi is connected.
const uint32_t STATUS_LED_OK
const float LATE
For components that should be initialized at the very end of the setup process.
This class simplifies creating components that periodically check a state.
const float AFTER_BLUETOOTH
void set_component_source(const char *source)
Set where this component was loaded from for some debug messages.
const float BUS
For communication buses like i2c/spi.
virtual void on_shutdown()
const float HARDWARE_LATE
Alias for DATA (here for compatibility reasons)
const uint32_t COMPONENT_STATE_SETUP
virtual void on_safe_shutdown()
const uint32_t COMPONENT_STATE_CONSTRUCTION
const float PROCESSOR
For components that use data from sensors like displays.
const uint32_t COMPONENT_STATE_MASK
const uint32_t STATUS_LED_WARNING
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
const float IO
For components that represent GPIO pins like PCF8573.
const uint32_t STATUS_LED_ERROR
Implementation of SPI Controller mode.
const uint32_t STATUS_LED_MASK