From 236d1ea88f00b22be505aa1f5351b4a92de2ab33 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 26 Mar 2026 12:56:30 -1000 Subject: [PATCH] Fix: use inline function for empty vector to avoid EMPTY macro clash and static local overhead --- esphome/components/climate/climate_traits.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/esphome/components/climate/climate_traits.h b/esphome/components/climate/climate_traits.h index 1b80846729..5ec7b87cd6 100644 --- a/esphome/components/climate/climate_traits.h +++ b/esphome/components/climate/climate_traits.h @@ -41,6 +41,12 @@ inline const char *vector_find(const std::vector &vec, const char return nullptr; } +/// Shared empty vector for returning const references when no custom modes are set. +inline const std::vector &get_empty_custom_modes() { + static const std::vector INSTANCE; + return INSTANCE; +} + /** This class contains all static data for climate devices. * * All climate devices must support these features: @@ -157,8 +163,7 @@ class ClimateTraits { } const std::vector &get_supported_custom_fan_modes() const { - static const std::vector EMPTY; - return this->supported_custom_fan_modes_ ? *this->supported_custom_fan_modes_ : EMPTY; + return this->supported_custom_fan_modes_ ? *this->supported_custom_fan_modes_ : get_empty_custom_modes(); } bool supports_custom_fan_mode(const char *custom_fan_mode) const { return this->supported_custom_fan_modes_ && vector_contains(*this->supported_custom_fan_modes_, custom_fan_mode); @@ -178,8 +183,7 @@ class ClimateTraits { } const std::vector &get_supported_custom_presets() const { - static const std::vector EMPTY; - return this->supported_custom_presets_ ? *this->supported_custom_presets_ : EMPTY; + return this->supported_custom_presets_ ? *this->supported_custom_presets_ : get_empty_custom_modes(); } bool supports_custom_preset(const char *custom_preset) const { return this->supported_custom_presets_ && vector_contains(*this->supported_custom_presets_, custom_preset);