mirror of
https://github.com/esphome/esphome.git
synced 2025-11-14 13:55:45 +00:00
simplify
This commit is contained in:
@@ -699,11 +699,11 @@ void APIConnection::climate_command(const ClimateCommandRequest &msg) {
|
|||||||
if (msg.has_fan_mode)
|
if (msg.has_fan_mode)
|
||||||
call.set_fan_mode(static_cast<climate::ClimateFanMode>(msg.fan_mode));
|
call.set_fan_mode(static_cast<climate::ClimateFanMode>(msg.fan_mode));
|
||||||
if (msg.has_custom_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)
|
if (msg.has_preset)
|
||||||
call.set_preset(static_cast<climate::ClimatePreset>(msg.preset));
|
call.set_preset(static_cast<climate::ClimatePreset>(msg.preset));
|
||||||
if (msg.has_custom_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)
|
if (msg.has_swing_mode)
|
||||||
call.set_swing_mode(static_cast<climate::ClimateSwingMode>(msg.swing_mode));
|
call.set_swing_mode(static_cast<climate::ClimateSwingMode>(msg.swing_mode));
|
||||||
call.perform();
|
call.perform();
|
||||||
|
|||||||
@@ -232,13 +232,12 @@ ClimateCall &ClimateCall::set_preset(const char *custom_preset) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Find the matching pointer from traits
|
// Find the matching pointer from traits
|
||||||
const auto &supported = this->parent_->get_traits().get_supported_custom_presets();
|
auto traits = this->parent_->get_traits();
|
||||||
for (const char *preset : supported) {
|
const char *preset_ptr = traits.find_custom_preset(custom_preset);
|
||||||
if (strcmp(preset, custom_preset) == 0) {
|
if (preset_ptr != nullptr) {
|
||||||
this->custom_preset_ = preset;
|
this->custom_preset_ = preset_ptr;
|
||||||
this->preset_.reset();
|
this->preset_.reset();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ESP_LOGW(TAG, "'%s' - Unrecognized preset %s", this->parent_->get_name().c_str(), custom_preset);
|
ESP_LOGW(TAG, "'%s' - Unrecognized preset %s", this->parent_->get_name().c_str(), custom_preset);
|
||||||
return *this;
|
return *this;
|
||||||
|
|||||||
Reference in New Issue
Block a user