Commit Graph
27953 Commits
Author SHA1 Message Date
J. Nick Koston 7d0cb4afe6 [core] Deduplicate entity type boilerplate with X-macro pattern
Introduce entity_types.inc X-macro and entity_includes.h shared header
to eliminate ~1000 lines of repetitive #ifdef/entity-type blocks across
core files.

entity_types.inc defines each entity type once with two macros:
- ENTITY_TYPE_ for non-controller entities (button, infrared)
- ENTITY_CONTROLLER_TYPE_ for entities with controller callbacks

Each consumer includes the file with appropriate macro definitions.
Sites wanting all entities delegate ENTITY_CONTROLLER_TYPE_ to
ENTITY_TYPE_. Sites wanting only controller entities define
ENTITY_TYPE_ as empty.

entity_includes.h consolidates the conditional entity header includes
shared by application.h, controller.h, and controller_registry.h.

Also makes ComponentIterator::on_media_player pure virtual for
consistency (trivial override added to web_server::ListEntitiesIterator).
2026-04-09 14:13:39 -10:00
Jesse Hills 668007707d [CI] Add org fork detection warning to auto-label PR workflow (#15588) 2026-04-10 12:13:22 +12:00
J. Nick Koston b9d0f96053 Merge remote-tracking branch 'origin/inline-encode-ble-adv' into integration 2026-04-09 11:57:55 -10:00
J. Nick Koston fd69a8e380 Merge remote-tracking branch 'upstream/dev' into integration 2026-04-09 11:56:18 -10:00
dependabot[bot]andJ. Nick Koston ab71f5276f Bump ruff from 0.15.9 to 0.15.10 (#15609)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@home-assistant.io>
2026-04-09 19:36:25 +00:00
J. Nick Koston 6fe6bf79d4 Address Copilot review: fix namespace and custom separator test 2026-04-09 09:30:06 -10:00
Jonathan Swoboda d062f62656 [sx127x][cc1101] Disable loop when packet mode is inactive (#15606) 2026-04-09 15:00:52 -04:00
J. Nick Koston a941422fa6 Add unit tests for format_hex helpers 2026-04-09 08:36:40 -10:00
J. Nick Koston c945cbc64c bot comments 2026-04-09 08:10:39 -10:00
J. Nick Koston 36ac6e277a Merge branch 'dev' into optimize-value-accuracy 2026-04-09 07:54:37 -10:00
J. Nick Koston a0b0238ff8 Merge branch 'dev' into optimize-format-hex 2026-04-09 07:54:02 -10:00
J. Nick Koston 03db32d045 [core] Add CodSpeed benchmarks for hot helper functions (#15593) 2026-04-09 07:48:32 -10:00
J. Nick Koston 8f6d489a9a [ci] Use --base-only for memory impact builds (#15598) 2026-04-09 11:48:33 -04:00
J. Nick Koston dd07fba943 [socket] Document ready() contract: callers must drain or track (#15590) 2026-04-09 11:48:18 -04:00
J. Nick Koston 6f5d642a31 [gdk101] Increase reset retries for slow-booting sensor MCU (#15584) 2026-04-09 11:48:10 -04:00
J. Nick Koston 781ab59611 Remove duplicate unrolled inline size cases, always use loop 2026-04-09 00:16:07 -10:00
J. Nick Koston 382202334a Simplify field_ifdef handling in inline blocks 2026-04-09 00:15:24 -10:00
J. Nick Koston 277552cef0 Address review: reserve_byte, varint(0), field_ifdef, getattr guard 2026-04-09 00:13:36 -10:00
J. Nick Koston 1d9b097e1f Merge branch 'dev' into inline-encode-ble-adv 2026-04-09 00:05:06 -10:00
dependabot[bot] 2721f08bcc Bump aioesphomeapi from 44.12.0 to 44.13.1 (#15600)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-09 10:03:58 +00:00
J. Nick Koston 1279e6112a Support max_data_length in get_max_encoded_size for string types 2026-04-08 23:42:08 -10:00
J. Nick Koston 24edb9c98e Eliminate sub_size variable, accumulate directly into size 2026-04-08 23:29:51 -10:00
J. Nick Koston 1ac2a73267 Remove redundant body_start variable in inline encode 2026-04-08 23:25:12 -10:00
J. Nick Koston 14a4a2c618 Remove redundant block scoping inside loop bodies 2026-04-08 23:12:47 -10:00
J. Nick Koston 4d4b77f9fc [api] Add (inline_encode) proto option for sub-message inlining
Add a new message-level option (inline_encode) that causes the code
generator to inline sub-message encoding directly into the parent's
encode/calculate_size methods instead of going through the
encode_sub_message function pointer indirection.

When set on a sub-message type, the generator:
- Inlines field encoding directly (no function pointer, no backpatch overhead)
- Inlines size calculation (no separate method call)
- Skips generating standalone encode/calculate_size methods
- Validates at generation time that max encoded size < 128 bytes

Applied to BluetoothLERawAdvertisement which is encoded 12 times per
BLE advertisement batch in a hot loop.
2026-04-08 23:06:41 -10:00
J. Nick Koston e0fa1340e2 Use std::span for uint32_to_str public API 2026-04-08 21:02:20 -10:00
J. Nick Koston 3b45179948 Split uint32_to_str/frac_to_str into internal and public API
- uint32_to_str_(): raw pointer, internal use
- uint32_to_str(): template with compile-time buffer size check
- frac_to_str_(): raw pointer, internal use
- small_pow10(): simplify to ternary chain
2026-04-08 21:01:32 -10:00
J. Nick Koston e52c3b01e6 Extract buf_append_sep_str helper, add tests 2026-04-08 20:52:51 -10:00
J. Nick Koston c8e636f253 Add unit tests for small_pow10, uint32_to_str, frac_to_str 2026-04-08 20:51:06 -10:00
J. Nick Koston ff1f0a0d46 Extract inline helpers: small_pow10, uint32_to_str, frac_to_str 2026-04-08 20:50:03 -10:00
J. Nick Koston 5ac1f10b28 Fix clang-tidy braces 2026-04-08 20:46:16 -10:00
J. Nick Koston d8e586609f [core] Optimize value_accuracy_to_buf to avoid snprintf
Replace snprintf("%.*f") with integer-based formatting for finite
float values with accuracy_decimals 0-3 (covers virtually all sensor
usage). Falls back to snprintf for higher accuracy or NaN/Inf.

Uses lrint() with double cast for the multiply to match snprintf's
rounding behavior exactly. The fast path avoids snprintf's heavy
float formatting machinery entirely.

Also optimizes value_accuracy_with_uom_to_buf to append the UOM
string directly instead of going through snprintf.

Adds C++ unit tests that verify output matches snprintf for a range
of values including edge cases.

Benchmark: 92,961ns -> 6,484ns (14.3x faster, 2000 iterations).
2026-04-08 20:46:16 -10:00
J. Nick Koston bd66f26144 [core] Optimize format_hex_internal by eliminating per-byte length check
Remove the per-byte `i < length - 1` check in the separator path by
writing the separator unconditionally after each byte and overwriting
the last one with the null terminator.

Single-loop approach keeps code smaller than the original while
eliminating the hot-path branch. Flash: -16 bytes vs baseline.
2026-04-08 20:41:09 -10:00
J. Nick Koston 671e434400 [core] Force-inline format_hex_char to prevent outlining
The loop split in format_hex_internal doubled the call sites for
format_hex_char, causing the compiler to outline it (+30 bytes new
symbol). Mark it always_inline to keep it inlined.
2026-04-08 20:25:48 -10:00
J. Nick Koston b8e4343d86 [core] Optimize format_hex_internal by splitting separator loop
Split the single loop into two paths (with/without separator) to
eliminate the per-byte branch on separator. In the separator path,
write the separator unconditionally and overwrite the last one with
the null terminator. This also lets the compiler use constant stride
values (2 or 3) instead of a runtime variable.

Benchmarks show ~16-20% improvement on the separator path
(format_hex_pretty_to, format_mac_addr_upper).
2026-04-08 20:04:44 -10:00
J. Nick Koston 352121b7bf [core] Add CodSpeed benchmarks for hot helper functions
Add benchmarks for format_hex_to, format_hex_pretty_to,
format_mac_addr_upper, fnv1_hash, fnv1a_hash, fnv1_hash_object_id,
parse_hex, crc8, crc16, value_accuracy_to_buf, int8_to_str, and
base64_decode to establish baseline performance data before optimization.
2026-04-08 19:57:37 -10:00
J. Nick Koston eafc5df3f2 [safe_mode] Combine related OTA rollback log messages (#15592) 2026-04-09 05:30:39 +00:00
J. Nick Koston 46d0c29be5 [safe_mode] Use loop component start time instead of millis() (#15591) 2026-04-09 05:20:32 +00:00
J. Nick Koston 6ef0d993c9 Merge remote-tracking branch 'upstream/safe-mode-combine-log-messages' into integration 2026-04-08 18:57:37 -10:00
J. Nick Koston afbecce86f [safe_mode] Combine related OTA rollback log messages 2026-04-08 18:56:35 -10:00
J. Nick Koston 3a16cd6eb9 Merge remote-tracking branch 'upstream/safe-mode-use-loop-start-time' into integration 2026-04-08 18:50:44 -10:00
J. Nick Koston 05816d8786 [safe_mode] Use loop component start time instead of millis() 2026-04-08 18:49:40 -10:00
J. Nick Koston 4089e422dd Merge remote-tracking branch 'upstream/dev' into integration 2026-04-08 18:44:50 -10:00
J. Nick Koston abdbbf4dd2 [api] Fix ListEntitiesRequest not read due to LWIP rcvevent tracking (#15589) 2026-04-09 02:14:01 +00:00
Jesse Hills 4dc0599a7d Merge branch 'beta' into dev 2026-04-09 13:41:27 +12:00
Jesse Hills ded0936b2a Merge pull request #15587 from esphome/bump-2026.4.0b1
2026.4.0b1
2026.4.0b1
2026-04-09 13:40:37 +12:00
J. Nick Koston 8c0ca29c04 [api] Update MAX_MESSAGES_PER_LOOP comment to not hardcode old value 2026-04-08 15:38:01 -10:00
J. Nick Koston 0eb2e8710e Merge branch 'fix-api-list-entities-read-stall' into integration 2026-04-08 15:33:18 -10:00
J. Nick Koston 5c7e858c79 Merge remote-tracking branch 'upstream/dev' into integration 2026-04-08 15:33:08 -10:00
J. Nick Koston d0e5035f0e [api] Fix ListEntitiesRequest not being read due to LWIP rcvevent tracking
When the client sends 6+ messages during handshake (HelloReq, AuthReq,
GetTimeResp, SubscribeLogsReq, DeviceInfoReq, ListEntitiesReq),
MAX_MESSAGES_PER_LOOP=5 caused ListEntitiesReq to remain unread in
the socket buffer.

LWIP's rcvevent counter (used by is_socket_ready) tracks pbuf dequeues,
not remaining bytes. When multiple ESPHome messages share a single TCP
segment/pbuf, reading all but the last message exhausts rcvevent to 0
while the last message's data remains in LWIP's internal lastdata cache.
is_socket_ready() then returns false, and the data is never read — the
entity listing silently stalls until something else (like a keepalive
ping) triggers new socket activity.

Fix:
- Track when the read loop hits MAX_MESSAGES_PER_LOOP and retry on the
  next iteration without the is_socket_ready() gate
- Increase MAX_MESSAGES_PER_LOOP from 5 to 10 (decode cost is now 3x
  cheaper, and we batch 24-34 messages per write)
- Move set_nodelay_for_message(false) before try_to_clear_buffer in
  process_batch_() so NODELAY is set before draining overflow
2026-04-08 15:27:02 -10:00