From 30b5c3fb715b6db7e47db167aa8435be45442efc Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 22 Mar 2026 16:49:20 -1000 Subject: [PATCH] [sensor] Keep add_on_raw_state_callback always available Delegate to callback_ when USE_SENSOR_FILTER is off since raw state equals filtered state without filters. This avoids requiring external components to know about USE_SENSOR_FILTER. --- esphome/components/sensor/sensor.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/esphome/components/sensor/sensor.h b/esphome/components/sensor/sensor.h index 4baf188a9c..73fd10ea6f 100644 --- a/esphome/components/sensor/sensor.h +++ b/esphome/components/sensor/sensor.h @@ -115,12 +115,15 @@ class Sensor : public EntityBase { // (In most use cases you won't need these) /// Add a callback that will be called every time a filtered value arrives. template void add_on_state_callback(F &&callback) { this->callback_.add(std::forward(callback)); } -#ifdef USE_SENSOR_FILTER /// Add a callback that will be called every time the sensor sends a raw value. + /// Without filters, raw state equals filtered state so this delegates to the regular callback. template void add_on_raw_state_callback(F &&callback) { +#ifdef USE_SENSOR_FILTER this->raw_callback_.add(std::forward(callback)); - } +#else + this->callback_.add(std::forward(callback)); #endif + } /** This member variable stores the last state that has passed through all filters. *