Replace encode_message with encode_sub_message for protobuf submessage encoding.
For repeated submessage fields, encode_sub_message uses a backpatch approach:
writes field tag, reserves 1 byte for length varint, encodes the body, then
backpatches the actual length. For bodies >= 128 bytes, shifts the body forward
to make room for a multi-byte varint. This eliminates 2 of 3 calculate_size()
calls per repeated submessage element.
For singular submessage fields, encode_sub_message uses calculate_size() upfront
to skip empty submessages without writing to the buffer, preserving the debug
size check.
For the BLE advertisement proxy hot path (16 advertisements per batch), this
reduces calculate_size() calls from 48 to 16 per flush.
The is_connected() method is called on every BLE advertisement
in the bluetooth_proxy hot path, but was forced out-of-line by
the state_subscription_only parameter added in #11906.
The default path (no argument) is just `!clients_.empty()` — a
simple pointer comparison. Split into:
- is_connected(): inline in header (common fast path)
- is_connected_with_state_subscription(): out-of-line (rare path)
No callers pass true directly; only APIConnectedCondition uses
the state_subscription_only template value, updated accordingly.
- Fix extract_packed_value regex to handle commas in entity names
by matching C++ string literals instead of [^,]+
- Only describe dc/uom/icon in comments when their index is actually
non-zero, so comment matches what was packed
Move the flag-check early return for status_clear_warning() and
status_clear_error() into inline methods in the header. The slow
path (flag clear + log message) remains out-of-line.
This eliminates a call8 on every poll cycle for components that
call status_clear_warning() unconditionally on success, which is
the common pattern.
Tests now verify packed values via comment strings and non-zero
checks rather than decoding individual bit positions. This removes
the coupling to internal bit layout constants.
All internal-flag tests now extract the packed value and verify
bit 24 is set/clear for the correct entities, instead of just
checking configure_entity_() call presence.
All internal-flag tests now extract the packed value and verify
bit 24 is set/clear for the correct entities, instead of just
checking configure_entity_() call presence.
Tests now go through _setup_entity_impl + setup_device_class/
setup_unit_of_measurement + finalize_entity_strings using real
CONF_* keys instead of internal _KEY_* constants.
- Remove hardcoded _ENTITY_CATEGORY_NAMES dict, derive from cv.ENTITY_CATEGORIES keys
- Remove redundant local import re (already at top level)
- Remove last setup_test_environment noqa line
- Sensor and text_sensor device_class tests now extract and verify the
packed argument is non-zero instead of just checking call presence
- Remove useless setup_test_environment fixture references in unit tests
Move set_internal(), set_disabled_by_default(), set_entity_category(),
and set_device() to protected on EntityBase. These were codegen-only
setters never intended for runtime use.
internal, disabled_by_default, and entity_category are now packed into
the existing configure_entity_() uint32 parameter alongside string
indices, eliminating up to 3 separate function calls per entity.
set_device() is renamed to set_device_() per protected naming convention
and remains a separate call (pointer can't be packed).
Entity category integer mapping is derived from cv.ENTITY_CATEGORIES
to stay in sync with the C++ enum automatically.