mirror of
https://github.com/esphome/esphome.git
synced 2025-11-15 06:15:47 +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));
|
return this->set_fan_mode(static_cast<ClimateFanMode>(mode_entry.value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Find the matching pointer from traits
|
// Find the matching pointer from parent climate device
|
||||||
auto traits = this->parent_->get_traits();
|
if (const char *mode_ptr = this->parent_->find_custom_fan_mode_(custom_fan_mode)) {
|
||||||
if (const char *mode_ptr = traits.find_custom_fan_mode(custom_fan_mode)) {
|
|
||||||
this->custom_fan_mode_ = mode_ptr;
|
this->custom_fan_mode_ = mode_ptr;
|
||||||
this->fan_mode_.reset();
|
this->fan_mode_.reset();
|
||||||
return *this;
|
return *this;
|
||||||
@@ -228,9 +227,8 @@ ClimateCall &ClimateCall::set_preset(const char *custom_preset) {
|
|||||||
return this->set_preset(static_cast<ClimatePreset>(preset_entry.value));
|
return this->set_preset(static_cast<ClimatePreset>(preset_entry.value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Find the matching pointer from traits
|
// Find the matching pointer from parent climate device
|
||||||
auto traits = this->parent_->get_traits();
|
if (const char *preset_ptr = this->parent_->find_custom_preset_(custom_preset)) {
|
||||||
if (const char *preset_ptr = traits.find_custom_preset(custom_preset)) {
|
|
||||||
this->custom_preset_ = preset_ptr;
|
this->custom_preset_ = preset_ptr;
|
||||||
this->preset_.reset();
|
this->preset_.reset();
|
||||||
return *this;
|
return *this;
|
||||||
@@ -622,34 +620,34 @@ bool Climate::set_fan_mode_(ClimateFanMode mode) {
|
|||||||
return set_alternative(this->fan_mode, this->custom_fan_mode, 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();
|
auto traits = this->get_traits();
|
||||||
const char *mode_ptr = traits.find_custom_fan_mode(mode.c_str());
|
const char *mode_ptr = traits.find_custom_fan_mode_(mode);
|
||||||
if (mode_ptr != nullptr) {
|
return mode_ptr != nullptr ? set_alternative(this->custom_fan_mode, this->fan_mode, mode_ptr)
|
||||||
return set_alternative(this->custom_fan_mode, this->fan_mode, mode_ptr);
|
: (this->custom_fan_mode != nullptr ? (this->custom_fan_mode = nullptr, true) : false);
|
||||||
}
|
|
||||||
// Mode not found in supported custom modes, clear it
|
|
||||||
if (this->custom_fan_mode != nullptr) {
|
|
||||||
this->custom_fan_mode = nullptr;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return 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_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();
|
auto traits = this->get_traits();
|
||||||
const char *preset_ptr = traits.find_custom_preset(preset.c_str());
|
const char *preset_ptr = traits.find_custom_preset_(preset);
|
||||||
if (preset_ptr != nullptr) {
|
return preset_ptr != nullptr ? set_alternative(this->custom_preset, this->preset, preset_ptr)
|
||||||
return set_alternative(this->custom_preset, this->preset, preset_ptr);
|
: (this->custom_preset != nullptr ? (this->custom_preset = nullptr, true) : false);
|
||||||
}
|
}
|
||||||
// Preset not found in supported custom presets, clear it
|
|
||||||
if (this->custom_preset != nullptr) {
|
bool Climate::set_custom_preset_(const std::string &preset) { return this->set_custom_preset_(preset.c_str()); }
|
||||||
this->custom_preset = nullptr;
|
|
||||||
return true;
|
const char *Climate::find_custom_fan_mode_(const char *custom_fan_mode) {
|
||||||
}
|
auto traits = this->get_traits();
|
||||||
return false;
|
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) {
|
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.
|
/// Set fan mode. Reset custom fan mode. Return true if fan mode has been changed.
|
||||||
bool set_fan_mode_(ClimateFanMode mode);
|
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.
|
/// 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);
|
bool set_custom_fan_mode_(const std::string &mode);
|
||||||
|
|
||||||
/// Set preset. Reset custom preset. Return true if preset has been changed.
|
/// Set preset. Reset custom preset. Return true if preset has been changed.
|
||||||
bool set_preset_(ClimatePreset preset);
|
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.
|
/// Set custom preset. Reset primary preset. Return true if preset has been changed.
|
||||||
bool set_custom_preset_(const std::string &preset);
|
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.
|
/** 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
|
* 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.
|
* - temperature step - the step with which to increase/decrease target temperature.
|
||||||
* This also affects with how many decimal places the temperature is shown
|
* This also affects with how many decimal places the temperature is shown
|
||||||
*/
|
*/
|
||||||
class Climate; // Forward declaration
|
class Climate; // Forward declaration
|
||||||
class ClimateCall; // Forward declaration
|
|
||||||
|
|
||||||
class ClimateTraits {
|
class ClimateTraits {
|
||||||
friend class Climate; // Allow Climate to access protected find methods
|
friend class Climate; // Allow Climate to access protected find methods
|
||||||
friend class ClimateCall; // Allow ClimateCall to access protected find methods
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Get/set feature flags (see ClimateFeatures enum in climate_mode.h)
|
/// 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
|
/// 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
|
/// 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 {
|
const char *find_custom_fan_mode_(const char *custom_fan_mode) const {
|
||||||
return vector_find(this->supported_custom_fan_modes_, custom_fan_mode);
|
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
|
/// 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
|
/// 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 {
|
const char *find_custom_preset_(const char *custom_preset) const {
|
||||||
return vector_find(this->supported_custom_presets_, custom_preset);
|
return vector_find(this->supported_custom_presets_, custom_preset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user