From 9291b71176c0e8ae13a6df023b5bccc9a2f24a24 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 22 Mar 2026 16:45:00 -1000 Subject: [PATCH] [binary_sensor] Move set_trigger_on_initial_state off StatefulEntityBase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- esphome/components/binary_sensor/binary_sensor.h | 2 +- esphome/core/entity_base.h | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/esphome/components/binary_sensor/binary_sensor.h b/esphome/components/binary_sensor/binary_sensor.h index 37362bc432e..9525832705b 100644 --- a/esphome/components/binary_sensor/binary_sensor.h +++ b/esphome/components/binary_sensor/binary_sensor.h @@ -35,7 +35,7 @@ class BinarySensor : public StatefulEntityBase { explicit BinarySensor() = default; const bool &get_state() const override { return this->state; } - void set_trigger_on_initial_state(bool value) override { this->trigger_on_initial_state_ = value; } + void set_trigger_on_initial_state(bool value) { this->trigger_on_initial_state_ = value; } /** Publish a new state to the front-end. * diff --git a/esphome/core/entity_base.h b/esphome/core/entity_base.h index 4ea7d069874..187894fea00 100644 --- a/esphome/core/entity_base.h +++ b/esphome/core/entity_base.h @@ -305,7 +305,6 @@ void log_entity_unit_of_measurement(const char *tag, const char *prefix, const E * - get_state(): return a const reference to the current value * - set_state_value(): store a new value (called only when the state actually changes) * - get_trigger_on_initial_state(): return whether callbacks should fire on the first state - * - set_trigger_on_initial_state(): store the value (subclass decides how) * * Subclasses may override set_new_state() to add behavior (logging, notifications) after calling * the base implementation. Since set_new_state() is virtual, callers like invalidate_state() and @@ -335,10 +334,6 @@ template class StatefulEntityBase : public EntityBase { this->state_callbacks_.add(std::forward(callback)); } - /// Control whether state_callbacks_ fire on the very first state (before any previous state exists). - /// Subclasses decide how to store the value. - virtual void set_trigger_on_initial_state(bool value) = 0; - protected: /// Subclasses return whether callbacks should fire on the very first state. virtual bool get_trigger_on_initial_state() const = 0;