From b760a74c5f4e2bfec1f4aafa5f5e72d799598166 Mon Sep 17 00:00:00 2001 From: Djordje <6750655+DjordjeMandic@users.noreply.github.com> Date: Wed, 13 Nov 2024 20:48:47 +0100 Subject: [PATCH] [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 --- esphome/components/midea/ac_automations.h | 3 ++- esphome/components/midea/air_conditioner.cpp | 9 +++++---- esphome/components/midea/air_conditioner.h | 2 +- esphome/components/midea/climate.py | 10 ++++++++-- esphome/components/midea/ir_transmitter.h | 9 ++++----- esphome/components/midea_ir/midea_data.h | 9 ++++----- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/esphome/components/midea/ac_automations.h b/esphome/components/midea/ac_automations.h index 5084fd1eec..ab17a91a15 100644 --- a/esphome/components/midea/ac_automations.h +++ b/esphome/components/midea/ac_automations.h @@ -19,10 +19,11 @@ template class MideaActionBase : public Action { template class FollowMeAction : public MideaActionBase { 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...)); } }; diff --git a/esphome/components/midea/air_conditioner.cpp b/esphome/components/midea/air_conditioner.cpp index 16be15d4da..0513160711 100644 --- a/esphome/components/midea/air_conditioner.cpp +++ b/esphome/components/midea/air_conditioner.cpp @@ -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(std::clamp(std::lroundf(temperature), 0L, static_cast(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"); diff --git a/esphome/components/midea/air_conditioner.h b/esphome/components/midea/air_conditioner.h index d809aa78f6..f5248f4bc4 100644 --- a/esphome/components/midea/air_conditioner.h +++ b/esphome/components/midea/air_conditioner.h @@ -32,7 +32,7 @@ class AirConditioner : public ApplianceBase, /* ### 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); } diff --git a/esphome/components/midea/climate.py b/esphome/components/midea/climate.py index e5612796a3..6af42db8f7 100644 --- a/esphome/components/midea/climate.py +++ b/esphome/components/midea/climate.py @@ -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_)) diff --git a/esphome/components/midea/ir_transmitter.h b/esphome/components/midea/ir_transmitter.h index b0a889fa05..30d817a132 100644 --- a/esphome/components/midea/ir_transmitter.h +++ b/esphome/components/midea/ir_transmitter.h @@ -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(val, MIN_TEMP_F, MAX_TEMP_F) - 31; diff --git a/esphome/components/midea_ir/midea_data.h b/esphome/components/midea_ir/midea_data.h index c4685b3b0e..b73898c356 100644 --- a/esphome/components/midea_ir/midea_data.h +++ b/esphome/components/midea_ir/midea_data.h @@ -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(val, MIN_TEMP_F, MAX_TEMP_F) - 31;