[midea] [midea_ir] Use esphome clamp helper instead of std clamp

This commit is contained in:
Djordje 2024-11-13 20:57:44 +01:00
parent b760a74c5f
commit 8561b0a62f
3 changed files with 8 additions and 7 deletions

View file

@ -1,6 +1,7 @@
#ifdef USE_ARDUINO #ifdef USE_ARDUINO
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/helpers.h"
#include "air_conditioner.h" #include "air_conditioner.h"
#include "ac_adapter.h" #include "ac_adapter.h"
#include <cmath> #include <cmath>
@ -131,7 +132,7 @@ void AirConditioner::do_follow_me(float temperature, bool fahrenheit, bool beepe
// Round and convert temperature to long, then clamp and convert it to uint8_t // Round and convert temperature to long, then clamp and convert it to uint8_t
uint8_t temp_uint8 = uint8_t temp_uint8 =
static_cast<uint8_t>(std::clamp<long>(std::lroundf(temperature), 0L, static_cast<long>(UINT8_MAX))); static_cast<uint8_t>(esphome::clamp<long>(std::lroundf(temperature), 0L, static_cast<long>(UINT8_MAX)));
char temp_symbol = fahrenheit ? 'F' : 'C'; char temp_symbol = fahrenheit ? 'F' : 'C';
ESP_LOGD(Constants::TAG, "Follow me action called with temperature: %f °%c, rounded to: %u °%c", temperature, ESP_LOGD(Constants::TAG, "Follow me action called with temperature: %f °%c, rounded to: %u °%c", temperature,

View file

@ -3,7 +3,7 @@
#ifdef USE_ARDUINO #ifdef USE_ARDUINO
#ifdef USE_REMOTE_TRANSMITTER #ifdef USE_REMOTE_TRANSMITTER
#include "esphome/components/remote_base/midea_protocol.h" #include "esphome/components/remote_base/midea_protocol.h"
#include <algorithm> #include "esphome/core/helpers.h"
namespace esphome { namespace esphome {
namespace midea { namespace midea {
@ -39,9 +39,9 @@ class IrFollowMeData : public IrData {
this->set_fahrenheit(fahrenheit); this->set_fahrenheit(fahrenheit);
if (this->fahrenheit()) { if (this->fahrenheit()) {
// see https://github.com/esphome/feature-requests/issues/1627#issuecomment-1365639966 // see https://github.com/esphome/feature-requests/issues/1627#issuecomment-1365639966
val = std::clamp<uint8_t>(val, MIN_TEMP_F, MAX_TEMP_F) - 31; val = esphome::clamp<uint8_t>(val, MIN_TEMP_F, MAX_TEMP_F) - 31;
} else { } else {
val = std::clamp<uint8_t>(val, MIN_TEMP_C, MAX_TEMP_C) + 1; val = esphome::clamp<uint8_t>(val, MIN_TEMP_C, MAX_TEMP_C) + 1;
} }
this->set_value_(4, val); this->set_value_(4, val);
} }

View file

@ -2,7 +2,7 @@
#include "esphome/components/remote_base/midea_protocol.h" #include "esphome/components/remote_base/midea_protocol.h"
#include "esphome/components/climate/climate_mode.h" #include "esphome/components/climate/climate_mode.h"
#include <algorithm> #include "esphome/core/helpers.h"
namespace esphome { namespace esphome {
namespace midea_ir { namespace midea_ir {
@ -85,9 +85,9 @@ class FollowMeData : public MideaData {
this->set_fahrenheit(fahrenheit); this->set_fahrenheit(fahrenheit);
if (this->fahrenheit()) { if (this->fahrenheit()) {
// see https://github.com/esphome/feature-requests/issues/1627#issuecomment-1365639966 // see https://github.com/esphome/feature-requests/issues/1627#issuecomment-1365639966
val = std::clamp<uint8_t>(val, MIN_TEMP_F, MAX_TEMP_F) - 31; val = esphome::clamp<uint8_t>(val, MIN_TEMP_F, MAX_TEMP_F) - 31;
} else { } else {
val = std::clamp<uint8_t>(val, MIN_TEMP_C, MAX_TEMP_C) + 1; val = esphome::clamp<uint8_t>(val, MIN_TEMP_C, MAX_TEMP_C) + 1;
} }
this->set_value_(4, val); this->set_value_(4, val);
} }