1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-28 16:12:24 +01:00

[climate] Remove STL algorithm overhead in save_state() method (#10888)

This commit is contained in:
J. Nick Koston
2025-09-25 19:19:48 -05:00
committed by GitHub
parent b26776fad4
commit 1560b8b8e2

View File

@@ -367,9 +367,11 @@ void Climate::save_state_() {
state.uses_custom_fan_mode = true; state.uses_custom_fan_mode = true;
const auto &supported = traits.get_supported_custom_fan_modes(); const auto &supported = traits.get_supported_custom_fan_modes();
std::vector<std::string> vec{supported.begin(), supported.end()}; std::vector<std::string> vec{supported.begin(), supported.end()};
auto it = std::find(vec.begin(), vec.end(), custom_fan_mode); for (size_t i = 0; i < vec.size(); i++) {
if (it != vec.end()) { if (vec[i] == custom_fan_mode) {
state.custom_fan_mode = std::distance(vec.begin(), it); state.custom_fan_mode = i;
break;
}
} }
} }
if (traits.get_supports_presets() && preset.has_value()) { if (traits.get_supports_presets() && preset.has_value()) {
@@ -380,10 +382,11 @@ void Climate::save_state_() {
state.uses_custom_preset = true; state.uses_custom_preset = true;
const auto &supported = traits.get_supported_custom_presets(); const auto &supported = traits.get_supported_custom_presets();
std::vector<std::string> vec{supported.begin(), supported.end()}; std::vector<std::string> vec{supported.begin(), supported.end()};
auto it = std::find(vec.begin(), vec.end(), custom_preset); for (size_t i = 0; i < vec.size(); i++) {
// only set custom preset if value exists, otherwise leave it as is if (vec[i] == custom_preset) {
if (it != vec.cend()) { state.custom_preset = i;
state.custom_preset = std::distance(vec.begin(), it); break;
}
} }
} }
if (traits.get_supports_swing_modes()) { if (traits.get_supports_swing_modes()) {