This commit is contained in:
J. Nick Koston
2025-10-31 11:18:14 -05:00
parent 91ae8c82b0
commit 76952026b7
2 changed files with 10 additions and 10 deletions

View File

@@ -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();
}

View File

@@ -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