mirror of
https://github.com/esphome/esphome.git
synced 2026-09-01 02:26:01 +00:00
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 ""
This commit is contained in:
@@ -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<char, MAX_ICON_LENGTH> 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
|
||||
|
||||
Reference in New Issue
Block a user