Move logger codegen priority above platform init so that
global_logger is set before setup_preferences() or any other
platform code that may contain ESP_LOG* calls.
Previously the logger initialized at DIAGNOSTICS priority (90),
which ran after PLATFORM (1000). With VERY_VERBOSE, the
ESP_LOGVV in ESP8266Preferences::setup() fired before
global_logger was set, causing a nullptr dereference crash.
Also hardcode `using namespace esphome;` in writer.py so it
precedes all variable declarations regardless of codegen
priority ordering.
Fixes#14970
Clear residual IOMUX function on UART0 default pins before calling
uart_set_pin(). The ROM bootloader configures these pins via IOMUX
for console output. ESP-IDF's uart_set_pin() has an asymmetry: when
routing TX via GPIO matrix it calls gpio_func_sel(PIN_FUNC_GPIO) to
clear IOMUX, but for RX it only calls gpio_input_enable() which does
NOT clear the IOMUX function select.
If a default UART0 TX pin is later reassigned as RX via GPIO matrix
(common on ESP32-C3 where users swap GPIO20/GPIO21), the old IOMUX TX
function remains active, causing transmitted data to loop back into RX.
This is a targeted fix using gpio_func_sel() which only writes the
IO MUX function register - unlike the previous gpio_reset_pin()
approach which also changed direction, pulls, and drive strength,
breaking external components that rely on default pin state (#11823).
Fixes#14973Fixes#14612
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Replace std::bind calls in subscribe/subscribe_json template methods
with equivalent lambdas. Uses static_cast<T*>(this) instead of
C-style cast for type safety.
Replace std::bind calls in subscribe_homeassistant_state template
methods with equivalent lambdas. Uses static_cast<T*>(this) instead
of C-style cast for type safety.
Replace std::bind calls that use std::placeholders with equivalent
lambdas. Lambdas with explicit parameters are more readable and
generate smaller callable objects than std::bind results.
Components: wifi (libretiny), haier (base, hon, smartair2),
homeassistant/number.
The set_timeout lambda captured [this, curr_time_ns] (4 + 8 = 12
bytes), exceeding the std::function small buffer optimization
threshold (8 bytes on 32-bit) and forcing a heap allocation every
measurement cycle (every 3s in LP mode).
Store curr_time_ns as a class member and capture only [this] (4
bytes), which fits inline in the SBO. Trades 8 bytes of permanent
member storage to eliminate a heap alloc+free cycle per measurement.