From 3552d2916762adf4ef4f5d1cc13c2dd157703903 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 30 Oct 2025 14:30:58 -0500 Subject: [PATCH] preen --- esphome/components/select/select_call.cpp | 21 +++++++++++---------- esphome/components/select/select_call.h | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/esphome/components/select/select_call.cpp b/esphome/components/select/select_call.cpp index ffdadfbc26..ae1e6b2f39 100644 --- a/esphome/components/select/select_call.cpp +++ b/esphome/components/select/select_call.cpp @@ -46,10 +46,10 @@ SelectCall &SelectCall::with_index(size_t index) { return *this; } -optional SelectCall::calculate_target_index_() { +optional SelectCall::calculate_target_index_(const char *name) { const auto &options = this->parent_->traits.get_options(); if (options.empty()) { - ESP_LOGW(TAG, "'%s' - Select has no options", this->parent_->get_name().c_str()); + ESP_LOGW(TAG, "'%s' - Select has no options", name); return {}; } @@ -63,23 +63,23 @@ optional SelectCall::calculate_target_index_() { if (this->operation_ == SELECT_OP_SET || this->operation_ == SELECT_OP_SET_INDEX) { if (!this->index_.has_value()) { - ESP_LOGW(TAG, "'%s' - No option set", this->parent_->get_name().c_str()); + ESP_LOGW(TAG, "'%s' - No option set", name); return {}; } auto idx = this->index_.value(); if (idx >= options.size()) { - ESP_LOGW(TAG, "'%s' - Index value %zu out of bounds", this->parent_->get_name().c_str(), idx); + ESP_LOGW(TAG, "'%s' - Index value %zu out of bounds", name, idx); return {}; } if (this->operation_ == SELECT_OP_SET) { - ESP_LOGD(TAG, "'%s' - Setting", this->parent_->get_name().c_str()); + ESP_LOGD(TAG, "'%s' - Setting", name); } return idx; } // SELECT_OP_NEXT or SELECT_OP_PREVIOUS - ESP_LOGD(TAG, "'%s' - Selecting %s, with%s cycling", this->parent_->get_name().c_str(), - this->operation_ == SELECT_OP_NEXT ? "next" : "previous", this->cycle_ ? "" : "out"); + ESP_LOGD(TAG, "'%s' - Selecting %s, with%s cycling", name, this->operation_ == SELECT_OP_NEXT ? "next" : "previous", + this->cycle_ ? "" : "out"); const auto size = options.size(); if (!this->parent_->has_state()) { @@ -105,20 +105,21 @@ optional SelectCall::calculate_target_index_() { void SelectCall::perform() { auto *parent = this->parent_; + const auto *name = parent->get_name().c_str(); if (this->operation_ == SELECT_OP_NONE) { - ESP_LOGW(TAG, "'%s' - SelectCall performed without selecting an operation", parent->get_name().c_str()); + ESP_LOGW(TAG, "'%s' - SelectCall performed without selecting an operation", name); return; } - auto target_index = this->calculate_target_index_(); + auto target_index = this->calculate_target_index_(name); if (!target_index.has_value()) { return; } auto idx = target_index.value(); // All operations use indices, call control() by index to avoid string conversion - ESP_LOGD(TAG, "'%s' - Set selected option to: %s", parent->get_name().c_str(), parent->option_at(idx)); + ESP_LOGD(TAG, "'%s' - Set selected option to: %s", name, parent->option_at(idx)); parent->control(idx); } diff --git a/esphome/components/select/select_call.h b/esphome/components/select/select_call.h index dc6bc85014..0b83cb143a 100644 --- a/esphome/components/select/select_call.h +++ b/esphome/components/select/select_call.h @@ -38,7 +38,7 @@ class SelectCall { SelectCall &with_index(size_t index); protected: - __attribute__((always_inline)) inline optional calculate_target_index_(); + __attribute__((always_inline)) inline optional calculate_target_index_(const char *name); Select *const parent_; optional index_;