Commit Graph

22476 Commits

Author SHA1 Message Date
J. Nick Koston
82e608369f Merge remote-tracking branch 'origin/integration' into integration 2026-02-14 05:32:59 -07:00
J. Nick Koston
c291d7deef Merge remote-tracking branch 'origin/fix-esp8266-dhcp-state-corruption' into integration 2026-02-14 05:32:40 -07:00
J. Nick Koston
46cc9c0eef [wifi] Simplify comment — remove unverified link state claim
Cannot confirm wifi_station_disconnect() synchronously clears the
lwIP netif LINK_UP flag on ESP8266 NONOS SDK. The comment doesn't
need to make claims about link state since the fix is simply that
the hostname never changes at runtime, making dhcp_renew() pointless.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 05:24:52 -07:00
J. Nick Koston
f7705c8589 [wifi] Remove dhcp_renew() entirely — it can never run usefully
The dhcp_renew() loop was cargo-culted from Arduino ESP8266's
WiFi.hostname() which was designed for changing the hostname on
an already-connected system with multiple interfaces (WiFi+Ethernet).

In ESPHome, wifi_apply_hostname_() is only called from:
  - setup_() — before WiFi connects (link never up)
  - wifi_sta_connect_() — after wifi_disconnect_() (link always down)

The hostname is fixed at compile time and never changes at runtime.
Setting intf->hostname is sufficient — lwIP automatically includes
it in DHCP DISCOVER/REQUEST packets via LWIP_NETIF_HOSTNAME.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 05:22:39 -07:00
J. Nick Koston
8abb472c3a [wifi] Also require netif_is_link_up for dhcp_renew guard
DHCP_STATE_BOUND alone is insufficient — during reconnection, DHCP
can remain BOUND from a previous connection while the link is down
(wifi_disconnect_() doesn't stop DHCP). Both conditions are needed:
DHCP must be BOUND and the interface must have link.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 20:04:51 -07:00
J. Nick Koston
c53d50b6cf [wifi] Use DHCP_STATE_BOUND check instead of netif_is_link_up
netif_is_link_up() is insufficient — if wifi_station_connect()
completes quickly (e.g. fast_connect), the setup() call at line 710
could reach dhcp_renew() with link up but DHCP still in SELECTING
or REQUESTING state, causing the same state corruption.

Check dhcp->state == DHCP_STATE_BOUND directly to ensure dhcp_renew()
is only called when there is an actual lease to renew.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 14:36:51 -06:00
J. Nick Koston
21528f03b6 Merge remote-tracking branch 'origin/fix-esp8266-dhcp-state-corruption' into integration 2026-02-13 14:35:05 -06:00
J. Nick Koston
1d9c9cb504 Merge remote-tracking branch 'origin/fix-esp8266-dhcp-state-corruption' into integration 2026-02-13 14:12:06 -06:00
J. Nick Koston
de76dfd117 [wifi] Fix ESP8266 DHCP state corruption from premature dhcp_renew()
wifi_apply_hostname_() calls dhcp_renew() on all interfaces with DHCP
data, including when WiFi is not yet connected. lwIP's dhcp_renew()
unconditionally sets the DHCP state to RENEWING (line 1159 in dhcp.c)
before attempting to send, and never rolls back the state on failure.

This corrupts the DHCP state machine: when WiFi later connects and
dhcp_network_changed() is called, it sees RENEWING state and calls
dhcp_reboot() instead of dhcp_discover(). dhcp_reboot() sends a
broadcast DHCP REQUEST for IP 0.0.0.0 (since no lease was ever
obtained), which can put some routers into a persistent bad state
that requires a router restart to clear.

This bug has existed since commit 072b2c445c (Dec 2019, "Add ESP8266
core v2.6.2") and affects every ESP8266 WiFi connection attempt. Most
routers handle the bogus DHCP REQUEST gracefully (NAK then fallback
to DISCOVER), but affected routers get stuck and refuse connections
from the device until restarted.

Fix: guard the dhcp_renew() call with netif_is_link_up() so it only
runs when the interface actually has an active link. The hostname is
still set on the netif regardless, so it will be included in DHCP
packets when the connection is established normally.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 14:02:21 -06:00
J. Nick Koston
cae14dff96 Merge branch 'nfc-constexpr-arrays' into integration 2026-02-13 11:31:30 -06:00
Kevin Ahrendt
903971de12 [runtime_image, online_image] Create runtime_image component to decode images (#10212) 2026-02-13 11:25:43 -05:00
J. Nick Koston
f3e930cb06 Fix clang-tidy: rename static constexpr to UPPER_SNAKE_CASE 2026-02-13 09:43:04 -06:00
J. Nick Koston
988b6db92c [nfc] Replace constant std::vector with static constexpr std::array
Replace heap-allocated std::vector constants with static constexpr
std::array in MIFARE Classic and Ultralight write operations across
pn532, pn7150, and pn7160 components.

Changes:
- Convert write_mifare_classic_block_ and write_mifare_ultralight_page_
  signatures from std::vector<uint8_t>& to const uint8_t*/size_t
- Replace 24 constant 16-byte vectors in format functions with
  static constexpr std::array (data now lives in flash/rodata)
- Replace 3 constant 4-byte blank_data vectors with static constexpr
  std::array
- Eliminate per-iteration vector copies in write_tag loops by passing
  pointers directly into the encoded buffer
2026-02-13 09:30:45 -06:00
J. Nick Koston
4149b9e040 Merge remote-tracking branch 'upstream/dev' into integration 2026-02-13 08:41:18 -06:00
J. Nick Koston
b04e427f01 [usb_host] Extract cold path from loop(), replace std::string with buffer API (#13957)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-02-13 06:39:00 -06:00
J. Nick Koston
b669a8a20f Merge branch 'make-log-entity-icon-noop-without-icons' into integration 2026-02-12 18:34:16 -06:00
J. Nick Koston
80927f0f80 [core] Make LOG_ENTITY_ICON a no-op when icons are compiled out
When USE_ENTITY_ICON is not defined, LOG_ENTITY_ICON and log_entity_icon
are now completely compiled out rather than calling a function that
checks an always-empty icon reference.
2026-02-12 18:29:55 -06:00
J. Nick Koston
bfd9448fcd Merge remote-tracking branch 'upstream/dev' into integration 2026-02-12 18:21:25 -06:00
J. Nick Koston
e0c03b2dfa [api] Fix ESP8266 noise API handshake deadlock and prompt socket cleanup (#13972) 2026-02-12 18:20:58 -06:00
J. Nick Koston
7dff631dcb [core] Flatten single-callsite vector realloc functions (#13970) 2026-02-12 18:20:39 -06:00
J. Nick Koston
36aba385af [web_server] Flatten deq_push_back_with_dedup_ to inline vector realloc (#13968) 2026-02-12 18:20:21 -06:00
J. Nick Koston
964e42e190 Merge remote-tracking branch 'origin/fix-esp8266-noise-handshake-deadlock' into integration 2026-02-12 17:58:16 -06:00
J. Nick Koston
375fc1db84 [api] Fix ESP8266 noise API handshake deadlock and prompt socket cleanup
Two fixes for ESP8266 with noise encryption:

1. Cache socket ready() before the handshake loop. On ESP8266 LWIP raw
   TCP, ready() returns the live state (false once rx buffer is consumed),
   unlike ESP32 where it is cached until the next main loop. Re-checking
   each iteration blocked handshake writes that must follow reads,
   deadlocking the handshake.

2. Process client removal immediately after loop() instead of deferring
   to the next server loop iteration. This closes the socket promptly
   to free LWIP PCB resources and prevent retransmit crashes on ESP8266.
2026-02-12 17:54:32 -06:00
J. Nick Koston
ebeb6ae9e1 Merge branch 'flatten-realloc-insert-callers' into integration 2026-02-12 16:48:20 -06:00
J. Nick Koston
2caaf681e2 Fix CI lint: rename push_item_ to push_item, remove const from bssid_t value param 2026-02-12 16:47:22 -06:00
J. Nick Koston
4a12eed328 Merge branch 'flatten-realloc-insert-callers' into integration 2026-02-12 16:45:48 -06:00
J. Nick Koston
54ab5ee6d5 tidy 2026-02-12 16:45:22 -06:00
J. Nick Koston
88660c4709 Merge remote-tracking branch 'origin/integration' into integration 2026-02-12 16:44:03 -06:00
J. Nick Koston
98fa8651fa Merge branch 'flatten-realloc-insert-callers' into integration 2026-02-12 16:43:50 -06:00
J. Nick Koston
5ed6a2b285 [core] Flatten single-callsite vector realloc functions
On ESP8266 (GCC 10.3), std::vector::push_back/emplace_back emit
separate _M_realloc_insert functions even when called from only
one site. Adding __attribute__((flatten)) inlines the realloc
path, saving the out-of-line function overhead.

Changes:
- wifi: Move set_sta_priority from header to .cpp (eliminates
  duplicate instantiation at 2 call sites) and add flatten
- web_server_base: Flatten add_handler (single push_back site)
- api: Flatten accept_new_connections_ (single emplace_back site)
- api: Extract push_item_ as single flattened push_back site for
  DeferredBatch (was 2 call sites in add_item/add_item_front)

Saves ~200 bytes of flash on ESP8266, ~40 bytes on ESP32.
2026-02-12 16:40:54 -06:00
J. Nick Koston
f5f662fa19 Merge branch 'flatten-realloc-insert-callers' into integration 2026-02-12 16:39:51 -06:00
J. Nick Koston
77a0eb4ebe Merge branch 'flatten-realloc-insert-callers' into integration 2026-02-12 16:29:58 -06:00
J. Nick Koston
bf9e3213f2 [core] Flatten single-callsite vector realloc functions
On ESP8266 (GCC 10.3), std::vector::push_back/emplace_back emit
separate _M_realloc_insert functions even when called from only
one site. Adding __attribute__((flatten)) inlines the realloc
path, saving the out-of-line function overhead.

Changes:
- wifi: Move set_sta_priority from header to .cpp (eliminates
  duplicate instantiation at 2 call sites) and add flatten
- web_server_base: Flatten add_handler (single push_back site)
- api: Flatten accept_new_connections_ (single emplace_back site)

Saves 160 bytes of flash on ESP8266.
2026-02-12 16:28:57 -06:00
J. Nick Koston
c4d83150f4 Merge remote-tracking branch 'origin/web_server-flatten-deq-push-back' into integration 2026-02-12 16:08:21 -06:00
J. Nick Koston
8cf3cbf7ea [web_server] Flatten deq_push_back_with_dedup_ to inline vector realloc
On ESP8266 (GCC 10.3), std::vector::push_back() emits a separate
_M_realloc_insert<DeferredEvent> function (198 bytes) that is only
called from one site. Adding __attribute__((flatten)) forces the
compiler to inline it, eliminating the out-of-line function's
prologue/epilogue and call overhead.

This matches what GCC 14.2 (ESP-IDF toolchain) already does
naturally for the equivalent code in web_server_idf.cpp.

Saves 80 bytes of flash on ESP8266.
2026-02-12 16:07:19 -06:00
J. Nick Koston
f7854fca8a Revert "[api] Extract keepalive ping to noinline function"
This reverts commit 94ea5bac3a.
2026-02-12 15:43:18 -06:00
J. Nick Koston
e8506218cb Merge branch 'api-extract-keepalive-ping' into integration 2026-02-12 15:33:55 -06:00
J. Nick Koston
94ea5bac3a [api] Extract keepalive ping to noinline function
Extract the keepalive ping sending logic from APIConnection::loop()
into a separate noinline send_keepalive_ping_() method. This code
only fires once per keepalive interval (~60s) making it cold relative
to the ~111 Hz loop rate. Moving it out reduces loop() from 337 to
258 bytes, keeping the hot path smaller and more cache-friendly.
2026-02-12 15:32:29 -06:00
J. Nick Koston
80d16dda42 Merge remote-tracking branch 'upstream/dev' into integration 2026-02-12 15:20:20 -06:00
Jonathan Swoboda
136d17366f [docker] Suppress git detached HEAD advice (#13962)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 16:12:17 -05:00
Jonathan Swoboda
db7870ef5f [alarm_control_panel] Fix flaky integration test race condition (#13964)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 16:04:39 -05:00
dependabot[bot]
bbc88d92ea Bump docker/build-push-action from 6.19.1 to 6.19.2 in /.github/actions/build-image (#13965)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-12 14:31:43 -06:00
J. Nick Koston
97c080e465 Merge branch 'wifi-memcpy-sort' into integration 2026-02-12 12:42:55 -06:00
J. Nick Koston
88df48a52d Add TODO for std::trivially_relocatable when available 2026-02-12 12:42:09 -06:00
J. Nick Koston
8676b99219 Merge branch 'wifi-memcpy-sort' into integration 2026-02-12 12:33:55 -06:00
J. Nick Koston
282ba90f62 Address review feedback: add explicit includes and clarify comments
- Add #include <type_traits> to both .cpp and .h for static_asserts
- Clarify CompactString comment: explicitly note it is not trivially
  copyable, and that memcpy safety relies on validated layout property
- Use memcpy_fn indirection to suppress both GCC -Wclass-memaccess
  and clang-tidy bugprone-undefined-memory-manipulation without
  platform-specific pragma guards
2026-02-12 12:32:06 -06:00
J. Nick Koston
58f8029264 [wifi] Use memcpy-based insertion sort for scan results
Replace copy-assignment with raw memcpy in the WiFi scan result
insertion sort. Copy assignment on WiFiScanResult calls
CompactString's destructor then placement-new for every shift,
which means delete[]/new[] per shift for heap-allocated SSIDs.

With 70+ networks visible (e.g., during captive portal transition
showing full scan results), this caused event loop blocking from
hundreds of heap allocations in a tight loop on an 80MHz ESP8266.

This optimization is safe because we're permuting elements within
the same array - each slot is overwritten exactly once, so no
ownership duplication occurs. CompactString stores either inline
data or a heap pointer, never a self-referential pointer (unlike
libstdc++ std::string SSO). This was made possible by PR#13472
which replaced std::string with CompactString.

Static asserts guard the memcpy safety assumptions at compile time.

Confirmed on real device: event loop blocking during captive portal
transition is eliminated and WiFi connection is slightly faster.
2026-02-12 12:29:19 -06:00
Jesse Hills
1604b5d6e4 Merge branch 'beta' into dev 2026-02-13 07:11:49 +13:00
Jesse Hills
e000858d77 Merge pull request #13951 from esphome/bump-2026.2.0b1
2026.2.0b1
2026.2.0b1
2026-02-13 07:11:07 +13:00
J. Nick Koston
7fd535179e [helpers] Add heap warnings to format_hex_pretty, deprecate ethernet/web_server std::string APIs (#13959) 2026-02-12 17:47:44 +00:00