From 4267d29cb50cede2d318bf02327d31c39820ed07 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 3 Mar 2026 08:19:30 -1000 Subject: [PATCH] simplify get_icon_to: single lookup call on non-ESP8266 - Non-ESP8266: just return entity_icon_lookup(idx) directly - ESP8266: short-circuit idx==0 to avoid strncpy_P on non-PROGMEM "" --- esphome/core/entity_base.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/esphome/core/entity_base.cpp b/esphome/core/entity_base.cpp index ae84579f4a..f91e661364 100644 --- a/esphome/core/entity_base.cpp +++ b/esphome/core/entity_base.cpp @@ -75,19 +75,21 @@ std::string EntityBase::get_unit_of_measurement() const { // Entity icon — buffer-based API for PROGMEM safety on ESP8266 const char *EntityBase::get_icon_to([[maybe_unused]] std::span buffer) const { -#ifndef USE_ENTITY_ICON - // No icons configured — skip lookup entirely - return ""; +#ifdef USE_ENTITY_ICON + const uint8_t idx = this->icon_idx_; #else - const char *icon = entity_icon_lookup(this->icon_idx_); + const uint8_t idx = 0; +#endif #ifdef USE_ESP8266 + if (idx == 0) + return ""; + const char *icon = entity_icon_lookup(idx); ESPHOME_strncpy_P(buffer.data(), icon, buffer.size() - 1); buffer[buffer.size() - 1] = '\0'; return buffer.data(); #else - return icon; + return entity_icon_lookup(idx); #endif -#endif // USE_ENTITY_ICON } #ifndef USE_ESP8266