From f11e8e36b5412ea09c3d69d904d4dbd3c6be8f0f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 22 Oct 2025 11:09:10 -1000 Subject: [PATCH] missed --- esphome/components/api/api_connection.cpp | 4 ++-- esphome/components/binary/fan/binary_fan.h | 2 +- esphome/components/copy/fan/copy_fan.h | 2 +- esphome/components/demo/demo_fan.h | 24 ++++++++++++---------- esphome/components/tuya/fan/tuya_fan.h | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 7c135946f8..05a4f9e63e 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -401,7 +401,7 @@ uint16_t APIConnection::try_send_fan_state(EntityBase *entity, APIConnection *co bool is_single) { auto *fan = static_cast(entity); FanStateResponse msg; - auto traits = fan->get_traits(); + const auto &traits = fan->get_traits(); msg.state = fan->state; if (traits.supports_oscillation()) msg.oscillating = fan->oscillating; @@ -418,7 +418,7 @@ uint16_t APIConnection::try_send_fan_info(EntityBase *entity, APIConnection *con bool is_single) { auto *fan = static_cast(entity); ListEntitiesFanResponse msg; - auto traits = fan->get_traits(); + const auto &traits = fan->get_traits(); msg.supports_oscillation = traits.supports_oscillation(); msg.supports_speed = traits.supports_speed(); msg.supports_direction = traits.supports_direction(); diff --git a/esphome/components/binary/fan/binary_fan.h b/esphome/components/binary/fan/binary_fan.h index 16bce2e6af..b87e1c5d9d 100644 --- a/esphome/components/binary/fan/binary_fan.h +++ b/esphome/components/binary/fan/binary_fan.h @@ -16,7 +16,7 @@ class BinaryFan : public Component, public fan::Fan { void set_oscillating(output::BinaryOutput *oscillating) { this->oscillating_ = oscillating; } void set_direction(output::BinaryOutput *direction) { this->direction_ = direction; } - fan::FanTraits get_traits() override; + const fan::FanTraits &get_traits() override; protected: void control(const fan::FanCall &call) override; diff --git a/esphome/components/copy/fan/copy_fan.h b/esphome/components/copy/fan/copy_fan.h index b474975bc4..194827b9f8 100644 --- a/esphome/components/copy/fan/copy_fan.h +++ b/esphome/components/copy/fan/copy_fan.h @@ -12,7 +12,7 @@ class CopyFan : public fan::Fan, public Component { void setup() override; void dump_config() override; - fan::FanTraits get_traits() override; + const fan::FanTraits &get_traits() override; protected: void control(const fan::FanCall &call) override; diff --git a/esphome/components/demo/demo_fan.h b/esphome/components/demo/demo_fan.h index 09edc4e0b7..568e90b826 100644 --- a/esphome/components/demo/demo_fan.h +++ b/esphome/components/demo/demo_fan.h @@ -16,8 +16,9 @@ enum class DemoFanType { class DemoFan : public fan::Fan, public Component { public: void set_type(DemoFanType type) { type_ = type; } - fan::FanTraits get_traits() override { - fan::FanTraits traits{}; + const fan::FanTraits &get_traits() override { + // Note: Demo fan builds traits dynamically, so we store it as a member + this->traits_ = fan::FanTraits{}; // oscillation // speed @@ -27,22 +28,22 @@ class DemoFan : public fan::Fan, public Component { case DemoFanType::TYPE_1: break; case DemoFanType::TYPE_2: - traits.set_oscillation(true); + this->traits_.set_oscillation(true); break; case DemoFanType::TYPE_3: - traits.set_direction(true); - traits.set_speed(true); - traits.set_supported_speed_count(5); + this->traits_.set_direction(true); + this->traits_.set_speed(true); + this->traits_.set_supported_speed_count(5); break; case DemoFanType::TYPE_4: - traits.set_direction(true); - traits.set_speed(true); - traits.set_supported_speed_count(100); - traits.set_oscillation(true); + this->traits_.set_direction(true); + this->traits_.set_speed(true); + this->traits_.set_supported_speed_count(100); + this->traits_.set_oscillation(true); break; } - return traits; + return this->traits_; } protected: @@ -60,6 +61,7 @@ class DemoFan : public fan::Fan, public Component { } DemoFanType type_; + fan::FanTraits traits_; }; } // namespace demo diff --git a/esphome/components/tuya/fan/tuya_fan.h b/esphome/components/tuya/fan/tuya_fan.h index 527efa8246..100579ea9f 100644 --- a/esphome/components/tuya/fan/tuya_fan.h +++ b/esphome/components/tuya/fan/tuya_fan.h @@ -17,7 +17,7 @@ class TuyaFan : public Component, public fan::Fan { void set_oscillation_id(uint8_t oscillation_id) { this->oscillation_id_ = oscillation_id; } void set_direction_id(uint8_t direction_id) { this->direction_id_ = direction_id; } - fan::FanTraits get_traits() override; + const fan::FanTraits &get_traits() override; protected: void control(const fan::FanCall &call) override;