mirror of
https://github.com/esphome/esphome.git
synced 2025-10-04 02:52:22 +01:00
Introduce clamp as a template function (#1953)
This commit is contained in:
@@ -6,7 +6,7 @@ namespace fan {
|
||||
|
||||
FanSpeed speed_level_to_enum(int speed_level, int supported_speed_levels) {
|
||||
const auto speed_ratio = static_cast<float>(speed_level) / (supported_speed_levels + 1);
|
||||
const auto legacy_level = static_cast<int>(clamp(ceilf(speed_ratio * 3), 1, 3));
|
||||
const auto legacy_level = clamp<int>(static_cast<int>(ceilf(speed_ratio * 3)), 1, 3);
|
||||
return static_cast<FanSpeed>(legacy_level - 1);
|
||||
}
|
||||
|
||||
|
@@ -54,7 +54,7 @@ void FanStateCall::perform() const {
|
||||
}
|
||||
if (this->speed_.has_value()) {
|
||||
const int speed_count = this->state_->get_traits().supported_speed_count();
|
||||
this->state_->speed = static_cast<int>(clamp(*this->speed_, 1, speed_count));
|
||||
this->state_->speed = clamp(*this->speed_, 1, speed_count);
|
||||
}
|
||||
|
||||
FanStateRTCState saved{};
|
||||
|
Reference in New Issue
Block a user