mirror of
https://github.com/esphome/esphome.git
synced 2025-11-04 17:11:51 +00:00
simplify
This commit is contained in:
@@ -110,12 +110,12 @@ class ClimateCall {
|
|||||||
const optional<ClimateFanMode> &get_fan_mode() const;
|
const optional<ClimateFanMode> &get_fan_mode() const;
|
||||||
const optional<ClimateSwingMode> &get_swing_mode() const;
|
const optional<ClimateSwingMode> &get_swing_mode() const;
|
||||||
const optional<ClimatePreset> &get_preset() const;
|
const optional<ClimatePreset> &get_preset() const;
|
||||||
|
/// @deprecated Use get_custom_fan_mode() (returns const char*) instead (since 2025.11.0)
|
||||||
|
optional<std::string> get_custom_fan_mode() const;
|
||||||
|
/// @deprecated Use get_custom_preset() (returns const char*) instead (since 2025.11.0)
|
||||||
|
optional<std::string> get_custom_preset() const;
|
||||||
const char *get_custom_fan_mode() const;
|
const char *get_custom_fan_mode() const;
|
||||||
const char *get_custom_preset() const;
|
const char *get_custom_preset() const;
|
||||||
/// @deprecated Use get_custom_fan_mode() (returns const char*) instead (since 2025.11.0)
|
|
||||||
optional<std::string> get_custom_fan_mode_optional() const;
|
|
||||||
/// @deprecated Use get_custom_preset() (returns const char*) instead (since 2025.11.0)
|
|
||||||
optional<std::string> get_custom_preset_optional() const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void validate_();
|
void validate_();
|
||||||
|
|||||||
@@ -19,6 +19,15 @@ inline bool vector_contains(const std::vector<const char *> &vec, const char *va
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find and return matching pointer from vector, or nullptr if not found
|
||||||
|
inline const char *vector_find(const std::vector<const char *> &vec, const char *value) {
|
||||||
|
for (const char *item : vec) {
|
||||||
|
if (strcmp(item, value) == 0)
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
// Type aliases for climate enum bitmasks
|
// Type aliases for climate enum bitmasks
|
||||||
// These replace std::set<EnumType> to eliminate red-black tree overhead
|
// These replace std::set<EnumType> to eliminate red-black tree overhead
|
||||||
// For contiguous enums starting at 0, DefaultBitPolicy provides 1:1 mapping (enum value = bit position)
|
// For contiguous enums starting at 0, DefaultBitPolicy provides 1:1 mapping (enum value = bit position)
|
||||||
@@ -153,11 +162,7 @@ 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
|
||||||
const char *find_custom_fan_mode(const char *custom_fan_mode) const {
|
const char *find_custom_fan_mode(const char *custom_fan_mode) const {
|
||||||
for (const char *mode : this->supported_custom_fan_modes_) {
|
return vector_find(this->supported_custom_fan_modes_, custom_fan_mode);
|
||||||
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; }
|
||||||
@@ -184,11 +189,7 @@ class ClimateTraits {
|
|||||||
}
|
}
|
||||||
/// 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
|
||||||
const char *find_custom_preset(const char *custom_preset) const {
|
const char *find_custom_preset(const char *custom_preset) const {
|
||||||
for (const char *preset : this->supported_custom_presets_) {
|
return vector_find(this->supported_custom_presets_, custom_preset);
|
||||||
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; }
|
||||||
|
|||||||
Reference in New Issue
Block a user