mirror of
https://github.com/esphome/esphome.git
synced 2026-08-31 10:06:03 +00:00
Merge remote-tracking branch 'upstream/sensor_value_list_static_array' into integration
This commit is contained in:
@@ -222,7 +222,14 @@ MultiplyFilter::MultiplyFilter(TemplatableValue<float> multiplier) : multiplier_
|
||||
|
||||
optional<float> MultiplyFilter::new_value(float value) { return value * this->multiplier_.value(); }
|
||||
|
||||
uint32_t get_loop_component_start_time() { return App.get_loop_component_start_time(); }
|
||||
bool throttle_check_and_update(uint32_t &last_input, uint32_t min_time_between_inputs) {
|
||||
const uint32_t now = App.get_loop_component_start_time();
|
||||
if (last_input == 0 || now - last_input >= min_time_between_inputs) {
|
||||
last_input = now;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ValueListFilter helper (non-template, shared by all ValueListFilter<N> instantiations)
|
||||
bool value_list_matches_any(Sensor *parent, float sensor_value, const TemplatableValue<float> *values, size_t count) {
|
||||
|
||||
@@ -332,8 +332,9 @@ 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<float> *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();
|
||||
/// 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).
|
||||
bool throttle_check_and_update(uint32_t &last_input, uint32_t min_time_between_inputs);
|
||||
|
||||
/** Base class for filters that compare sensor values against a fixed list of configured values.
|
||||
*
|
||||
@@ -389,10 +390,8 @@ template<size_t N> class ThrottleWithPriorityFilter : public ValueListFilter<N>
|
||||
: ValueListFilter<N>(prioritized_values), min_time_between_inputs_(min_time_between_inputs) {}
|
||||
|
||||
optional<float> new_value(float value) override {
|
||||
const uint32_t now = get_loop_component_start_time();
|
||||
if (this->last_input_ == 0 || now - this->last_input_ >= this->min_time_between_inputs_ ||
|
||||
if (throttle_check_and_update(this->last_input_, this->min_time_between_inputs_) ||
|
||||
this->value_matches_any_(value)) {
|
||||
this->last_input_ = now;
|
||||
return value;
|
||||
}
|
||||
return {};
|
||||
|
||||
@@ -504,7 +504,9 @@ template<typename T, size_t MAX_CAPACITY = std::numeric_limits<uint16_t>::max()>
|
||||
/// falls back to element-wise copy for non-trivially copyable types (e.g. TemplatableValue).
|
||||
/// N is set by code generation; ESPHOME_DEBUG_ASSERT catches mismatches in debug/integration tests.
|
||||
template<typename T, size_t N> inline void init_array_from(std::array<T, N> &dest, std::initializer_list<T> src) {
|
||||
ESPHOME_DEBUG_ASSERT(src.size() == N);
|
||||
#ifdef ESPHOME_DEBUG
|
||||
assert(src.size() == N);
|
||||
#endif
|
||||
if constexpr (std::is_trivially_copyable_v<T>) {
|
||||
__builtin_memcpy(dest.data(), src.begin(), N * sizeof(T));
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user