ESPHome 2026.10.0
Loading...
Searching...
No Matches
application.cpp
Go to the documentation of this file.
3#include "esphome/core/log.h"
5#include <cstring>
6
7#ifdef USE_ESP8266
8#include <pgmspace.h>
9#endif
10#ifdef USE_ESP32
11#include <esp_chip_info.h>
12#include <esp_ota_ops.h>
13#include <esp_bootloader_desc.h>
14#include <esp_flash.h>
15#if __has_include(<esp_flash_chips/spi_flash_chip_generic.h>)
16#include <esp_flash_chips/spi_flash_chip_generic.h> // ESP-IDF 6
17#include <esp_flash_chips/spi_flash_chip_mxic.h>
18#else
19#include <spi_flash_chip_generic.h>
20#include <spi_flash_chip_mxic.h>
21#endif
22// Vendor flash drivers linked next to the generic one; sdkconfig defines each as 1 or not at all
23#define ESPHOME_FLASH_VENDOR_DRIVERS \
24 (CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP + CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP + CONFIG_SPI_FLASH_SUPPORT_GD_CHIP + \
25 CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP + CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP + CONFIG_SPI_FLASH_SUPPORT_TH_CHIP + \
26 CONFIG_SPI_FLASH_SUPPORT_MXIC_OPI_CHIP)
27#endif
29#include "esphome/core/hal.h"
30#include <algorithm>
31#include <ranges>
32
33#ifdef USE_STATUS_LED
35#endif
36
37namespace esphome {
38
39ESPHOME_LOG_TAG(TAG, "app");
40
41// Delay after setup() finishes before trimming the scheduler freelist of its post-boot peak.
42// 10 s is well past the bulk of post-setup async work (Wi-Fi/MQTT connects, first-read latency).
43static constexpr uint32_t SCHEDULER_FREELIST_TRIM_DELAY_MS = 10000;
44
45// Helper function for insertion sort of components by priority
46// Using insertion sort instead of std::stable_sort saves ~1.3KB of flash
47// by avoiding template instantiations (std::rotate, std::stable_sort, lambdas)
48// IMPORTANT: This sort is stable (preserves relative order of equal elements),
49// which is necessary to maintain user-defined component order for same priority
50template<typename Iterator, float (Component::*GetPriority)() const>
51static void insertion_sort_by_priority(Iterator first, Iterator last) {
52 for (auto it = first + 1; it != last; ++it) {
53 auto key = *it;
54 float key_priority = (key->*GetPriority)();
55 auto j = it - 1;
56
57 // Using '<' (not '<=') ensures stability - equal priority components keep their order
58 while (j >= first && ((*j)->*GetPriority)() < key_priority) {
59 *(j + 1) = *j;
60 j--;
61 }
62 *(j + 1) = key;
63 }
64}
65
67 if (has_loop) {
69 }
70 this->components_.push_back(comp);
71}
73 ESP_LOGI(TAG, "Running through setup()");
74 ESP_LOGV(TAG, "Sorting components by setup priority");
75
76 // Sort by setup priority using our helper function
77 insertion_sort_by_priority<decltype(this->components_.begin()), &Component::get_actual_setup_priority>(
78 this->components_.begin(), this->components_.end());
79
80 // Initialize looping_components_ early so enable_pending_loops_() works during setup
82
83 for (uint32_t i = 0; i < this->components_.size(); i++) {
85
86 // Update loop_component_start_time_ before calling each component during setup
87 this->loop_component_start_time_ = MillisInternal::get();
88 component->call();
89 this->scheduler.process_to_add();
90 this->feed_wdt();
91 if (component->can_proceed())
92 continue;
93
94 // Force the status LED to blink WARNING while we wait for a slow
95 // component to come up. Cleared after setup() finishes if no real
96 // component has warning set.
98
99 do {
100 // Service scheduler and process pending loop enables to handle GPIO
101 // interrupts during setup. During setup we always run the component
102 // phase (no loop_interval_ gate), so call both helpers unconditionally.
103 this->scheduler_tick_(MillisInternal::get());
104 {
105 ComponentPhaseGuard phase_guard{*this};
106
107 for (uint32_t j = 0; j <= i; j++) {
108 // Update loop_component_start_time_ right before calling each component
109 this->loop_component_start_time_ = MillisInternal::get();
110 this->components_[j]->call();
111 this->feed_wdt();
112 }
113 }
114 yield();
115 } while (!component->can_proceed() && !component->is_failed());
116 }
117
118 // Setup is complete. Reconcile STATUS_LED_WARNING: the slow-setup path
119 // above may have forced it on, and any status_clear_warning() calls
120 // from components during setup were intentional no-ops (gated by
121 // APP_STATE_SETUP_COMPLETE). Walk components once here to pick up the
122 // real state. STATUS_LED_ERROR is never artificially forced, so its
123 // clear path always works and needs no reconciliation. Finally, set
124 // APP_STATE_SETUP_COMPLETE so subsequent warning clears go through
125 // the normal walk-and-clear path.
127 this->app_state_ &= ~STATUS_LED_WARNING;
129
130 ESP_LOGI(TAG, "setup() finished successfully!");
131
132 // Trim the scheduler freelist of its post-boot peak once startup churn settles.
133 this->scheduler.set_timeout(this, SCHEDULER_FREELIST_TRIM_DELAY_MS, [this]() { this->scheduler.trim_freelist(); });
134
135#ifdef USE_SETUP_PRIORITY_OVERRIDE
136 // Clear setup priority overrides to free memory
138#endif
139
140#if defined(USE_ESP32) || defined(USE_LIBRETINY)
141 // Save main loop task handle for wake_loop_*() / fast select FreeRTOS notifications.
142 esphome_main_task_handle = xTaskGetCurrentTaskHandle();
143#endif
144#ifdef USE_HOST
145 // Set up wake socket for waking main loop from tasks (host platform select() loop).
146 wake_setup();
147#endif
148
149 // Ensure all active looping components are in LOOP state.
150 // Components after the last blocking component only got one call() during setup
151 // (CONSTRUCTION→SETUP) and never received the second call() (SETUP→LOOP).
152 // The main loop calls loop() directly, bypassing call()'s state machine.
153 for (uint16_t i = 0; i < this->looping_components_active_end_; i++) {
154 this->looping_components_[i]->set_component_state_(COMPONENT_STATE_LOOP);
155 }
156
157 this->schedule_dump_config();
158}
159
160void Application::process_dump_config_() {
161 if (this->dump_config_at_ == 0) {
162 char build_time_str[Application::BUILD_TIME_STR_SIZE];
163 this->get_build_time_string(build_time_str);
164 ESP_LOGI(TAG, "ESPHome version " ESPHOME_VERSION " compiled on %s", build_time_str);
165#ifdef ESPHOME_PROJECT_NAME
166 ESP_LOGI(TAG, "Project " ESPHOME_PROJECT_NAME " version " ESPHOME_PROJECT_VERSION);
167#endif
168#ifdef USE_ESP32
169 esp_chip_info_t chip_info;
170 esp_chip_info(&chip_info);
171 ESP_LOGI(TAG, "ESP32 Chip: %s rev%d.%d, %d core(s)", ESPHOME_VARIANT, chip_info.revision / 100,
172 chip_info.revision % 100, chip_info.cores);
173 [[maybe_unused]] static const char *const ESP32_ADVANCED_PATH = "under esp32 > framework > advanced";
174#if ESPHOME_FLASH_VENDOR_DRIVERS > 0
175 {
176 // Only the driver in use earns its IRAM; with several linked at least one is idle
177 const spi_flash_chip_t *flash_driver = esp_flash_default_chip->chip_drv;
178#if ESPHOME_FLASH_VENDOR_DRIVERS > 1
179 constexpr bool idle_driver = true;
180#else
181 const bool idle_driver = flash_driver == &esp_flash_chip_generic;
182#endif
183 if (idle_driver) {
184 const char *value = flash_driver->name;
185#ifdef CONFIG_SPI_FLASH_SUPPORT_MXIC_OPI_CHIP
186 if (flash_driver == &esp_flash_chip_mxic_opi)
187 value = "mxic_opi";
188#endif
189 ESP_LOGW(TAG, "Set flash_chip: %s %s to save IRAM", value, ESP32_ADVANCED_PATH);
190 }
191 }
192#endif
193#if defined(USE_ESP32_VARIANT_ESP32) && !defined(USE_ESP32_MIN_CHIP_REVISION_SET)
194 {
195 // Suggest optimization for chips that don't need the PSRAM cache workaround
196 if (chip_info.revision >= 300) {
197#ifdef USE_PSRAM
198 ESP_LOGW(TAG, "Chip rev >= 3.0 detected. Set minimum_chip_revision: \"%d.%d\" %s to save ~10KB IRAM",
199 chip_info.revision / 100, chip_info.revision % 100, ESP32_ADVANCED_PATH);
200#else
201 ESP_LOGW(TAG, "Chip rev >= 3.0 detected. Set minimum_chip_revision: \"%d.%d\" %s to reduce binary size",
202 chip_info.revision / 100, chip_info.revision % 100, ESP32_ADVANCED_PATH);
203#endif
204 }
205 }
206#endif
207 {
208 // esp_bootloader_desc_t is available in ESP-IDF >= 5.2; if readable the bootloader is modern.
209 //
210 // Design decision: We intentionally do NOT mention sram1_as_iram when the bootloader is too old.
211 // Enabling sram1_as_iram with an old bootloader causes a hard brick (device fails to boot,
212 // requires USB reflash to recover). Users don't always read warnings carefully, so we only
213 // suggest the option once we've confirmed the bootloader can handle it. In practice this
214 // means a user with an old bootloader may need to flash twice: once via USB to update the
215 // bootloader (they'll see the suggestion on next boot), then OTA with sram1_as_iram: true.
216 // Two flashes is a better outcome than a bricked device.
217 esp_bootloader_desc_t boot_desc;
218 if (esp_ota_get_bootloader_description(nullptr, &boot_desc) != ESP_OK) {
219#ifdef USE_ESP32_VARIANT_ESP32
220 ESP_LOGW(TAG, "Bootloader too old for OTA rollback and SRAM1 as IRAM (+40KB). "
221 "Flash via USB once to update the bootloader");
222#else
223 ESP_LOGW(TAG, "Bootloader too old for OTA rollback. Flash via USB once to update the bootloader");
224#endif
225 }
226#if defined(USE_ESP32_VARIANT_ESP32) && !defined(USE_ESP32_SRAM1_AS_IRAM)
227 else {
228 ESP_LOGW(TAG, "Bootloader supports SRAM1 as IRAM (+40KB). Set sram1_as_iram: true %s", ESP32_ADVANCED_PATH);
229 }
230#endif
231 }
232#endif // USE_ESP32
233 }
234
235 this->components_[this->dump_config_at_]->call_dump_config_();
236 this->dump_config_at_++;
237}
238
240 // Cold entry: callers without a millis() timestamp in hand. Fetches the
241 // time and defers to the hot path.
242 this->feed_wdt_with_time(MillisInternal::get());
243}
244
246 // Callers (both feed_wdt() and feed_wdt_with_time()) have already
247 // confirmed the WDT_FEED_INTERVAL_MS rate limit was exceeded.
249 this->last_wdt_feed_ = time;
250}
251
252#ifdef USE_STATUS_LED
254 // Callers (feed_wdt(), feed_wdt_with_time()) have already confirmed the
255 // STATUS_LED_DISPATCH_INTERVAL_MS rate limit was exceeded. Rate-limited
256 // separately from arch_feed_wdt() so the LED blink pattern stays readable
257 // (status_led error blink period is 250 ms) while HAL watchdog pokes can
258 // still run at the much coarser WDT_FEED_INTERVAL_MS cadence.
259 this->last_status_led_service_ = time;
260 if (status_led::global_status_led == nullptr)
261 return;
263 uint8_t sl_state = sl->get_component_state() & COMPONENT_STATE_MASK;
264 if (sl_state == COMPONENT_STATE_LOOP_DONE) {
265 // status_led only transitions to LOOP_DONE from inside its own loop() (after the
266 // first idle-path dispatch), so its pin is already initialized by pre_setup() and
267 // its setup() has already run. Re-dispatch only if an error or warning bit has been
268 // set since; otherwise skip entirely.
269 if ((this->app_state_ & STATUS_LED_MASK) == 0)
270 return;
271 sl->enable_loop();
272 } else if (sl_state != COMPONENT_STATE_LOOP) {
273 // CONSTRUCTION/SETUP/FAILED: not our job — App::setup() drives the lifecycle.
274 return;
275 }
276 sl->loop();
277}
278#endif
279
281 // Walk all components (not just looping ones) so non-looping components'
282 // status bits are respected. Only called from the slow-path clear helpers
283 // (status_clear_warning_slow_path_ / status_clear_error_slow_path_) on an
284 // actual set→clear transition, so walking O(N) here is paid once per
285 // transition — not once per loop iteration.
286 for (auto *component : this->components_) {
287 if ((component->get_component_state() & flag) != 0)
288 return true;
289 }
290 return false;
291}
292
294 ESP_LOGI(TAG, "Forcing a reboot");
295 for (auto &component : std::ranges::reverse_view(this->components_)) {
296 component->on_shutdown();
297 }
298 arch_restart();
299}
301 ESP_LOGI(TAG, "Rebooting safely");
303 teardown_components(TEARDOWN_TIMEOUT_REBOOT_MS);
305 arch_restart();
306}
307
309 for (auto &component : std::ranges::reverse_view(this->components_)) {
310 component->on_safe_shutdown();
311 }
312 for (auto &component : std::ranges::reverse_view(this->components_)) {
313 component->on_shutdown();
314 }
315}
316
318 for (auto &component : std::ranges::reverse_view(this->components_)) {
319 component->on_powerdown();
320 }
321}
322
324 uint32_t start_time = MillisInternal::get();
325
326 // Use a StaticVector instead of std::vector to avoid heap allocation
327 // since we know the actual size at compile time
329
330 // Copy all components in reverse order
331 // Reverse order matches the behavior of run_safe_shutdown_hooks() above and ensures
332 // components are torn down in the opposite order of their setup_priority (which is
333 // used to sort components during Application::setup())
334 size_t num_components = this->components_.size();
335 for (size_t i = 0; i < num_components; ++i) {
336 pending_components[i] = this->components_[num_components - 1 - i];
337 }
338
339 uint32_t now = start_time;
340 size_t pending_count = num_components;
341
342 // Teardown Algorithm
343 // ==================
344 // We iterate through pending components, calling teardown() on each.
345 // Components that return false (need more time) are copied forward
346 // in the array. Components that return true (finished) are skipped.
347 //
348 // The compaction happens in-place during iteration:
349 // - still_pending tracks the write position (where to put next pending component)
350 // - i tracks the read position (which component we're testing)
351 // - When teardown() returns false, we copy component[i] to component[still_pending]
352 // - When teardown() returns true, we just skip it (don't increment still_pending)
353 //
354 // Example with 4 components where B can teardown immediately:
355 //
356 // Start:
357 // pending_components: [A, B, C, D]
358 // pending_count: 4 ^----------^
359 //
360 // Iteration 1:
361 // i=0: A needs more time → keep at pos 0 (no copy needed)
362 // i=1: B finished → skip
363 // i=2: C needs more time → copy to pos 1
364 // i=3: D needs more time → copy to pos 2
365 //
366 // After iteration 1:
367 // pending_components: [A, C, D | D]
368 // pending_count: 3 ^--------^
369 //
370 // Iteration 2:
371 // i=0: A finished → skip
372 // i=1: C needs more time → copy to pos 0
373 // i=2: D finished → skip
374 //
375 // After iteration 2:
376 // pending_components: [C | C, D, D] (positions 1-3 have old values)
377 // pending_count: 1 ^--^
378
379 while (pending_count > 0 && (now - start_time) < timeout_ms) {
380 // Feed watchdog during teardown to prevent triggering
381 this->feed_wdt_with_time(now);
382
383 // Process components and compact the array, keeping only those still pending
384 size_t still_pending = 0;
385 for (size_t i = 0; i < pending_count; ++i) {
386 if (!pending_components[i]->teardown()) {
387 // Component still needs time, copy it forward
388 if (still_pending != i) {
389 pending_components[still_pending] = pending_components[i];
390 }
391 ++still_pending;
392 }
393 // Component finished teardown, skip it (don't increment still_pending)
394 }
395 pending_count = still_pending;
396
397 // Give some time for I/O operations if components are still pending
398 if (pending_count > 0) {
400 }
401
402 // Update time for next iteration
403 now = MillisInternal::get();
404 }
405
406 if (pending_count > 0) {
407 // Note: At this point, connections are either disconnected or in a bad state,
408 // so this warning will only appear via serial rather than being transmitted to clients
409 for (size_t i = 0; i < pending_count; ++i) {
410 ESP_LOGW(TAG, "%s did not complete teardown within %" PRIu32 " ms",
411 LOG_STR_ARG(pending_components[i]->get_component_log_str()), timeout_ms);
412 }
413 }
414}
415
417 for (auto *obj : this->components_) {
418 if (obj->has_overridden_loop() &&
419 ((obj->get_component_state() & COMPONENT_STATE_MASK) == COMPONENT_STATE_LOOP_DONE) == match_loop_done) {
420 this->looping_components_.push_back(obj);
421 }
422 }
423}
424
426 // This method must be reentrant - components can disable themselves during their own loop() call
427 // Linear search to find component in active section
428 // Most configs have 10-30 looping components (30 is on the high end)
429 // O(n) is acceptable here as we optimize for memory, not complexity
430 for (uint16_t i = 0; i < this->looping_components_active_end_; i++) {
431 if (this->looping_components_[i] == component) {
432 // Move last active component to this position
433 this->looping_components_active_end_--;
434 if (i != this->looping_components_active_end_) {
435 std::swap(this->looping_components_[i], this->looping_components_[this->looping_components_active_end_]);
436
437 // If we're currently iterating and just swapped the current position
438 if (this->in_loop_ && i == this->current_loop_index_) {
439 // Decrement so we'll process the swapped component next
440 this->current_loop_index_--;
441 // Update the loop start time to current time so the swapped component
442 // gets correct timing instead of inheriting stale timing.
443 // This prevents integer underflow in timing calculations by ensuring
444 // the swapped component starts with a fresh timing reference, avoiding
445 // errors caused by stale or wrapped timing values.
446 this->loop_component_start_time_ = MillisInternal::get();
447 }
448 }
449 return;
450 }
451 }
452}
453
455 // Helper to move component from inactive to active section
456 if (index != this->looping_components_active_end_) {
457 std::swap(this->looping_components_[index], this->looping_components_[this->looping_components_active_end_]);
458 }
460}
461
463 // This method is only called when component state is LOOP_DONE, so we know
464 // the component must be in the inactive section (if it exists in looping_components_)
465 // Only search the inactive portion for better performance
466 // With typical 0-5 inactive components, O(k) is much faster than O(n)
467 const uint16_t size = this->looping_components_.size();
468 for (uint16_t i = this->looping_components_active_end_; i < size; i++) {
469 if (this->looping_components_[i] == component) {
470 // Found in inactive section - move to active
472 return;
473 }
474 }
475 // Component not found in looping_components_ - this is normal for components
476 // that don't have loop() or were not included in the partitioned vector
477}
478
480 // Process components that requested enable_loop from ISR context
481 // Only iterate through inactive looping_components_ (typically 0-5) instead of all components
482 //
483 // Race condition handling:
484 // 1. We check if component is already in LOOP state first - if so, just clear the flag
485 // This handles reentrancy where enable_loop() was called between ISR and processing
486 // 2. We only clear pending_enable_loop_ after checking state, preventing lost requests
487 // 3. If any components aren't in LOOP_DONE state, we set has_pending_enable_loop_requests_
488 // back to true to ensure we check again next iteration
489 // 4. ISRs can safely set flags at any time - worst case is we process them next iteration
490 // 5. The global flag (has_pending_enable_loop_requests_) is cleared before this method,
491 // so any ISR that fires during processing will be caught in the next loop
492 const uint16_t size = this->looping_components_.size();
493 bool has_pending = false;
494
495 for (uint16_t i = this->looping_components_active_end_; i < size; i++) {
497 if (!component->pending_enable_loop_) {
498 continue; // Skip components without pending requests
499 }
500
501 // Check current state
503
504 // If already in LOOP state, nothing to do - clear flag and continue
506 component->pending_enable_loop_ = false;
507 continue;
508 }
509
510 // If not in LOOP_DONE state, can't enable yet - keep flag set
512 has_pending = true; // Keep tracking this component
513 continue; // Keep the flag set - try again next iteration
514 }
515
516 // Clear the pending flag and enable the loop
517 component->pending_enable_loop_ = false;
518 ESP_LOGVV(TAG, "%s loop enabled from ISR", LOG_STR_ARG(component->get_component_log_str()));
519 component->set_component_state_(COMPONENT_STATE_LOOP);
520
521 // Move to active section
523 }
524
525 // If we couldn't process some requests, ensure we check again next iteration
526 if (has_pending) {
528 }
529}
530
531// App storage — asm label shares the linker symbol with "extern Application App".
532// char[] is trivially destructible, so no __cxa_atexit or destructor chain is emitted.
533// Constructed via placement new in the generated setup().
534#ifndef __GXX_ABI_VERSION
535#error "Application placement new requires Itanium C++ ABI (GCC/Clang)"
536#endif
537static_assert(std::is_default_constructible<Application>::value, "Application must be default-constructible");
538// __USER_LABEL_PREFIX__ is "_" on Mach-O (macOS) and empty on ELF (embedded targets).
539// String literal concatenation produces the correct platform-specific mangled symbol.
540// Two-level macro needed: # stringifies before expansion, so the
541// indirection forces __USER_LABEL_PREFIX__ to expand first.
542#define ESPHOME_STRINGIFY_IMPL_(x) #x
543#define ESPHOME_STRINGIFY_(x) ESPHOME_STRINGIFY_IMPL_(x)
544// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
545alignas(Application) char app_storage[sizeof(Application)] asm(
546 ESPHOME_STRINGIFY_(__USER_LABEL_PREFIX__) "_ZN7esphome3AppE");
547#undef ESPHOME_STRINGIFY_
548#undef ESPHOME_STRINGIFY_IMPL_
549
550void Application::get_build_time_string(std::span<char, BUILD_TIME_STR_SIZE> buffer) {
551 ESPHOME_strncpy_P(buffer.data(), ESPHOME_BUILD_TIME_STR, buffer.size());
552 buffer[buffer.size() - 1] = '\0';
553}
554
555void Application::get_comment_string(std::span<char, ESPHOME_COMMENT_SIZE_MAX> buffer) {
556 ESPHOME_strncpy_P(buffer.data(), ESPHOME_COMMENT_STR, ESPHOME_COMMENT_SIZE);
557 buffer[ESPHOME_COMMENT_SIZE - 1] = '\0';
558}
559
560uint32_t Application::get_config_hash() { return ESPHOME_CONFIG_HASH; }
561
562uint32_t Application::get_config_version_hash() { return fnv1a_hash_extend(ESPHOME_CONFIG_HASH, ESPHOME_VERSION); }
563
564time_t Application::get_build_time() { return ESPHOME_BUILD_TIME; }
565
566} // namespace esphome
uint32_t ESPHOME_ALWAYS_INLINE scheduler_tick_(uint32_t now)
void setup()
Reserve space for components to avoid memory fragmentation.
void ESPHOME_ALWAYS_INLINE feed_wdt_with_time(uint32_t time)
Feed the task watchdog, hot entry.
uint16_t looping_components_active_end_
void service_status_led_slow_(uint32_t time)
Slow path for the status_led dispatch rate limit.
static constexpr size_t BUILD_TIME_STR_SIZE
Size of buffer required for build time string (including null terminator)
uint32_t get_config_hash()
Get the config hash as a 32-bit integer.
StaticVector< Component *, ESPHOME_COMPONENT_COUNT > components_
bool any_component_has_status_flag_(uint8_t flag) const
Walk all registered components looking for any whose component_state_ has the given flag set.
void get_build_time_string(std::span< char, BUILD_TIME_STR_SIZE > buffer)
Copy the build time string into the provided buffer Buffer must be BUILD_TIME_STR_SIZE bytes (compile...
void enable_component_loop_(Component *component)
uint32_t loop_component_start_time_
void feed_wdt()
Feed the task watchdog.
void disable_component_loop_(Component *component)
void activate_looping_component_(uint16_t index)
uint32_t last_status_led_service_
void teardown_components(uint32_t timeout_ms)
Teardown all components with a timeout.
FixedVector< Component * > looping_components_
void add_looping_components_by_state_(bool match_loop_done)
volatile bool has_pending_enable_loop_requests_
void get_comment_string(std::span< char, ESPHOME_COMMENT_SIZE_MAX > buffer)
Copy the comment string into the provided buffer.
void feed_wdt_slow_(uint32_t time)
Slow path for feed_wdt(): actually calls arch_feed_wdt() and updates last_wdt_feed_.
uint16_t current_loop_index_
time_t get_build_time()
Get the build time as a Unix timestamp.
uint32_t get_config_version_hash()
Get the config hash extended with ESPHome version.
void calculate_looping_components_()
void register_component_impl_(Component *comp, bool has_loop)
float get_actual_setup_priority() const
uint8_t get_component_state() const
Definition component.h:193
virtual bool can_proceed()
uint8_t component_state_
State of this component - each bit has a purpose: Bits 0-2: Component state (0x00=CONSTRUCTION,...
Definition component.h:495
Minimal static vector - saves memory by avoiding std::vector overhead.
Definition helpers.h:291
size_t size() const
Definition helpers.h:360
const Component * component
Definition component.cpp:34
void yield(void)
bool state
Definition fan.h:2
uint32_t buffer
Definition gif.cpp:50
TaskHandle_t esphome_main_task_handle
Main loop task handle and wake helpers — shared between wake.h (C++) and lwip_fast_select....
Definition main_task.c:4
void ESPHOME_ALWAYS_INLINE wakeable_delay(uint32_t ms)
Host wakeable_delay uses select() over the registered fds — defined in wake_host.cpp.
StatusLED * global_status_led
constexpr uint8_t COMPONENT_HAS_LOOP
Definition component.h:93
constexpr uint32_t fnv1a_hash_extend(uint32_t hash, const char *str)
Extend a FNV-1a hash with additional string data.
Definition helpers.h:930
constexpr uint8_t STATUS_LED_MASK
Definition component.h:88
constexpr uint8_t COMPONENT_STATE_LOOP
Definition component.h:84
constexpr uint8_t APP_STATE_SETUP_COMPLETE
Definition component.h:98
constexpr uint8_t STATUS_LED_WARNING
Definition component.h:90
constexpr uint8_t COMPONENT_STATE_MASK
Definition component.h:81
uint16_t size
Definition helpers.cpp:33
void clear_setup_priority_overrides()
ESPHOME_LOG_TAG(TAG, "app")
void arch_feed_wdt()
Definition hal.cpp:57
constexpr uint8_t COMPONENT_STATE_LOOP_DONE
Definition component.h:86
void wake_setup()
One-time setup of the loopback wake socket. Called from Application::setup().
void arch_restart()
Definition hal.cpp:36
static void uint32_t