mirror of
https://github.com/esphome/esphome.git
synced 2025-11-03 08:31:47 +00:00
simplify
This commit is contained in:
@@ -197,13 +197,12 @@ ClimateCall &ClimateCall::set_fan_mode(const char *custom_fan_mode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Find the matching pointer from traits
|
// Find the matching pointer from traits
|
||||||
const auto &supported = this->parent_->get_traits().get_supported_custom_fan_modes();
|
auto traits = this->parent_->get_traits();
|
||||||
for (const char *mode : supported) {
|
const char *mode_ptr = traits.find_custom_fan_mode(custom_fan_mode);
|
||||||
if (strcmp(mode, custom_fan_mode) == 0) {
|
if (mode_ptr != nullptr) {
|
||||||
this->custom_fan_mode_ = mode;
|
this->custom_fan_mode_ = mode_ptr;
|
||||||
this->fan_mode_.reset();
|
this->fan_mode_.reset();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ESP_LOGW(TAG, "'%s' - Unrecognized fan mode %s", this->parent_->get_name().c_str(), custom_fan_mode);
|
ESP_LOGW(TAG, "'%s' - Unrecognized fan mode %s", this->parent_->get_name().c_str(), custom_fan_mode);
|
||||||
return *this;
|
return *this;
|
||||||
|
|||||||
@@ -151,6 +151,14 @@ class ClimateTraits {
|
|||||||
bool supports_custom_fan_mode(const std::string &custom_fan_mode) const {
|
bool supports_custom_fan_mode(const std::string &custom_fan_mode) const {
|
||||||
return this->supports_custom_fan_mode(custom_fan_mode.c_str());
|
return this->supports_custom_fan_mode(custom_fan_mode.c_str());
|
||||||
}
|
}
|
||||||
|
/// Find and return the matching custom fan mode pointer from supported modes, or nullptr if not found
|
||||||
|
const char *find_custom_fan_mode(const char *custom_fan_mode) const {
|
||||||
|
for (const char *mode : this->supported_custom_fan_modes_) {
|
||||||
|
if (strcmp(mode, custom_fan_mode) == 0)
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void set_supported_presets(ClimatePresetMask presets) { this->supported_presets_ = presets; }
|
void set_supported_presets(ClimatePresetMask presets) { this->supported_presets_ = presets; }
|
||||||
void add_supported_preset(ClimatePreset preset) { this->supported_presets_.insert(preset); }
|
void add_supported_preset(ClimatePreset preset) { this->supported_presets_.insert(preset); }
|
||||||
@@ -174,6 +182,14 @@ class ClimateTraits {
|
|||||||
bool supports_custom_preset(const std::string &custom_preset) const {
|
bool supports_custom_preset(const std::string &custom_preset) const {
|
||||||
return this->supports_custom_preset(custom_preset.c_str());
|
return this->supports_custom_preset(custom_preset.c_str());
|
||||||
}
|
}
|
||||||
|
/// Find and return the matching custom preset pointer from supported presets, or nullptr if not found
|
||||||
|
const char *find_custom_preset(const char *custom_preset) const {
|
||||||
|
for (const char *preset : this->supported_custom_presets_) {
|
||||||
|
if (strcmp(preset, custom_preset) == 0)
|
||||||
|
return preset;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void set_supported_swing_modes(ClimateSwingModeMask modes) { this->supported_swing_modes_ = modes; }
|
void set_supported_swing_modes(ClimateSwingModeMask modes) { this->supported_swing_modes_ = modes; }
|
||||||
void add_supported_swing_mode(ClimateSwingMode mode) { this->supported_swing_modes_.insert(mode); }
|
void add_supported_swing_mode(ClimateSwingMode mode) { this->supported_swing_modes_.insert(mode); }
|
||||||
|
|||||||
Reference in New Issue
Block a user