[midea] Add Fahrenheit support to follow me action

By default temperature is in celsius, user can specify optional boolean to mark that passed temp is in fahrenheit. Should close https://github.com/esphome/feature-requests/issues/2790
This commit is contained in:
Djordje 2024-11-13 20:48:47 +01:00
parent adcfdc9e4c
commit b760a74c5f
6 changed files with 24 additions and 18 deletions

View file

@ -19,10 +19,11 @@ template<typename... Ts> class MideaActionBase : public Action<Ts...> {
template<typename... Ts> class FollowMeAction : public MideaActionBase<Ts...> {
TEMPLATABLE_VALUE(float, temperature)
TEMPLATABLE_VALUE(bool, fahrenheit)
TEMPLATABLE_VALUE(bool, beeper)
void play(Ts... x) override {
this->parent_->do_follow_me(this->temperature_.value(x...), this->beeper_.value(x...));
this->parent_->do_follow_me(this->temperature_.value(x...), this->fahrenheit_.value(x...), this->beeper_.value(x...));
}
};

View file

@ -121,7 +121,7 @@ void AirConditioner::dump_config() {
/* ACTIONS */
void AirConditioner::do_follow_me(float temperature, bool beeper) {
void AirConditioner::do_follow_me(float temperature, bool fahrenheit, bool beeper) {
#ifdef USE_REMOTE_TRANSMITTER
// Check if temperature is finite (not NaN or infinite)
if (!std::isfinite(temperature)) {
@ -133,11 +133,12 @@ void AirConditioner::do_follow_me(float temperature, bool beeper) {
uint8_t temp_uint8 =
static_cast<uint8_t>(std::clamp<long>(std::lroundf(temperature), 0L, static_cast<long>(UINT8_MAX)));
ESP_LOGD(Constants::TAG, "Follow me action called with temperature: %f °C, rounded to: %u °C", temperature,
temp_uint8);
char temp_symbol = fahrenheit ? 'F' : 'C';
ESP_LOGD(Constants::TAG, "Follow me action called with temperature: %f °%c, rounded to: %u °%c", temperature,
temp_symbol, temp_uint8, temp_symbol);
// Create and transmit the data
IrFollowMeData data(temp_uint8, beeper);
IrFollowMeData data(temp_uint8, fahrenheit, beeper);
this->transmitter_.transmit(data);
#else
ESP_LOGW(Constants::TAG, "Action needs remote_transmitter component");

View file

@ -32,7 +32,7 @@ class AirConditioner : public ApplianceBase<dudanov::midea::ac::AirConditioner>,
/* ### ACTIONS ### */
/* ############### */
void do_follow_me(float temperature, bool beeper = false);
void do_follow_me(float temperature, bool fahrenheit, bool beeper = false);
void do_display_toggle();
void do_swing_step();
void do_beeper_on() { this->set_beeper_feedback(true); }

View file

@ -40,6 +40,7 @@ DEPENDENCIES = ["climate", "uart"]
AUTO_LOAD = ["sensor"]
CONF_POWER_USAGE = "power_usage"
CONF_HUMIDITY_SETPOINT = "humidity_setpoint"
CONF_FAHRENHEIT = "fahrenheit"
midea_ac_ns = cg.esphome_ns.namespace("midea").namespace("ac")
AirConditioner = midea_ac_ns.class_("AirConditioner", climate.Climate, cg.Component)
Capabilities = midea_ac_ns.namespace("Constants")
@ -172,11 +173,14 @@ MIDEA_ACTION_BASE_SCHEMA = cv.Schema(
)
# FollowMe action
MIDEA_FOLLOW_ME_MIN = 0
MIDEA_FOLLOW_ME_MAX = 37
MIDEA_FOLLOW_ME_MIN_C = 0
MIDEA_FOLLOW_ME_MAX_C = 37
MIDEA_FOLLOW_ME_MIN_F = 32
MIDEA_FOLLOW_ME_MAX_F = 99
MIDEA_FOLLOW_ME_SCHEMA = cv.Schema(
{
cv.Required(CONF_TEMPERATURE): cv.templatable(cv.temperature),
cv.Optional(CONF_FAHRENHEIT, default=False): cv.templatable(cv.boolean),
cv.Optional(CONF_BEEPER, default=False): cv.templatable(cv.boolean),
}
)
@ -186,6 +190,8 @@ MIDEA_FOLLOW_ME_SCHEMA = cv.Schema(
async def follow_me_to_code(var, config, args):
template_ = await cg.templatable(config[CONF_BEEPER], args, cg.bool_)
cg.add(var.set_beeper(template_))
template_ = await cg.templatable(config[CONF_FAHRENHEIT], args, cg.bool_)
cg.add(var.set_fahrenheit(template_))
template_ = await cg.templatable(config[CONF_TEMPERATURE], args, cg.float_)
cg.add(var.set_temperature(template_))

View file

@ -19,14 +19,12 @@ class IrFollowMeData : public IrData {
IrFollowMeData(const IrData &data) : IrData(data) {}
// Direct from temperature in celsius and beeper values
IrFollowMeData(uint8_t temp, bool beeper = false) : IrFollowMeData() {
this->set_fahrenheit(false);
this->set_temp(temp);
this->set_temp(temp, false);
this->set_beeper(beeper);
}
// Direct from temperature, fahrenheit and beeper values
IrFollowMeData(uint8_t temp, bool fahrenheit, bool beeper) : IrFollowMeData() {
this->set_fahrenheit(fahrenheit);
this->set_temp(temp);
this->set_temp(temp, fahrenheit);
this->set_beeper(beeper);
}
@ -37,7 +35,8 @@ class IrFollowMeData : public IrData {
}
return this->get_value_(4) - 1;
}
void set_temp(uint8_t val) {
void set_temp(uint8_t val, bool fahrenheit = false) {
this->set_fahrenheit(fahrenheit);
if (this->fahrenheit()) {
// see https://github.com/esphome/feature-requests/issues/1627#issuecomment-1365639966
val = std::clamp<uint8_t>(val, MIN_TEMP_F, MAX_TEMP_F) - 31;

View file

@ -65,14 +65,12 @@ class FollowMeData : public MideaData {
FollowMeData(const MideaData &data) : MideaData(data) {}
// Direct from temperature in celsius and beeper values
FollowMeData(uint8_t temp, bool beeper = false) : FollowMeData() {
this->set_fahrenheit(false);
this->set_temp(temp);
this->set_temp(temp, false);
this->set_beeper(beeper);
}
// Direct from temperature, fahrenheit and beeper values
FollowMeData(uint8_t temp, bool fahrenheit, bool beeper) : FollowMeData() {
this->set_fahrenheit(fahrenheit);
this->set_temp(temp);
this->set_temp(temp, fahrenheit);
this->set_beeper(beeper);
}
@ -83,7 +81,8 @@ class FollowMeData : public MideaData {
}
return this->get_value_(4) - 1;
}
void set_temp(uint8_t val) {
void set_temp(uint8_t val, bool fahrenheit = false) {
this->set_fahrenheit(fahrenheit);
if (this->fahrenheit()) {
// see https://github.com/esphome/feature-requests/issues/1627#issuecomment-1365639966
val = std::clamp<uint8_t>(val, MIN_TEMP_F, MAX_TEMP_F) - 31;