mirror of
https://github.com/esphome/esphome.git
synced 2026-02-19 16:05:35 -07:00
preen
This commit is contained in:
@@ -12,11 +12,7 @@ void CopyFan::setup() {
|
||||
this->oscillating = source_->oscillating;
|
||||
this->speed = source_->speed;
|
||||
this->direction = source_->direction;
|
||||
const char *preset = source_->get_preset_mode();
|
||||
if (preset != nullptr)
|
||||
this->set_preset_mode_(preset);
|
||||
else
|
||||
this->clear_preset_mode_();
|
||||
this->set_preset_mode_(source_->get_preset_mode());
|
||||
this->publish_state();
|
||||
});
|
||||
|
||||
@@ -24,11 +20,7 @@ void CopyFan::setup() {
|
||||
this->oscillating = source_->oscillating;
|
||||
this->speed = source_->speed;
|
||||
this->direction = source_->direction;
|
||||
const char *preset = source_->get_preset_mode();
|
||||
if (preset != nullptr)
|
||||
this->set_preset_mode_(preset);
|
||||
else
|
||||
this->clear_preset_mode_();
|
||||
this->set_preset_mode_(source_->get_preset_mode());
|
||||
this->publish_state();
|
||||
}
|
||||
|
||||
|
||||
@@ -138,6 +138,14 @@ FanCall Fan::make_call() { return FanCall(*this); }
|
||||
const char *Fan::find_preset_mode_(const char *preset_mode) { return this->get_traits().find_preset_mode(preset_mode); }
|
||||
|
||||
bool Fan::set_preset_mode_(const char *preset_mode) {
|
||||
if (preset_mode == nullptr) {
|
||||
// Treat nullptr as clearing the preset mode
|
||||
if (this->preset_mode_ == nullptr) {
|
||||
return false; // No change
|
||||
}
|
||||
this->clear_preset_mode_();
|
||||
return true;
|
||||
}
|
||||
const char *validated = this->find_preset_mode_(preset_mode);
|
||||
if (validated == nullptr || this->preset_mode_ == validated) {
|
||||
return false; // Preset mode not supported or no change
|
||||
|
||||
Reference in New Issue
Block a user