From 5c7029623e6d728441bf655609ff0394ef7209e1 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 22 Oct 2025 11:44:42 -1000 Subject: [PATCH] fixed --- esphome/components/fan/fan.cpp | 14 ++++++++------ esphome/components/fan/fan_traits.h | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/esphome/components/fan/fan.cpp b/esphome/components/fan/fan.cpp index 26a61de0b1..856152de63 100644 --- a/esphome/components/fan/fan.cpp +++ b/esphome/components/fan/fan.cpp @@ -50,13 +50,15 @@ void FanCall::validate_() { } if (!this->preset_mode_.empty()) { - const auto &preset_modes = traits.supported_preset_modes(); - // Linear search is efficient for small preset mode lists (typically 2-5 items) bool found = false; - for (const auto &mode : preset_modes) { - if (mode == this->preset_mode_) { - found = true; - break; + if (traits.supports_preset_modes()) { + const auto &preset_modes = traits.supported_preset_modes(); + // Linear search is efficient for small preset mode lists (typically 2-5 items) + for (const auto &mode : preset_modes) { + if (mode == this->preset_mode_) { + found = true; + break; + } } } if (!found) { diff --git a/esphome/components/fan/fan_traits.h b/esphome/components/fan/fan_traits.h index 4c10ccd10a..138d39bb65 100644 --- a/esphome/components/fan/fan_traits.h +++ b/esphome/components/fan/fan_traits.h @@ -45,7 +45,7 @@ class FanTraits { /// Set the preset modes supported by the fan. void set_supported_preset_modes(const FixedVector *preset_modes) { this->preset_modes_ = preset_modes; } /// Return if preset modes are supported - bool supports_preset_modes() const { return !this->preset_modes_->empty(); } + bool supports_preset_modes() const { return this->preset_modes_ != nullptr && !this->preset_modes_->empty(); } protected: #ifdef USE_API