13static constexpr uint32_t SECONDS_PER_HOUR = 3600;
14static constexpr float MINUTES_PER_DAY = 24.0f * 60.0f;
23void FilterLifetime::update() {
26 this->last_update_ = now;
30 if (std::isnan(speed))
32 speed = std::clamp(speed, 0.0f, 100.0f);
40 ESP_LOGV(TAG,
"Elapsed %" PRIu32
" ms at %.0f%%, runtime %" PRIu32
" s", elapsed_ms, speed, this->
runtime_seconds_);
48 const float remaining_minutes = std::max(0.0f, max_minutes - runtime_minutes);
49 this->
publish_state(100.0f * remaining_minutes / max_minutes);
50 PUBLISH_STATE(this->runtime_hours_sensor_, runtime_minutes / 60.0f);
51 PUBLISH_STATE(this->remaining_days_sensor_, remaining_minutes / MINUTES_PER_DAY);
56void FilterLifetime::reset_filter() {
61 ESP_LOGI(TAG,
"Filter lifetime reset");
65#ifdef USE_BINARY_SENSOR
67 if (this->is_on_binary_sensor_ !=
nullptr)
68 return this->is_on_binary_sensor_->state;
76 if (this->current_speed_sensor_ !=
nullptr)
77 return this->current_speed_sensor_->state;
83void FilterLifetime::dump_config() {
84 LOG_SENSOR(
"",
"Filter Lifetime",
this);
86 " Max lifetime: %" PRIu32
" min (%.1f days)\n"
90#ifdef USE_BINARY_SENSOR
91 if (this->is_on_binary_sensor_ !=
nullptr) {
92 LOG_BINARY_SENSOR(
" ",
"Is-on sensor", this->is_on_binary_sensor_);
96 ESP_LOGCONFIG(TAG,
" Is-on: %s",
97 this->
is_on_lambda_ !=
nullptr ? LOG_STR_LITERAL(
"lambda") : LOG_STR_LITERAL(
"always"));
99 if (this->current_speed_sensor_ !=
nullptr) {
100 LOG_SENSOR(
" ",
"Speed sensor", this->current_speed_sensor_);
102 ESP_LOGCONFIG(TAG,
" Speed: %s",
105 LOG_SENSOR(
" ",
"Runtime hours", this->runtime_hours_sensor_);
106 LOG_SENSOR(
" ",
"Remaining days", this->remaining_days_sensor_);
107 LOG_UPDATE_INTERVAL(
this);