15 namespace setup_priority {
18 extern const float BUS;
20 extern const float IO;
24 extern const float DATA;
31 extern const float WIFI;
40 extern const float LATE;
44 static const uint32_t SCHEDULER_DONT_RUN = 4294967295UL;
46 #define LOG_UPDATE_INTERVAL(this) \ 47 if (this->get_update_interval() == SCHEDULER_DONT_RUN) { \ 48 ESP_LOGCONFIG(TAG, " Update Interval: never"); \ 49 } else if (this->get_update_interval() < 100) { \ 50 ESP_LOGCONFIG(TAG, " Update Interval: %.3fs", this->get_update_interval() / 1000.0f); \ 52 ESP_LOGCONFIG(TAG, " Update Interval: %.1fs", this->get_update_interval() / 1000.0f); \ 83 virtual void dump_config();
91 virtual float get_setup_priority()
const;
93 float get_actual_setup_priority()
const;
95 void set_setup_priority(
float priority);
103 virtual float get_loop_priority()
const;
110 uint32_t get_component_state()
const;
118 virtual void mark_failed();
124 virtual bool can_proceed();
126 bool status_has_warning();
128 bool status_has_error();
130 void status_set_warning();
132 void status_set_error();
134 void status_clear_warning();
136 void status_clear_error();
138 void status_momentary_warning(
const std::string &
name, uint32_t length = 5000);
140 void status_momentary_error(
const std::string &name, uint32_t length = 5000);
142 bool has_overridden_loop()
const;
153 const char *get_component_source()
const;
158 virtual void call_loop();
159 virtual void call_setup();
160 virtual void call_dump_config();
177 void set_interval(
const std::string &name, uint32_t interval, std::function<
void()> &&f);
179 void set_interval(uint32_t interval, std::function<
void()> &&f);
186 bool cancel_interval(
const std::string &name);
218 void set_retry(
const std::string &name, uint32_t initial_wait_time, uint8_t max_attempts,
219 std::function<
RetryResult(uint8_t)> &&f,
float backoff_increase_factor = 1.0f);
221 void set_retry(uint32_t initial_wait_time, uint8_t max_attempts, std::function<
RetryResult(uint8_t)> &&f,
222 float backoff_increase_factor = 1.0f);
229 bool cancel_retry(
const std::string &name);
245 void set_timeout(
const std::string &name, uint32_t timeout, std::function<
void()> &&f);
247 void set_timeout(uint32_t timeout, std::function<
void()> &&f);
254 bool cancel_timeout(
const std::string &name);
263 void defer(
const std::string &name, std::function<
void()> &&f);
266 void defer(std::function<
void()> &&f);
269 bool cancel_defer(
const std::string &name);
271 uint32_t component_state_{0x0000};
272 float setup_priority_override_{NAN};
273 const char *component_source_{
nullptr};
298 virtual void set_update_interval(uint32_t update_interval);
302 virtual void update() = 0;
306 void call_setup()
override;
309 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
const uint32_t STATUS_LED_MASK