[sensor] Pack ThrottleAverageFilter have_nan_ into n_ bitfield (-4 B/instance) (#16169)

This commit is contained in:
J. Nick Koston
2026-04-30 19:13:10 -05:00
committed by GitHub
parent 2f3e16b482
commit 3b3e003aa3
2 changed files with 11 additions and 3 deletions
+6 -1
View File
@@ -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)
+5 -2
View File
@@ -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)>;