mirror of
https://github.com/esphome/esphome.git
synced 2025-10-31 23:21:54 +00:00
simplify
This commit is contained in:
@@ -195,9 +195,8 @@ ClimateCall &ClimateCall::set_fan_mode(const char *custom_fan_mode) {
|
||||
return this->set_fan_mode(static_cast<ClimateFanMode>(mode_entry.value));
|
||||
}
|
||||
}
|
||||
// Find the matching pointer from traits
|
||||
auto traits = this->parent_->get_traits();
|
||||
if (const char *mode_ptr = traits.find_custom_fan_mode(custom_fan_mode)) {
|
||||
// Find the matching pointer from parent climate device
|
||||
if (const char *mode_ptr = this->parent_->find_custom_fan_mode_(custom_fan_mode)) {
|
||||
this->custom_fan_mode_ = mode_ptr;
|
||||
this->fan_mode_.reset();
|
||||
return *this;
|
||||
@@ -228,9 +227,8 @@ ClimateCall &ClimateCall::set_preset(const char *custom_preset) {
|
||||
return this->set_preset(static_cast<ClimatePreset>(preset_entry.value));
|
||||
}
|
||||
}
|
||||
// Find the matching pointer from traits
|
||||
auto traits = this->parent_->get_traits();
|
||||
if (const char *preset_ptr = traits.find_custom_preset(custom_preset)) {
|
||||
// Find the matching pointer from parent climate device
|
||||
if (const char *preset_ptr = this->parent_->find_custom_preset_(custom_preset)) {
|
||||
this->custom_preset_ = preset_ptr;
|
||||
this->preset_.reset();
|
||||
return *this;
|
||||
@@ -622,34 +620,34 @@ bool Climate::set_fan_mode_(ClimateFanMode mode) {
|
||||
return set_alternative(this->fan_mode, this->custom_fan_mode, mode);
|
||||
}
|
||||
|
||||
bool Climate::set_custom_fan_mode_(const std::string &mode) {
|
||||
bool Climate::set_custom_fan_mode_(const char *mode) {
|
||||
auto traits = this->get_traits();
|
||||
const char *mode_ptr = traits.find_custom_fan_mode(mode.c_str());
|
||||
if (mode_ptr != nullptr) {
|
||||
return set_alternative(this->custom_fan_mode, this->fan_mode, mode_ptr);
|
||||
}
|
||||
// Mode not found in supported custom modes, clear it
|
||||
if (this->custom_fan_mode != nullptr) {
|
||||
this->custom_fan_mode = nullptr;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
const char *mode_ptr = traits.find_custom_fan_mode_(mode);
|
||||
return mode_ptr != nullptr ? set_alternative(this->custom_fan_mode, this->fan_mode, mode_ptr)
|
||||
: (this->custom_fan_mode != nullptr ? (this->custom_fan_mode = nullptr, true) : false);
|
||||
}
|
||||
|
||||
bool Climate::set_custom_fan_mode_(const std::string &mode) { return this->set_custom_fan_mode_(mode.c_str()); }
|
||||
|
||||
bool Climate::set_preset_(ClimatePreset preset) { return set_alternative(this->preset, this->custom_preset, preset); }
|
||||
|
||||
bool Climate::set_custom_preset_(const std::string &preset) {
|
||||
bool Climate::set_custom_preset_(const char *preset) {
|
||||
auto traits = this->get_traits();
|
||||
const char *preset_ptr = traits.find_custom_preset(preset.c_str());
|
||||
if (preset_ptr != nullptr) {
|
||||
return set_alternative(this->custom_preset, this->preset, preset_ptr);
|
||||
}
|
||||
// Preset not found in supported custom presets, clear it
|
||||
if (this->custom_preset != nullptr) {
|
||||
this->custom_preset = nullptr;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
const char *preset_ptr = traits.find_custom_preset_(preset);
|
||||
return preset_ptr != nullptr ? set_alternative(this->custom_preset, this->preset, preset_ptr)
|
||||
: (this->custom_preset != nullptr ? (this->custom_preset = nullptr, true) : false);
|
||||
}
|
||||
|
||||
bool Climate::set_custom_preset_(const std::string &preset) { return this->set_custom_preset_(preset.c_str()); }
|
||||
|
||||
const char *Climate::find_custom_fan_mode_(const char *custom_fan_mode) {
|
||||
auto traits = this->get_traits();
|
||||
return traits.find_custom_fan_mode_(custom_fan_mode);
|
||||
}
|
||||
|
||||
const char *Climate::find_custom_preset_(const char *custom_preset) {
|
||||
auto traits = this->get_traits();
|
||||
return traits.find_custom_preset_(custom_preset);
|
||||
}
|
||||
|
||||
void Climate::dump_traits_(const char *tag) {
|
||||
|
||||
@@ -263,15 +263,25 @@ class Climate : public EntityBase {
|
||||
/// Set fan mode. Reset custom fan mode. Return true if fan mode has been changed.
|
||||
bool set_fan_mode_(ClimateFanMode mode);
|
||||
|
||||
/// Set custom fan mode. Reset primary fan mode. Return true if fan mode has been changed.
|
||||
bool set_custom_fan_mode_(const char *mode);
|
||||
/// Set custom fan mode. Reset primary fan mode. Return true if fan mode has been changed.
|
||||
bool set_custom_fan_mode_(const std::string &mode);
|
||||
|
||||
/// Set preset. Reset custom preset. Return true if preset has been changed.
|
||||
bool set_preset_(ClimatePreset preset);
|
||||
|
||||
/// Set custom preset. Reset primary preset. Return true if preset has been changed.
|
||||
bool set_custom_preset_(const char *preset);
|
||||
/// Set custom preset. Reset primary preset. Return true if preset has been changed.
|
||||
bool set_custom_preset_(const std::string &preset);
|
||||
|
||||
/// Find and return the matching custom fan mode pointer from traits, or nullptr if not found.
|
||||
const char *find_custom_fan_mode_(const char *custom_fan_mode);
|
||||
|
||||
/// Find and return the matching custom preset pointer from traits, or nullptr if not found.
|
||||
const char *find_custom_preset_(const char *custom_preset);
|
||||
|
||||
/** Get the default traits of this climate device.
|
||||
*
|
||||
* Traits are static data that encode the capabilities and static data for a climate device such as supported
|
||||
|
||||
@@ -65,12 +65,10 @@ using ClimatePresetMask = FiniteSetMask<ClimatePreset, DefaultBitPolicy<ClimateP
|
||||
* - temperature step - the step with which to increase/decrease target temperature.
|
||||
* This also affects with how many decimal places the temperature is shown
|
||||
*/
|
||||
class Climate; // Forward declaration
|
||||
class ClimateCall; // Forward declaration
|
||||
class Climate; // Forward declaration
|
||||
|
||||
class ClimateTraits {
|
||||
friend class Climate; // Allow Climate to access protected find methods
|
||||
friend class ClimateCall; // Allow ClimateCall to access protected find methods
|
||||
friend class Climate; // Allow Climate to access protected find methods
|
||||
|
||||
public:
|
||||
/// Get/set feature flags (see ClimateFeatures enum in climate_mode.h)
|
||||
@@ -248,14 +246,14 @@ class ClimateTraits {
|
||||
}
|
||||
|
||||
/// Find and return the matching custom fan mode pointer from supported modes, or nullptr if not found
|
||||
/// This is protected as it's an implementation detail - use Climate::set_custom_fan_mode_() instead
|
||||
const char *find_custom_fan_mode(const char *custom_fan_mode) const {
|
||||
/// This is protected as it's an implementation detail - use Climate::find_custom_fan_mode_() instead
|
||||
const char *find_custom_fan_mode_(const char *custom_fan_mode) const {
|
||||
return vector_find(this->supported_custom_fan_modes_, custom_fan_mode);
|
||||
}
|
||||
|
||||
/// Find and return the matching custom preset pointer from supported presets, or nullptr if not found
|
||||
/// This is protected as it's an implementation detail - use Climate::set_custom_preset_() instead
|
||||
const char *find_custom_preset(const char *custom_preset) const {
|
||||
/// This is protected as it's an implementation detail - use Climate::find_custom_preset_() instead
|
||||
const char *find_custom_preset_(const char *custom_preset) const {
|
||||
return vector_find(this->supported_custom_presets_, custom_preset);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user