mirror of
https://github.com/esphome/esphome.git
synced 2026-05-21 02:01:57 +08:00
[sensor] Pack ThrottleAverageFilter have_nan_ into n_ bitfield (-4 B/instance) (#16169)
This commit is contained in:
@@ -564,7 +564,12 @@ async def exponential_moving_average_filter_to_code(config, filter_id):
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register(
|
||||
"throttle_average", ThrottleAverageFilter, cv.positive_time_period_milliseconds
|
||||
"throttle_average",
|
||||
ThrottleAverageFilter,
|
||||
cv.All(
|
||||
cv.positive_time_period_milliseconds,
|
||||
cv.Range(max=cv.TimePeriod(hours=24)),
|
||||
),
|
||||
)
|
||||
async def throttle_average_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(filter_id, config)
|
||||
|
||||
@@ -264,9 +264,12 @@ class ThrottleAverageFilter : public Filter {
|
||||
|
||||
protected:
|
||||
float sum_{0.0f};
|
||||
unsigned int n_{0};
|
||||
uint32_t time_period_;
|
||||
bool have_nan_{false};
|
||||
// Sample count packed with NaN-seen flag in a single 32-bit word.
|
||||
// n_ is bounded by YAML cap on time_period_ (24 h) × max plausible source
|
||||
// rate (1 kHz) = 86.4M ≪ 2^31, so 31 bits has 25x headroom.
|
||||
uint32_t n_ : 31 {0};
|
||||
uint32_t have_nan_ : 1 {0};
|
||||
};
|
||||
|
||||
using lambda_filter_t = std::function<optional<float>(float)>;
|
||||
|
||||
Reference in New Issue
Block a user