manual copy

This commit is contained in:
J. Nick Koston
2025-10-22 12:24:47 -10:00
parent 516889f35e
commit 6d1ee10742
2 changed files with 13 additions and 1 deletions
+11 -1
View File
@@ -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;
}
+2
View File
@@ -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<std::string> preset_modes_{};
};
} // namespace copy