ESPHome 2026.11.0-dev
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 // %s reads flash on ESP8266, so the build time needs no RAM copy
163 ESP_LOGI(TAG, "ESPHome version " ESPHOME_VERSION " compiled on %s", ESPHOME_BUILD_TIME_STR);
164#ifdef ESPHOME_PROJECT_NAME
165 ESP_LOGI(TAG, "Project " ESPHOME_PROJECT_NAME " version " ESPHOME_PROJECT_VERSION);
166#endif
167#ifdef USE_ESP32
168 esp_chip_info_t chip_info;
169 esp_chip_info(&chip_info);
170 ESP_LOGI(TAG, "ESP32 Chip: %s rev%d.%d, %d core(s)", ESPHOME_VARIANT, chip_info.revision / 100,
171 chip_info.revision % 100, chip_info.cores);
172 [[maybe_unused]] static const char *const ESP32_ADVANCED_PATH = "under esp32 > framework > advanced";
173#if ESPHOME_FLASH_VENDOR_DRIVERS > 0
174 {
175 // Only the driver in use earns its IRAM; with several linked at least one is idle
176 const spi_flash_chip_t *flash_driver = esp_flash_default_chip->chip_drv;
177#if ESPHOME_FLASH_VENDOR_DRIVERS > 1
178 constexpr bool idle_driver = true;
179#else
180 const bool idle_driver = flash_driver == &esp_flash_chip_generic;
181#endif
182 if (idle_driver) {
183 const char *value = flash_driver->name;
184#ifdef CONFIG_SPI_FLASH_SUPPORT_MXIC_OPI_CHIP
185 if (flash_driver == &esp_flash_chip_mxic_opi)
186 value = "mxic_opi";
187#endif
188 ESP_LOGW(TAG, "Set flash_chip: %s %s to save IRAM", value, ESP32_ADVANCED_PATH);
189 }
190 }
191#endif
192#if defined(USE_ESP32_VARIANT_ESP32) && !defined(USE_ESP32_MIN_CHIP_REVISION_SET)
193 {
194 // Suggest optimization for chips that don't need the PSRAM cache workaround
195 if (chip_info.revision >= 300) {
196#ifdef USE_PSRAM
197 ESP_LOGW(TAG, "Chip rev >= 3.0 detected. Set minimum_chip_revision: \"%d.%d\" %s to save ~10KB IRAM",
198 chip_info.revision / 100, chip_info.revision % 100, ESP32_ADVANCED_PATH);
199#else
200 ESP_LOGW(TAG, "Chip rev >= 3.0 detected. Set minimum_chip_revision: \"%d.%d\" %s to reduce binary size",
201 chip_info.revision / 100, chip_info.revision % 100, ESP32_ADVANCED_PATH);
202#endif
203 }
204 }
205#endif
206 {
207 // esp_bootloader_desc_t is available in ESP-IDF >= 5.2; if readable the bootloader is modern.
208 //
209 // Design decision: We intentionally do NOT mention sram1_as_iram when the bootloader is too old.
210 // Enabling sram1_as_iram with an old bootloader causes a hard brick (device fails to boot,
211 // requires USB reflash to recover). Users don't always read warnings carefully, so we only
212 // suggest the option once we've confirmed the bootloader can handle it. In practice this
213 // means a user with an old bootloader may need to flash twice: once via USB to update the
214 // bootloader (they'll see the suggestion on next boot), then OTA with sram1_as_iram: true.
215 // Two flashes is a better outcome than a bricked device.
216 esp_bootloader_desc_t boot_desc;
217 if (esp_ota_get_bootloader_description(nullptr, &boot_desc) != ESP_OK) {
218#ifdef USE_ESP32_VARIANT_ESP32
219 ESP_LOGW(TAG, "Bootloader too old for OTA rollback and SRAM1 as IRAM (+40KB). "
220 "Flash via USB once to update the bootloader");
221#else
222 ESP_LOGW(TAG, "Bootloader too old for OTA rollback. Flash via USB once to update the bootloader");
223#endif
224 }
225#if defined(USE_ESP32_VARIANT_ESP32) && !defined(USE_ESP32_SRAM1_AS_IRAM)
226 else {
227 ESP_LOGW(TAG, "Bootloader supports SRAM1 as IRAM (+40KB). Set sram1_as_iram: true %s", ESP32_ADVANCED_PATH);
228 }
229#endif
230 }
231#endif // USE_ESP32
232 }
233
234 this->components_[this->dump_config_at_]->call_dump_config_();
235 this->dump_config_at_++;
236}
237
239 // Cold entry: callers without a millis() timestamp in hand. Fetches the
240 // time and defers to the hot path.
241 this->feed_wdt_with_time(MillisInternal::get());
242}
243
245 // Callers (both feed_wdt() and feed_wdt_with_time()) have already
246 // confirmed the WDT_FEED_INTERVAL_MS rate limit was exceeded.
248 this->last_wdt_feed_ = time;
249}
250
251#ifdef USE_STATUS_LED
253 // Callers (feed_wdt(), feed_wdt_with_time()) have already confirmed the
254 // STATUS_LED_DISPATCH_INTERVAL_MS rate limit was exceeded. Rate-limited
255 // separately from arch_feed_wdt() so the LED blink pattern stays readable
256 // (status_led error blink period is 250 ms) while HAL watchdog pokes can
257 // still run at the much coarser WDT_FEED_INTERVAL_MS cadence.
258 this->last_status_led_service_ = time;
259 if (status_led::global_status_led == nullptr)
260 return;
262 uint8_t sl_state = sl->get_component_state() & COMPONENT_STATE_MASK;
263 if (sl_state == COMPONENT_STATE_LOOP_DONE) {
264 // status_led only transitions to LOOP_DONE from inside its own loop() (after the
265 // first idle-path dispatch), so its pin is already initialized by pre_setup() and
266 // its setup() has already run. Re-dispatch only if an error or warning bit has been
267 // set since; otherwise skip entirely.
268 if ((this->app_state_ & STATUS_LED_MASK) == 0)
269 return;
270 sl->enable_loop();
271 } else if (sl_state != COMPONENT_STATE_LOOP) {
272 // CONSTRUCTION/SETUP/FAILED: not our job — App::setup() drives the lifecycle.
273 return;
274 }
275 sl->loop();
276}
277#endif
278
280 // Walk all components (not just looping ones) so non-looping components'
281 // status bits are respected. Only called from the slow-path clear helpers
282 // (status_clear_warning_slow_path_ / status_clear_error_slow_path_) on an
283 // actual set→clear transition, so walking O(N) here is paid once per
284 // transition — not once per loop iteration.
285 for (auto *component : this->components_) {
286 if ((component->get_component_state() & flag) != 0)
287 return true;
288 }
289 return false;
290}
291
293 ESP_LOGI(TAG, "Forcing a reboot");
294 for (auto &component : std::ranges::reverse_view(this->components_)) {
295 component->on_shutdown();
296 }
297 arch_restart();
298}
300 ESP_LOGI(TAG, "Rebooting safely");
302 teardown_components(TEARDOWN_TIMEOUT_REBOOT_MS);
304 arch_restart();
305}
306
308 for (auto &component : std::ranges::reverse_view(this->components_)) {
309 component->on_safe_shutdown();
310 }
311 for (auto &component : std::ranges::reverse_view(this->components_)) {
312 component->on_shutdown();
313 }
314}
315
317 for (auto &component : std::ranges::reverse_view(this->components_)) {
318 component->on_powerdown();
319 }
320}
321
323 uint32_t start_time = MillisInternal::get();
324
325 // Use a StaticVector instead of std::vector to avoid heap allocation
326 // since we know the actual size at compile time
328
329 // Copy all components in reverse order
330 // Reverse order matches the behavior of run_safe_shutdown_hooks() above and ensures
331 // components are torn down in the opposite order of their setup_priority (which is
332 // used to sort components during Application::setup())
333 size_t num_components = this->components_.size();
334 for (size_t i = 0; i < num_components; ++i) {
335 pending_components[i] = this->components_[num_components - 1 - i];
336 }
337
338 uint32_t now = start_time;
339 size_t pending_count = num_components;
340
341 // Teardown Algorithm
342 // ==================
343 // We iterate through pending components, calling teardown() on each.
344 // Components that return false (need more time) are copied forward
345 // in the array. Components that return true (finished) are skipped.
346 //
347 // The compaction happens in-place during iteration:
348 // - still_pending tracks the write position (where to put next pending component)
349 // - i tracks the read position (which component we're testing)
350 // - When teardown() returns false, we copy component[i] to component[still_pending]
351 // - When teardown() returns true, we just skip it (don't increment still_pending)
352 //
353 // Example with 4 components where B can teardown immediately:
354 //
355 // Start:
356 // pending_components: [A, B, C, D]
357 // pending_count: 4 ^----------^
358 //
359 // Iteration 1:
360 // i=0: A needs more time → keep at pos 0 (no copy needed)
361 // i=1: B finished → skip
362 // i=2: C needs more time → copy to pos 1
363 // i=3: D needs more time → copy to pos 2
364 //
365 // After iteration 1:
366 // pending_components: [A, C, D | D]
367 // pending_count: 3 ^--------^
368 //
369 // Iteration 2:
370 // i=0: A finished → skip
371 // i=1: C needs more time → copy to pos 0
372 // i=2: D finished → skip
373 //
374 // After iteration 2:
375 // pending_components: [C | C, D, D] (positions 1-3 have old values)
376 // pending_count: 1 ^--^
377
378 while (pending_count > 0 && (now - start_time) < timeout_ms) {
379 // Feed watchdog during teardown to prevent triggering
380 this->feed_wdt_with_time(now);
381
382 // Process components and compact the array, keeping only those still pending
383 size_t still_pending = 0;
384 for (size_t i = 0; i < pending_count; ++i) {
385 if (!pending_components[i]->teardown()) {
386 // Component still needs time, copy it forward
387 if (still_pending != i) {
388 pending_components[still_pending] = pending_components[i];
389 }
390 ++still_pending;
391 }
392 // Component finished teardown, skip it (don't increment still_pending)
393 }
394 pending_count = still_pending;
395
396 // Give some time for I/O operations if components are still pending
397 if (pending_count > 0) {
399 }
400
401 // Update time for next iteration
402 now = MillisInternal::get();
403 }
404
405 if (pending_count > 0) {
406 // Note: At this point, connections are either disconnected or in a bad state,
407 // so this warning will only appear via serial rather than being transmitted to clients
408 for (size_t i = 0; i < pending_count; ++i) {
409 ESP_LOGW(TAG, "%s did not complete teardown within %" PRIu32 " ms",
410 LOG_STR_ARG(pending_components[i]->get_component_log_str()), timeout_ms);
411 }
412 }
413}
414
416 for (auto *obj : this->components_) {
417 if (obj->has_overridden_loop() &&
418 ((obj->get_component_state() & COMPONENT_STATE_MASK) == COMPONENT_STATE_LOOP_DONE) == match_loop_done) {
419 this->looping_components_.push_back(obj);
420 }
421 }
422}
423
425 // This method must be reentrant - components can disable themselves during their own loop() call
426 // Linear search to find component in active section
427 // Most configs have 10-30 looping components (30 is on the high end)
428 // O(n) is acceptable here as we optimize for memory, not complexity
429 for (uint16_t i = 0; i < this->looping_components_active_end_; i++) {
430 if (this->looping_components_[i] == component) {
431 // Move last active component to this position
432 this->looping_components_active_end_--;
433 if (i != this->looping_components_active_end_) {
434 std::swap(this->looping_components_[i], this->looping_components_[this->looping_components_active_end_]);
435
436 // If we're currently iterating and just swapped the current position
437 if (this->in_loop_ && i == this->current_loop_index_) {
438 // Decrement so we'll process the swapped component next
439 this->current_loop_index_--;
440 // Update the loop start time to current time so the swapped component
441 // gets correct timing instead of inheriting stale timing.
442 // This prevents integer underflow in timing calculations by ensuring
443 // the swapped component starts with a fresh timing reference, avoiding
444 // errors caused by stale or wrapped timing values.
445 this->loop_component_start_time_ = MillisInternal::get();
446 }
447 }
448 return;
449 }
450 }
451}
452
454 // Helper to move component from inactive to active section
455 if (index != this->looping_components_active_end_) {
456 std::swap(this->looping_components_[index], this->looping_components_[this->looping_components_active_end_]);
457 }
459}
460
462 // This method is only called when component state is LOOP_DONE, so we know
463 // the component must be in the inactive section (if it exists in looping_components_)
464 // Only search the inactive portion for better performance
465 // With typical 0-5 inactive components, O(k) is much faster than O(n)
466 const uint16_t size = this->looping_components_.size();
467 for (uint16_t i = this->looping_components_active_end_; i < size; i++) {
468 if (this->looping_components_[i] == component) {
469 // Found in inactive section - move to active
471 return;
472 }
473 }
474 // Component not found in looping_components_ - this is normal for components
475 // that don't have loop() or were not included in the partitioned vector
476}
477
479 // Process components that requested enable_loop from ISR context
480 // Only iterate through inactive looping_components_ (typically 0-5) instead of all components
481 //
482 // Race condition handling:
483 // 1. We check if component is already in LOOP state first - if so, just clear the flag
484 // This handles reentrancy where enable_loop() was called between ISR and processing
485 // 2. We only clear pending_enable_loop_ after checking state, preventing lost requests
486 // 3. If any components aren't in LOOP_DONE state, we set has_pending_enable_loop_requests_
487 // back to true to ensure we check again next iteration
488 // 4. ISRs can safely set flags at any time - worst case is we process them next iteration
489 // 5. The global flag (has_pending_enable_loop_requests_) is cleared before this method,
490 // so any ISR that fires during processing will be caught in the next loop
491 const uint16_t size = this->looping_components_.size();
492 bool has_pending = false;
493
494 for (uint16_t i = this->looping_components_active_end_; i < size; i++) {
496 if (!component->pending_enable_loop_) {
497 continue; // Skip components without pending requests
498 }
499
500 // Check current state
502
503 // If already in LOOP state, nothing to do - clear flag and continue
505 component->pending_enable_loop_ = false;
506 continue;
507 }
508
509 // If not in LOOP_DONE state, can't enable yet - keep flag set
511 has_pending = true; // Keep tracking this component
512 continue; // Keep the flag set - try again next iteration
513 }
514
515 // Clear the pending flag and enable the loop
516 component->pending_enable_loop_ = false;
517 ESP_LOGVV(TAG, "%s loop enabled from ISR", LOG_STR_ARG(component->get_component_log_str()));
518 component->set_component_state_(COMPONENT_STATE_LOOP);
519
520 // Move to active section
522 }
523
524 // If we couldn't process some requests, ensure we check again next iteration
525 if (has_pending) {
527 }
528}
529
530// App storage — asm label shares the linker symbol with "extern Application App".
531// char[] is trivially destructible, so no __cxa_atexit or destructor chain is emitted.
532// Constructed via placement new in the generated setup().
533#ifndef __GXX_ABI_VERSION
534#error "Application placement new requires Itanium C++ ABI (GCC/Clang)"
535#endif
536static_assert(std::is_default_constructible<Application>::value, "Application must be default-constructible");
537// __USER_LABEL_PREFIX__ is "_" on Mach-O (macOS) and empty on ELF (embedded targets).
538// String literal concatenation produces the correct platform-specific mangled symbol.
539// Two-level macro needed: # stringifies before expansion, so the
540// indirection forces __USER_LABEL_PREFIX__ to expand first.
541#define ESPHOME_STRINGIFY_IMPL_(x) #x
542#define ESPHOME_STRINGIFY_(x) ESPHOME_STRINGIFY_IMPL_(x)
543// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
544alignas(Application) char app_storage[sizeof(Application)] asm(
545 ESPHOME_STRINGIFY_(__USER_LABEL_PREFIX__) "_ZN7esphome3AppE");
546#undef ESPHOME_STRINGIFY_
547#undef ESPHOME_STRINGIFY_IMPL_
548
549void Application::get_build_time_string(std::span<char, BUILD_TIME_STR_SIZE> buffer) {
550 ESPHOME_strncpy_P(buffer.data(), ESPHOME_BUILD_TIME_STR, buffer.size());
551 buffer[buffer.size() - 1] = '\0';
552}
553
554void Application::get_comment_string(std::span<char, ESPHOME_COMMENT_SIZE_MAX> buffer) {
555 ESPHOME_strncpy_P(buffer.data(), ESPHOME_COMMENT_STR, ESPHOME_COMMENT_SIZE);
556 buffer[ESPHOME_COMMENT_SIZE - 1] = '\0';
557}
558
559uint32_t Application::get_config_hash() { return ESPHOME_CONFIG_HASH; }
560
561uint32_t Application::get_config_version_hash() { return ESPHOME_CONFIG_VERSION_HASH; }
562
563time_t Application::get_build_time() { return ESPHOME_BUILD_TIME; }
564
565} // 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.
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:195
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:504
Minimal static vector - saves memory by avoiding std::vector overhead.
Definition helpers.h:286
size_t size() const
Definition helpers.h:355
const Component * component
Definition component.cpp:34
void yield(void)
const char * key
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
ESPHOME_LOG_TAG(TAG, CRASH_LOG_TAG)
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:95
constexpr uint8_t STATUS_LED_MASK
Definition component.h:90
constexpr uint8_t COMPONENT_STATE_LOOP
Definition component.h:86
constexpr uint8_t APP_STATE_SETUP_COMPLETE
Definition component.h:100
constexpr uint8_t STATUS_LED_WARNING
Definition component.h:92
constexpr uint8_t COMPONENT_STATE_MASK
Definition component.h:83
uint16_t size
Definition helpers.cpp:34
void clear_setup_priority_overrides()
void arch_feed_wdt()
Definition hal.cpp:58
constexpr uint8_t COMPONENT_STATE_LOOP_DONE
Definition component.h:88
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