mirror of
https://github.com/esphome/esphome.git
synced 2026-07-11 01:15:33 +00:00
Fix: prioritized values must update last_input_ to match dev behavior
This commit is contained in:
@@ -255,6 +255,8 @@ bool throttle_check_and_update(uint32_t &last_input, uint32_t min_time_between_i
|
||||
return false;
|
||||
}
|
||||
|
||||
void throttle_update_timestamp(uint32_t &last_input) { last_input = App.get_loop_component_start_time(); }
|
||||
|
||||
// ThrottleFilter
|
||||
ThrottleFilter::ThrottleFilter(uint32_t min_time_between_inputs) : min_time_between_inputs_(min_time_between_inputs) {}
|
||||
optional<float> ThrottleFilter::new_value(float value) {
|
||||
|
||||
@@ -378,10 +378,13 @@ class ThrottleFilter : public Filter {
|
||||
uint32_t min_time_between_inputs_;
|
||||
};
|
||||
|
||||
/// Returns true if throttle should allow the value through (time expired or first input).
|
||||
/// Updates last_input in-place. Implementation in filter.cpp (accesses App without circular include).
|
||||
/// Returns true if throttle time has expired or this is the first input.
|
||||
/// Implementation in filter.cpp (accesses App without circular include).
|
||||
bool throttle_check_and_update(uint32_t &last_input, uint32_t min_time_between_inputs);
|
||||
|
||||
/// Update last_input timestamp to current loop time. Implementation in filter.cpp.
|
||||
void throttle_update_timestamp(uint32_t &last_input);
|
||||
|
||||
/// Same as 'throttle' but will immediately publish values contained in `value_to_prioritize`.
|
||||
template<size_t N> class ThrottleWithPriorityFilter : public ValueListFilter<N> {
|
||||
public:
|
||||
@@ -392,6 +395,7 @@ template<size_t N> class ThrottleWithPriorityFilter : public ValueListFilter<N>
|
||||
optional<float> new_value(float value) override {
|
||||
if (throttle_check_and_update(this->last_input_, this->min_time_between_inputs_) ||
|
||||
this->value_matches_any_(value)) {
|
||||
throttle_update_timestamp(this->last_input_);
|
||||
return value;
|
||||
}
|
||||
return {};
|
||||
|
||||
Reference in New Issue
Block a user