diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 5576f915e2..337b282d70 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -413,7 +413,7 @@ uint16_t APIConnection::try_send_fan_info(EntityBase *entity, APIConnection *con msg.supports_speed = traits.supports_speed(); msg.supports_direction = traits.supports_direction(); msg.supported_speed_count = traits.supported_speed_count(); - msg.supported_preset_modes = &traits.supported_preset_modes(); + msg.supported_preset_modes = &traits.supported_preset_modes_ref(); return fill_and_encode_entity_info(fan, msg, ListEntitiesFanResponse::MESSAGE_TYPE, conn, remaining_size, is_single); } void APIConnection::fan_command(const FanCommandRequest &msg) { @@ -469,7 +469,7 @@ uint16_t APIConnection::try_send_light_info(EntityBase *entity, APIConnection *c auto *light = static_cast(entity); ListEntitiesLightResponse msg; auto traits = light->get_traits(); - msg.supported_color_modes = &traits.get_supported_color_modes(); + msg.supported_color_modes = &traits.get_supported_color_modes_ref(); if (traits.supports_color_capability(light::ColorCapability::COLOR_TEMPERATURE) || traits.supports_color_capability(light::ColorCapability::COLD_WARM_WHITE)) { msg.min_mireds = traits.get_min_mireds(); @@ -655,7 +655,7 @@ uint16_t APIConnection::try_send_climate_info(EntityBase *entity, APIConnection msg.supports_current_humidity = traits.get_supports_current_humidity(); msg.supports_two_point_target_temperature = traits.get_supports_two_point_target_temperature(); msg.supports_target_humidity = traits.get_supports_target_humidity(); - msg.supported_modes = &traits.get_supported_modes(); + msg.supported_modes = &traits.get_supported_modes_ref(); msg.visual_min_temperature = traits.get_visual_min_temperature(); msg.visual_max_temperature = traits.get_visual_max_temperature(); msg.visual_target_temperature_step = traits.get_visual_target_temperature_step(); @@ -663,11 +663,11 @@ uint16_t APIConnection::try_send_climate_info(EntityBase *entity, APIConnection msg.visual_min_humidity = traits.get_visual_min_humidity(); msg.visual_max_humidity = traits.get_visual_max_humidity(); msg.supports_action = traits.get_supports_action(); - msg.supported_fan_modes = &traits.get_supported_fan_modes(); - msg.supported_custom_fan_modes = &traits.get_supported_custom_fan_modes(); - msg.supported_presets = &traits.get_supported_presets(); - msg.supported_custom_presets = &traits.get_supported_custom_presets(); - msg.supported_swing_modes = &traits.get_supported_swing_modes(); + msg.supported_fan_modes = &traits.get_supported_fan_modes_ref(); + msg.supported_custom_fan_modes = &traits.get_supported_custom_fan_modes_ref(); + msg.supported_presets = &traits.get_supported_presets_ref(); + msg.supported_custom_presets = &traits.get_supported_custom_presets_ref(); + msg.supported_swing_modes = &traits.get_supported_swing_modes_ref(); return fill_and_encode_entity_info(climate, msg, ListEntitiesClimateResponse::MESSAGE_TYPE, conn, remaining_size, is_single); } diff --git a/esphome/components/climate/climate_traits.h b/esphome/components/climate/climate_traits.h index c3a0dfca8f..171fd0ab2f 100644 --- a/esphome/components/climate/climate_traits.h +++ b/esphome/components/climate/climate_traits.h @@ -74,6 +74,7 @@ class ClimateTraits { void set_supports_dry_mode(bool supports_dry_mode) { set_mode_support_(CLIMATE_MODE_DRY, supports_dry_mode); } bool supports_mode(ClimateMode mode) const { return this->supported_modes_.count(mode); } const std::set &get_supported_modes() const { return this->supported_modes_; } + const std::set &get_supported_modes_ref() const { return this->supported_modes_; } void set_supports_action(bool supports_action) { this->supports_action_ = supports_action; } bool get_supports_action() const { return this->supports_action_; } @@ -104,11 +105,13 @@ class ClimateTraits { return !this->supported_fan_modes_.empty() || !this->supported_custom_fan_modes_.empty(); } const std::set &get_supported_fan_modes() const { return this->supported_fan_modes_; } + const std::set &get_supported_fan_modes_ref() const { return this->supported_fan_modes_; } void set_supported_custom_fan_modes(std::set supported_custom_fan_modes) { this->supported_custom_fan_modes_ = std::move(supported_custom_fan_modes); } const std::set &get_supported_custom_fan_modes() const { return this->supported_custom_fan_modes_; } + const std::set &get_supported_custom_fan_modes_ref() const { return this->supported_custom_fan_modes_; } bool supports_custom_fan_mode(const std::string &custom_fan_mode) const { return this->supported_custom_fan_modes_.count(custom_fan_mode); } @@ -119,11 +122,13 @@ class ClimateTraits { bool supports_preset(ClimatePreset preset) const { return this->supported_presets_.count(preset); } bool get_supports_presets() const { return !this->supported_presets_.empty(); } const std::set &get_supported_presets() const { return this->supported_presets_; } + const std::set &get_supported_presets_ref() const { return this->supported_presets_; } void set_supported_custom_presets(std::set supported_custom_presets) { this->supported_custom_presets_ = std::move(supported_custom_presets); } const std::set &get_supported_custom_presets() const { return this->supported_custom_presets_; } + const std::set &get_supported_custom_presets_ref() const { return this->supported_custom_presets_; } bool supports_custom_preset(const std::string &custom_preset) const { return this->supported_custom_presets_.count(custom_preset); } @@ -143,6 +148,7 @@ class ClimateTraits { bool supports_swing_mode(ClimateSwingMode swing_mode) const { return this->supported_swing_modes_.count(swing_mode); } bool get_supports_swing_modes() const { return !this->supported_swing_modes_.empty(); } const std::set &get_supported_swing_modes() const { return this->supported_swing_modes_; } + const std::set &get_supported_swing_modes_ref() const { return this->supported_swing_modes_; } float get_visual_min_temperature() const { return this->visual_min_temperature_; } void set_visual_min_temperature(float visual_min_temperature) { diff --git a/esphome/components/fan/fan_traits.h b/esphome/components/fan/fan_traits.h index d3010cb39b..67ba651eb1 100644 --- a/esphome/components/fan/fan_traits.h +++ b/esphome/components/fan/fan_traits.h @@ -29,7 +29,8 @@ class FanTraits { /// Set whether this fan supports changing direction void set_direction(bool direction) { this->direction_ = direction; } /// Return the preset modes supported by the fan. - const std::set &supported_preset_modes() const { return this->preset_modes_; } + std::set supported_preset_modes() const { return this->preset_modes_; } + const std::set &supported_preset_modes_ref() const { return this->preset_modes_; } /// Set the preset modes supported by the fan. void set_supported_preset_modes(const std::set &preset_modes) { this->preset_modes_ = preset_modes; } /// Return if preset modes are supported diff --git a/esphome/components/light/light_traits.h b/esphome/components/light/light_traits.h index 7c99d721f0..6c083a1017 100644 --- a/esphome/components/light/light_traits.h +++ b/esphome/components/light/light_traits.h @@ -13,6 +13,7 @@ class LightTraits { LightTraits() = default; const std::set &get_supported_color_modes() const { return this->supported_color_modes_; } + const std::set &get_supported_color_modes_ref() const { return this->supported_color_modes_; } void set_supported_color_modes(std::set supported_color_modes) { this->supported_color_modes_ = std::move(supported_color_modes); }