mirror of
https://github.com/esphome/esphome.git
synced 2025-10-31 23:21:54 +00:00
simplify
This commit is contained in:
@@ -699,11 +699,11 @@ void APIConnection::climate_command(const ClimateCommandRequest &msg) {
|
||||
if (msg.has_fan_mode)
|
||||
call.set_fan_mode(static_cast<climate::ClimateFanMode>(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<climate::ClimatePreset>(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<climate::ClimateSwingMode>(msg.swing_mode));
|
||||
call.perform();
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user