diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 382c4acc16..8730828994 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -699,11 +699,11 @@ void APIConnection::climate_command(const ClimateCommandRequest &msg) { if (msg.has_fan_mode) call.set_fan_mode(static_cast(msg.fan_mode)); if (msg.has_custom_fan_mode) - call.set_fan_mode(msg.custom_fan_mode); + call.set_fan_mode(msg.custom_fan_mode.c_str()); if (msg.has_preset) call.set_preset(static_cast(msg.preset)); if (msg.has_custom_preset) - call.set_preset(msg.custom_preset); + call.set_preset(msg.custom_preset.c_str()); if (msg.has_swing_mode) call.set_swing_mode(static_cast(msg.swing_mode)); call.perform(); diff --git a/esphome/components/climate/climate.cpp b/esphome/components/climate/climate.cpp index dc83189692..ff97265d9e 100644 --- a/esphome/components/climate/climate.cpp +++ b/esphome/components/climate/climate.cpp @@ -232,13 +232,12 @@ ClimateCall &ClimateCall::set_preset(const char *custom_preset) { } } // Find the matching pointer from traits - const auto &supported = this->parent_->get_traits().get_supported_custom_presets(); - for (const char *preset : supported) { - if (strcmp(preset, custom_preset) == 0) { - this->custom_preset_ = preset; - this->preset_.reset(); - return *this; - } + auto traits = this->parent_->get_traits(); + const char *preset_ptr = traits.find_custom_preset(custom_preset); + if (preset_ptr != nullptr) { + this->custom_preset_ = preset_ptr; + this->preset_.reset(); + return *this; } ESP_LOGW(TAG, "'%s' - Unrecognized preset %s", this->parent_->get_name().c_str(), custom_preset); return *this;