Commit Graph

13967 Commits

Author SHA1 Message Date
J. Nick Koston
1d1b15c2d0 Merge branch 'dev' into binary-sensor-remove-optional-state 2026-03-22 21:11:33 -10:00
J. Nick Koston
5560c9eef7 [test] Fix flakey ld2412 integration test race condition (#15100) 2026-03-22 21:10:51 -10:00
J. Nick Koston
f4097d5a95 [api] Devirtualize API command dispatch (#15044) 2026-03-23 19:57:40 +13:00
Keith Burzinski
225330413a [uart] Rename FlushResult to UARTFlushResult with UART_FLUSH_RESULT_ prefix (#15101)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 01:55:14 -05:00
J. Nick Koston
e67b5a78d0 [esp32] Patch DRAM segment for testing mode to fix grouped component test overflow (#15102) 2026-03-23 01:51:40 -05:00
J. Nick Koston
c717ec0256 [binary_sensor] Fix doc comment about send_state_internal dispatch 2026-03-22 19:17:06 -10:00
J. Nick Koston
58c1ca086b Merge remote-tracking branch 'upstream/dev' into binary-sensor-remove-optional-state 2026-03-22 18:50:49 -10:00
J. Nick Koston
eaf38c10cc [binary_sensor] Use const T* instead of T current{} in set_new_state
Avoids requiring T to be default-constructible, which would break
future instantiations with non-default-constructible state types.

Capture old_state before set_state_value() since the pointer aliases
subclass storage that gets overwritten.
2026-03-22 18:40:00 -10:00
J. Nick Koston
cd5b19ab0d [binary_sensor] Fast-path dedup in send_state_internal before virtual dispatch
Check state == new_state directly before calling virtual set_new_state.
Avoids the virtual dispatch chain (BinarySensor::set_new_state →
StatefulEntityBase::set_new_state → virtual get_state()) on the
common no-change path. Fixes -20% CodSpeed regression on
BinarySensorPublish_NoChange benchmark.
2026-03-22 18:38:34 -10:00
J. Nick Koston
baf365404c [network] Inline get_use_address() to eliminate function call overhead (#14942) 2026-03-23 04:18:43 +00:00
J. Nick Koston
4a200f8a2b [binary_sensor] Reduce flash: cache get_state(), guard full_state_callbacks call
- Cache get_state() result to avoid calling the virtual method twice
  (once for comparison, once for old_state construction)
- Move full_state_callbacks_.call() inside the !empty() guard so both
  the optional construction and the call are skipped when no callbacks
- Swap to had_state || get_trigger_on_initial_state() so the virtual
  call is skipped on the common path (every change except the first)

Saves ~21 bytes of flash in set_new_state.
2026-03-22 18:16:57 -10:00
J. Nick Koston
8a4b152488 Merge branch 'dev' into binary-sensor-remove-optional-state 2026-03-22 18:08:32 -10:00
J. Nick Koston
0de2c758aa [scheduler] Use placement-new for std::function move in set_timer_common_ (#14757) 2026-03-23 16:31:27 +13:00
J. Nick Koston
597bb18543 [benchmark] Add binary sensor publish and sensor filter benchmarks (#15035) 2026-03-23 16:30:57 +13:00
Jesse Hills
ebdf20adc0 Merge branch 'release' into dev 2026-03-23 16:10:17 +13:00
J. Nick Koston
5e3d1f8de2 Merge branch 'dev' into binary-sensor-remove-optional-state 2026-03-22 17:09:40 -10:00
Jesse Hills
7ecdf6db2e Merge pull request #15084 from esphome/bump-2026.3.1
Some checks failed
CI for docker images / Build docker containers (docker, ubuntu-24.04) (push) Has been cancelled
CI for docker images / Build docker containers (docker, ubuntu-24.04-arm) (push) Has been cancelled
CI for docker images / Build docker containers (ha-addon, ubuntu-24.04) (push) Has been cancelled
CI for docker images / Build docker containers (ha-addon, ubuntu-24.04-arm) (push) Has been cancelled
CI / Create common environment (push) Has been cancelled
CI / Check pylint (push) Has been cancelled
CI / Run script/ci-custom (push) Has been cancelled
CI / Run pytest (macOS-latest, 3.11) (push) Has been cancelled
CI / Run pytest (macOS-latest, 3.14) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.11) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.13) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.14) (push) Has been cancelled
CI / Run pytest (windows-latest, 3.11) (push) Has been cancelled
CI / Run pytest (windows-latest, 3.14) (push) Has been cancelled
CI / Determine which jobs to run (push) Has been cancelled
CI / Run integration tests (push) Has been cancelled
CI / Run C++ unit tests (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 IDF (push) Has been cancelled
CI / Run script/clang-tidy for ESP8266 (push) Has been cancelled
CI / Run script/clang-tidy for ZEPHYR (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 1/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 2/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 3/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 4/4 (push) Has been cancelled
CI / Test components batch (${{ matrix.components }}) (push) Has been cancelled
CI / pre-commit.ci lite (push) Has been cancelled
CI / Build target branch for memory impact (push) Has been cancelled
CI / Build PR branch for memory impact (push) Has been cancelled
CI / Comment memory impact (push) Has been cancelled
CI / CI Status (push) Has been cancelled
2026.3.1
2026.3.1
2026-03-23 16:09:32 +13:00
J. Nick Koston
8a3b5a8def [core] Fix placement new storage name for templated types (#15096) 2026-03-23 16:09:23 +13:00
J. Nick Koston
65f02ac690 Merge remote-tracking branch 'upstream/fix-pstorage-template-namespace' into binary-sensor-remove-optional-state 2026-03-22 16:59:09 -10:00
J. Nick Koston
6c95f2e706 [core] Fix placement new storage name for templated types
When Pvariable types contain template arguments with :: (e.g.
Automation<std::optional<bool>>), the namespace extraction logic
incorrectly split on :: inside the template params, producing
invalid C++ identifiers like Automation<std__automation_id__pstorage.

Fix by stripping template arguments before extracting the namespace.
Extract the logic into a testable _extract_component_ns helper.
2026-03-22 16:56:35 -10:00
J. Nick Koston
9291b71176 [binary_sensor] Move set_trigger_on_initial_state off StatefulEntityBase
set_trigger_on_initial_state is only called from codegen on concrete
BinarySensor instances. It's an implementation detail of BinarySensor,
not part of the StatefulEntityBase contract. Only get_trigger_on_initial_state
remains as a pure virtual — subclasses decide how to control it.
2026-03-22 16:45:00 -10:00
J. Nick Koston
8aa9a82c13 [binary_sensor] Clarify trigger_on_initial_state docs - subclass decides storage 2026-03-22 16:43:37 -10:00
J. Nick Koston
a6e230d665 [binary_sensor] Restore comment about USE_BINARY_SENSOR guard 2026-03-22 16:40:47 -10:00
J. Nick Koston
1a8cbe92ff [binary_sensor] Update StatefulEntityBase docs to reflect virtual dispatch design 2026-03-22 16:39:28 -10:00
J. Nick Koston
3fd28eeea2 [binary_sensor] Inline send_state_internal - virtual dispatch prevents template bloat 2026-03-22 16:38:38 -10:00
J. Nick Koston
0417de007a [binary_sensor] Restore virtual set_new_state, remove on_state_changed hook
Making set_new_state virtual means callers like send_state_internal
and invalidate_state resolve via vtable dispatch to the .cpp, avoiding
template bloat without needing out-of-line tricks or hiding declarations.

BinarySensor overrides set_new_state directly for logging and
ControllerRegistry notification, matching the original pattern.
2026-03-22 16:37:54 -10:00
J. Nick Koston
27d38baf0d [binary_sensor] Fix invalidate_state: keep inline on base, hide on BinarySensor
invalidate_state() can't be declaration-only on a template class.
Keep it inline on StatefulEntityBase, and add a hiding declaration
on BinarySensor with an out-of-line definition in the .cpp to prevent
template bloat from automation.h and filter.cpp callers.
2026-03-22 16:36:17 -10:00
J. Nick Koston
df733708d5 Merge branch 'dev' into binary-sensor-remove-optional-state 2026-03-22 16:33:32 -10:00
J. Nick Koston
a827410ecf [binary_sensor] Fix clang-tidy naming: no trailing underscore on virtual methods
- set_new_state → set_new_state_ (protected non-virtual, trailing underscore)
- on_state_changed_ → on_state_changed (virtual, no trailing underscore)
- set_state_value_ → set_state_value (virtual, no trailing underscore)

Update StatefulEntityBase docs to list on_state_changed and invalidate_state.
2026-03-22 16:27:34 -10:00
J. Nick Koston
98d9fd76b3 [mqtt] Fix const-correctness for trigger constructors (#15093) 2026-03-22 16:27:20 -10:00
J. Nick Koston
6992219e34 [core] Attribute placement new storage symbols to components (#15092) 2026-03-22 16:27:07 -10:00
J. Nick Koston
349f45f582 [binary_sensor] Move send_state_internal and invalidate_state to .cpp
set_new_state is a template method (~189 bytes when instantiated).
Inlining callers like send_state_internal and invalidate_state causes
the template code to be duplicated at every call site (publish_state,
Filter::output, BinarySensorInvalidateAction::play, etc.), adding
~384 bytes of flash.

Keep these as out-of-line definitions in the .cpp so the template
is instantiated once.
2026-03-22 16:26:16 -10:00
J. Nick Koston
58498bacff [binary_sensor] Skip old_state construction when no full_state_callbacks registered 2026-03-22 16:21:25 -10:00
J. Nick Koston
14c54597ce [binary_sensor] Make set_new_state non-virtual, add on_state_changed_ hook
set_new_state is only called internally. Making it non-virtual
eliminates a vtable entry and allows the compiler to inline it.

BinarySensor now overrides on_state_changed_() for logging and
ControllerRegistry notification instead of overriding set_new_state.
2026-03-22 16:20:29 -10:00
J. Nick Koston
5854fa1d82 [binary_sensor] Access flags_ directly in set_new_state to reduce flash 2026-03-22 16:17:35 -10:00
J. Nick Koston
e28c9d191c [binary_sensor] Move send_state_internal to header for devirtualization 2026-03-22 16:16:59 -10:00
J. Nick Koston
2833401cc1 [binary_sensor] Simplify else-if in set_new_state 2026-03-22 16:15:24 -10:00
J. Nick Koston
1e2c5fbc4e [binary_sensor] Update state before firing callbacks in set_new_state
Move set_has_state and set_state_value_ before callback invocations
so callback code can inspect the entity's current state via
get_state()/has_state(). The old state is passed as a parameter.

Addresses Copilot review feedback.
2026-03-22 16:13:35 -10:00
J. Nick Koston
db3cfaa3fc [binary_sensor] Reduce flash: un-inline send_state_internal, optimize set_new_state
Move send_state_internal back to .cpp to avoid duplicating it at each
call site (publish_state and Filter::output).

Optimize set_new_state to compare has_state + value directly instead
of constructing optional<T> on stack for the comparison. Optionals
are only constructed in the changed path for callbacks that need them.
2026-03-22 16:11:06 -10:00
J. Nick Koston
fc1186895c [binary_sensor] Fix stale comment in StatefulEntityBase docs 2026-03-22 16:03:44 -10:00
J. Nick Koston
047a744ed3 [binary_sensor] Inline send_state_internal into header 2026-03-22 16:02:51 -10:00
J. Nick Koston
e406fb25cb [binary_sensor] Move trigger_on_initial_state out of EntityBase flags into BinarySensor
Use pure virtual get/set methods on StatefulEntityBase instead of
storing the flag in EntityBase::flags_. This keeps EntityBase clean
and avoids mixing binary_sensor-specific state into the base entity.
2026-03-22 16:01:39 -10:00
J. Nick Koston
98b0aea6bf [binary_sensor] Restore comment on state member 2026-03-22 16:00:07 -10:00
J. Nick Koston
7754e517f2 [binary_sensor] Add documentation comments to StatefulEntityBase 2026-03-22 15:59:33 -10:00
J. Nick Koston
91944988ef [binary_sensor] Remove redundant optional<bool> state_ from StatefulEntityBase
Replace optional<T> state_ in StatefulEntityBase with pure virtual
get_state()/set_state_value_() that subclasses implement. BinarySensor
stores its value in the existing public bool state member and uses
EntityBase::flags_.has_state instead of the optional's discriminant.

Move trigger_on_initial_state_ into EntityBase::flags_ (1 bit from
reserved), eliminating the standalone bool and its padding.

Saves 8 bytes per BinarySensor instance:
- optional<bool> (2B) + padding (2B) = 4B removed
- bool trigger_on_initial_state_ (1B) + padding (3B) = 4B removed
2026-03-22 15:58:31 -10:00
J. Nick Koston
fbe3e7d99c [api] Emit raw tag+value writes for forced fixed32 key fields (#15051) 2026-03-22 15:28:46 -10:00
J. Nick Koston
9cdc17566a [combination] Use FixedVector and parent pointer to enable inline Callback storage (#14947) 2026-03-22 15:06:45 -10:00
Kamil Cukrowski
cd05462e9f [core] Use placement new allocation for Pvariables (#15079)
Co-authored-by: J. Nick Koston <nick@home-assistant.io>
Co-authored-by: J. Nick Koston <nick@koston.org>
2026-03-22 14:42:04 -10:00
J. Nick Koston
83d02c602a [logger] Fix dummy_main.cpp Logger constructor for clang-tidy (#15088)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 13:25:04 +13:00
J. Nick Koston
e85065b1c4 [logger] Fix dummy_main.cpp Logger constructor for clang-tidy (#15088)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-22 14:06:00 -10:00