mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 23:21:54 +00:00 
			
		
		
		
	[climate] Remove STL algorithm overhead in save_state() method
This commit is contained in:
		| @@ -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.value()) { | ||||||
|       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.value()) { | ||||||
|     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()) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user