From 6d1ee107426a38206e118a6818d1d937524f9725 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 22 Oct 2025 12:24:47 -1000 Subject: [PATCH] manual copy --- esphome/components/copy/fan/copy_fan.cpp | 12 +++++++++++- esphome/components/copy/fan/copy_fan.h | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/esphome/components/copy/fan/copy_fan.cpp b/esphome/components/copy/fan/copy_fan.cpp index cf5341531a..b939338b24 100644 --- a/esphome/components/copy/fan/copy_fan.cpp +++ b/esphome/components/copy/fan/copy_fan.cpp @@ -35,7 +35,17 @@ fan::FanTraits CopyFan::get_traits() { traits.set_speed(base.supports_speed()); traits.set_supported_speed_count(base.supported_speed_count()); traits.set_direction(base.supports_direction()); - traits.set_supported_preset_modes(&base.supported_preset_modes()); + + // Copy preset modes from source to avoid dangling pointer to temporary + if (base.supports_preset_modes()) { + const auto &source_modes = base.supported_preset_modes(); + this->preset_modes_.clear(); + for (const auto &mode : source_modes) { + this->preset_modes_.push_back(mode); + } + traits.set_supported_preset_modes(&this->preset_modes_); + } + return traits; } diff --git a/esphome/components/copy/fan/copy_fan.h b/esphome/components/copy/fan/copy_fan.h index b474975bc4..78134c6890 100644 --- a/esphome/components/copy/fan/copy_fan.h +++ b/esphome/components/copy/fan/copy_fan.h @@ -1,6 +1,7 @@ #pragma once #include "esphome/core/component.h" +#include "esphome/core/helpers.h" #include "esphome/components/fan/fan.h" namespace esphome { @@ -19,6 +20,7 @@ class CopyFan : public fan::Fan, public Component { ; fan::Fan *source_; + FixedVector preset_modes_{}; }; } // namespace copy