diff --git a/esphome/components/sensor/filter.cpp b/esphome/components/sensor/filter.cpp index eef5c6cade..998f34be0f 100644 --- a/esphome/components/sensor/filter.cpp +++ b/esphome/components/sensor/filter.cpp @@ -222,8 +222,6 @@ MultiplyFilter::MultiplyFilter(TemplatableValue multiplier) : multiplier_ optional MultiplyFilter::new_value(float value) { return value * this->multiplier_.value(); } -uint32_t get_loop_component_start_time() { return App.get_loop_component_start_time(); } - // ValueListFilter helper (non-template, shared by all ValueListFilter instantiations) bool value_list_matches_any(Sensor *parent, float sensor_value, const TemplatableValue *values, size_t count) { int8_t accuracy = parent->get_accuracy_decimals(); diff --git a/esphome/components/sensor/filter.h b/esphome/components/sensor/filter.h index 87a309ffb3..db8156f544 100644 --- a/esphome/components/sensor/filter.h +++ b/esphome/components/sensor/filter.h @@ -332,8 +332,14 @@ class MultiplyFilter : public Filter { /// Non-template helper for value matching (implementation in filter.cpp) bool value_list_matches_any(Sensor *parent, float sensor_value, const TemplatableValue *values, size_t count); -/// Non-template helper to get cached loop start time (avoids circular include of application.h) -uint32_t get_loop_component_start_time(); +} // namespace esphome::sensor +// Forward declaration — avoids circular include of application.h. +// Template bodies are only instantiated in main.cpp where Application is fully defined. +namespace esphome { +class Application; +extern Application App; +} // namespace esphome +namespace esphome::sensor { /** Base class for filters that compare sensor values against a fixed list of configured values. * @@ -389,7 +395,7 @@ template class ThrottleWithPriorityFilter : public ValueListFilter : ValueListFilter(prioritized_values), min_time_between_inputs_(min_time_between_inputs) {} optional new_value(float value) override { - const uint32_t now = get_loop_component_start_time(); + const uint32_t now = App.get_loop_component_start_time(); if (this->last_input_ == 0 || now - this->last_input_ >= this->min_time_between_inputs_ || this->value_matches_any_(value)) { this->last_input_ = now;