This commit is contained in:
J. Nick Koston
2025-10-22 11:44:42 -10:00
parent fdb23a2c13
commit 5c7029623e
2 changed files with 9 additions and 7 deletions

View File

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

View File

@@ -45,7 +45,7 @@ class FanTraits {
/// Set the preset modes supported by the fan.
void set_supported_preset_modes(const FixedVector<std::string> *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