mirror of
https://github.com/esphome/esphome.git
synced 2026-09-24 13:34:07 +00:00
manual copy
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user