Commit Graph

441 Commits

Author SHA1 Message Date
J. Nick Koston
64197c7330 Merge branch 'pack-entity-strings' into integration_pack_entity_strings
# Conflicts:
#	esphome/components/esp32/core.cpp
#	esphome/components/esp8266/core.cpp
#	esphome/components/host/core.cpp
#	esphome/components/libretiny/core.cpp
#	esphome/components/rp2040/core.cpp
#	esphome/components/zephyr/core.cpp
#	esphome/core/hal.h
2026-02-20 23:47:50 -06:00
J. Nick Koston
2906f56b3f tweaks 2026-02-20 23:32:28 -06:00
J. Nick Koston
f77da803c9 [api] Write protobuf encode output to pre-sized buffer directly (#14018) 2026-02-20 21:39:18 -06:00
J. Nick Koston
4c70f2001a Merge branch 'fix_logger_loop_disable' into integration 2026-02-20 13:21:08 -06:00
Jonathan Swoboda
9ce01fc369 [esp32] Add engineering_sample option for ESP32-P4 (#14139)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 11:20:05 -05:00
J. Nick Koston
d51b0e51b1 Merge remote-tracking branch 'origin/api_varint_split_32_64' into integration 2026-02-19 20:25:25 -06:00
J. Nick Koston
21b9a4139a Address review feedback: fix unconditional guard bug, add ifndef guard, clarify comment
- Fix get_varint64_ifdef() to return unconditional guard when any 64-bit
  varint field has no ifdef (None in ifdefs set)
- Wrap USE_API_VARINT64 define with #ifndef to avoid redefinition warnings
  when esphome/core/defines.h also defines it (test/IDE builds)
- Clarify proto.h comment about uint32_t shift behavior at byte 4
- Add namespace to generated api_pb2_defines.h for linter compliance
2026-02-19 20:23:17 -06:00
J. Nick Koston
4e3b2abd5f Fix ODR violation: generate api_pb2_defines.h for consistent ProtoVarInt layout
USE_API_VARINT64 was only defined in api_pb2.h, but proto.cpp (where
decode() and parse_wide() live) includes proto.h directly. This caused:

1. parse_wide() not compiled in proto.cpp (guarded by #ifdef)
2. decode() used 32-bit-only parse(), returning {} for varints > 5 bytes
3. ODR violation: ProtoVarInt was 4 bytes in proto.cpp but 8 bytes in
   api_pb2*.cpp translation units

For bluetooth_proxy, 48-bit BLE addresses encode as 7-byte varints.
The failed parse caused decode() to return early, leaving request_type
at its default value of 0 (BLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT),
producing spurious "V1 connections removed" errors.

Fix: Generate api_pb2_defines.h with the USE_API_VARINT64 define and
include it from proto.h, ensuring all translation units see a consistent
ProtoVarInt layout.
2026-02-19 20:08:29 -06:00
J. Nick Koston
41cfe2f9ad Merge remote-tracking branch 'upstream/dev' into integration 2026-02-19 09:17:46 -06:00
J. Nick Koston
b5a8e1c94c [ci] Update lint message to recommend constexpr over static const (#14099) 2026-02-19 09:06:46 -06:00
J. Nick Koston
2873f7f8f3 Merge branch 'api_varint_split_32_64' into integration 2026-02-18 10:23:08 -06:00
J. Nick Koston
bd6048faf8 Merge origin/dev into api_varint_split_32_64 2026-02-17 18:56:11 -06:00
J. Nick Koston
3989236154 [api] Split ProtoVarInt::parse into 32-bit and 64-bit phases
On 32-bit platforms (ESP32 Xtensa), 64-bit shifts in varint parsing
compile to __ashldi3 library calls. Since the vast majority of protobuf
varint fields (message types, sizes, enum values, sensor readings) fit
in 4 bytes, the 64-bit arithmetic is unnecessary overhead on the common
path.

Split parse() into two phases:
- Bytes 0-3: uint32_t loop with native 32-bit shifts (0, 7, 14, 21)
- Bytes 4-9: noinline parse_wide_() with uint64_t, only for BLE
  addresses and other 64-bit fields

The code generator auto-detects which proto messages use int64/uint64/
sint64 fields and emits USE_API_VARINT64 conditionally. On non-BLE
configs, parse_wide_() and the 64-bit accessors (as_uint64, as_int64,
as_sint64) are compiled out entirely.

Saves ~40 bytes flash on non-BLE configs. Benchmark shows 25-50%
faster parsing for 1-4 byte varints (the common case).
2026-02-17 18:54:25 -06:00
J. Nick Koston
63bf03c467 Merge branch 'api-proto-write-presized-buffer' into integration 2026-02-16 16:09:01 -06:00
J. Nick Koston
9d387b66db address copilot revie wcomments 2026-02-16 16:03:35 -06:00
J. Nick Koston
09f604f2fc Merge branch 'api-proto-write-presized-buffer' into integration
# Conflicts:
#	esphome/components/api/proto.h
2026-02-16 15:17:06 -06:00
J. Nick Koston
f1d51773af Revert "[api] Pass ProtoWriteBuffer by reference in encode()"
This reverts commit 6369f3b279.
2026-02-16 15:12:10 -06:00
J. Nick Koston
6369f3b279 [api] Pass ProtoWriteBuffer by reference in encode()
Pass ProtoWriteBuffer by reference instead of by value in virtual
encode() methods. This avoids copying both buffer_ and pos_ pointers
for every encode call - only a single pointer is passed.

Also simplifies encode_message since child writes directly advance
the shared pos_. Adds debug_check_size_ to verify calculate_size
matches actual encode output.
2026-02-16 15:01:59 -06:00
J. Nick Koston
af4579ca87 [api] Write protobuf encode output to pre-sized buffer directly
ProtoSize::calculate_size() already computes the exact encoded size
before encode() runs and is the boundary validation. The buffer is
pre-sized to match. Since the buffer size is always correct,
push_back() capacity checks on every byte are redundant overhead.

Rename ProtoWriteBuffer to ProtoWritePreSizedBuffer to document the
contract. Write through a raw uint8_t* pointer instead of push_back().
Pre-resize the buffer to include payload space before encoding.

Add ESPHOME_DEBUG_API bounds checks to validate writes stay within the
pre-sized region during development and integration testing.
2026-02-16 14:40:55 -06:00
J. Nick Koston
e8f2d21d66 Merge remote-tracking branch 'origin/deprecate-wifi-ssid' into integration 2026-02-12 10:49:15 -06:00
Guillermo Ruffino
7b251dcc31 [schema-gen] fix Windows: ensure UTF-8 encoding when reading component files (#13952) 2026-02-12 11:23:59 -05:00
J. Nick Koston
6c6da8a3cd [api] Skip class generation for empty SOURCE_CLIENT protobuf messages (#13880) 2026-02-09 18:45:24 +00:00
J. Nick Koston
e4ea016d1e [ci] Block new std::to_string() usage, suggest snprintf alternatives (#13369) 2026-02-09 12:26:19 -06:00
J. Nick Koston
743fdee8e2 Merge branch 'no_gen_empty_messages' into integration 2026-02-09 12:20:20 -06:00
J. Nick Koston
8b733921b5 rename dict to make bot happy 2026-02-09 12:20:01 -06:00
J. Nick Koston
e40fccc526 Merge branch 'no_gen_empty_messages' into integration
# Conflicts:
#	esphome/components/esp32_hosted/update/esp32_hosted_update.cpp
#	esphome/core/component.cpp
2026-02-09 12:12:28 -06:00
J. Nick Koston
c658d7b57f [api] Merge auth check into base read_message, eliminate APIServerConnection (#13873) 2026-02-09 12:02:02 -06:00
J. Nick Koston
3cde3daceb [api] Collapse APIServerConnection intermediary layer (#13872) 2026-02-09 08:45:33 -06:00
J. Nick Koston
4f5be934a0 [api] Skip class generation for empty SOURCE_CLIENT protobuf messages 2026-02-09 04:12:01 -06:00
J. Nick Koston
f3a0d46ee9 Revert "[api] Skip class generation for empty SOURCE_CLIENT protobuf messages"
This reverts commit bd23e3ffa9.
2026-02-09 04:11:39 -06:00
J. Nick Koston
bd23e3ffa9 [api] Skip class generation for empty SOURCE_CLIENT protobuf messages 2026-02-09 04:05:23 -06:00
J. Nick Koston
140ec0639c [api] Elide empty message construction in protobuf dispatch (#13871) 2026-02-09 03:24:45 -06:00
J. Nick Koston
491112db69 Generate auth check unconditionally in read_message
If all messages required auth (both no_conn_ids and conn_only_ids
empty), the auth check block would be skipped entirely. Now generates
a simple check_authenticated_() call as fallback when there are no
exceptions to the default auth requirement.
2026-02-08 10:23:22 -06:00
J. Nick Koston
140629a323 Merge branch 'merge_read_message' into integration 2026-02-08 10:19:57 -06:00
J. Nick Koston
2376c020e8 Merge auth check into base read_message, eliminate APIServerConnection
Move the authentication/connection check switch into
APIServerConnectionBase::read_message before the dispatch switch,
eliminating the APIServerConnection class entirely. APIConnection
now inherits directly from APIServerConnectionBase.
2026-02-08 10:11:42 -06:00
J. Nick Koston
d28c3e2641 Collapse APIServerConnection intermediary layer
Remove the 48 on_xxx overrides and 48 pure virtual methods from
the generated APIServerConnection class. APIConnection now overrides
on_xxx() directly from APIServerConnectionBase, eliminating one
virtual call per message dispatch and ~96 vtable entries.
2026-02-08 10:05:10 -06:00
J. Nick Koston
4cf1d7babf Revert "Collapse APIServerConnection intermediary layer"
This reverts commit cac82280b3.
2026-02-08 09:57:03 -06:00
J. Nick Koston
cac82280b3 Collapse APIServerConnection intermediary layer
Remove the 48 on_xxx overrides and 48 pure virtual methods from
the generated APIServerConnection class. APIConnection now overrides
on_xxx() directly from APIServerConnectionBase, eliminating one
virtual call per message dispatch and ~96 vtable entries.
2026-02-08 09:55:31 -06:00
J. Nick Koston
df7e837e3e Merge branch 'empty_messages_reduce' into integration 2026-02-08 09:35:48 -06:00
J. Nick Koston
aa38ec379a Address review: fix RECEIVE_CASES type annotation and log format
- Update RECEIVE_CASES type hint from 2-tuple to 3-tuple to match
  the actual stored shape (case, ifdef, message_name)
- Use consistent log format "%s: {}" for empty message overload
  to match the "%s: %s" pattern of non-empty messages
2026-02-08 09:32:40 -06:00
J. Nick Koston
639a704411 Merge branch 'empty_messages_reduce' into integration 2026-02-08 09:21:27 -06:00
J. Nick Koston
c641256396 empty messages 2026-02-08 09:16:53 -06:00
J. Nick Koston
e4dd75f0b5 empty messages 2026-02-08 09:15:15 -06:00
J. Nick Koston
a7d1686cfd empty messages 2026-02-08 09:14:15 -06:00
J. Nick Koston
a56415ca3f empty messages 2026-02-08 09:10:48 -06:00
J. Nick Koston
55ef8393af [api] Remove is_single parameter and fix batch buffer preparation (#13773)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-02-05 15:19:03 +01:00
J. Nick Koston
c3b823552f Merge branch 'get_rid_of_is_single' into integration 2026-02-05 15:00:40 +01:00
J. Nick Koston
f4e410f47f [ci] Block new scanf() usage to prevent ~9.8KB flash bloat (#13657) 2026-02-06 02:56:43 +13:00
J. Nick Koston
da4fc73c06 tweak 2026-02-05 14:44:13 +01:00
J. Nick Koston
3859f48ddd make clang-tidy happy 2026-02-05 14:38:12 +01:00