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();
122 this->status_set_error(message);
126 bool is_failed()
const;
128 bool is_ready()
const;
130 virtual bool can_proceed();
132 bool status_has_warning()
const;
134 bool status_has_error()
const;
136 void status_set_warning(
const char *message =
"unspecified");
138 void status_set_error(
const char *message =
"unspecified");
140 void status_clear_warning();
142 void status_clear_error();
144 void status_momentary_warning(
const std::string &
name, uint32_t
length = 5000);
146 void status_momentary_error(
const std::string &name, uint32_t
length = 5000);
148 bool has_overridden_loop()
const;
159 const char *get_component_source()
const;
164 virtual void call_loop();
165 virtual void call_setup();
166 virtual void call_dump_config();
190 void set_interval(
const std::string &name, uint32_t interval, std::function<
void()> &&f);
192 void set_interval(uint32_t interval, std::function<
void()> &&f);
199 bool cancel_interval(
const std::string &name);
231 void set_retry(
const std::string &name, uint32_t initial_wait_time, uint8_t max_attempts,
232 std::function<
RetryResult(uint8_t)> &&f,
float backoff_increase_factor = 1.0f);
234 void set_retry(uint32_t initial_wait_time, uint8_t max_attempts, std::function<
RetryResult(uint8_t)> &&f,
235 float backoff_increase_factor = 1.0f);
242 bool cancel_retry(
const std::string &name);
258 void set_timeout(
const std::string &name, uint32_t timeout, std::function<
void()> &&f);
260 void set_timeout(uint32_t timeout, std::function<
void()> &&f);
267 bool cancel_timeout(
const std::string &name);
276 void defer(
const std::string &name, std::function<
void()> &&f);
279 void defer(std::function<
void()> &&f);
282 bool cancel_defer(
const std::string &name);
284 uint32_t component_state_{0x0000};
285 float setup_priority_override_{NAN};
286 const char *component_source_{
nullptr};
287 std::string error_message_{};
312 virtual void set_update_interval(uint32_t update_interval);
316 virtual void update() = 0;
320 void call_setup()
override;
323 virtual uint32_t get_update_interval()
const;
const uint32_t COMPONENT_STATE_LOOP
const uint32_t COMPONENT_STATE_FAILED
uint32_t update_interval_
void mark_failed(const char *message)
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