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.
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.
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.
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
Deprecate direct access to sensor .raw_state member in favor of
get_raw_state(). This prepares for eventually compiling out raw_state
on builds without sensor filters, saving 4 bytes per sensor instance.
Guard raw_callback_ and add_on_raw_state_callback behind
USE_SENSOR_FILTER, saving 4 bytes per sensor on builds without
filters immediately.
Guard SensorRawStateTrigger behind USE_SENSOR_FILTER and ensure
on_raw_value automation sets USE_SENSOR_FILTER define.
Fix nextion sensor to stop directly writing .raw_state/.state
members - the publish=false path was redundantly setting already-current
values.
Migrate haier hon_climate from .raw_state to get_raw_state().
Embed component namespace in storage variable names so analyze-memory
can reliably attribute them. Display as "storage for {id}" in reports
and always show regardless of size threshold.
The Logger constructor requires a task_log_buffer_size argument when
USE_ESPHOME_TASK_LOG_BUFFER is defined, which is the case in defines.h
used by clang-tidy.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>