[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.
This commit is contained in:
J. Nick Koston
2026-03-22 16:49:20 -10:00
parent c082ba7d64
commit 30b5c3fb71
+5 -2
View File
@@ -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<typename F> void add_on_state_callback(F &&callback) { this->callback_.add(std::forward<F>(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<typename F> void add_on_raw_state_callback(F &&callback) {
#ifdef USE_SENSOR_FILTER
this->raw_callback_.add(std::forward<F>(callback));
}
#else
this->callback_.add(std::forward<F>(callback));
#endif
}
/** This member variable stores the last state that has passed through all filters.
*