Merge branch 'icon_opt_pay_as_you_go' into integration

This commit is contained in:
J. Nick Koston 2025-07-05 17:38:13 -05:00
commit 0eecc29039
No known key found for this signature in database
4 changed files with 17 additions and 1 deletions

View File

@ -33,6 +33,7 @@
#define USE_DEEP_SLEEP
#define USE_DEVICES
#define USE_DISPLAY
#define USE_ENTITY_ICON
#define USE_ESP32_IMPROV_STATE_CALLBACK
#define USE_EVENT
#define USE_FAN

View File

@ -27,12 +27,22 @@ void EntityBase::set_name(const char *name) {
// Entity Icon
std::string EntityBase::get_icon() const {
#ifdef USE_ENTITY_ICON
if (this->icon_c_str_ == nullptr) {
return "";
}
return this->icon_c_str_;
#else
return "";
#endif
}
void EntityBase::set_icon(const char *icon) {
#ifdef USE_ENTITY_ICON
this->icon_c_str_ = icon;
#else
// No-op when USE_ENTITY_ICON is not defined
#endif
}
void EntityBase::set_icon(const char *icon) { this->icon_c_str_ = icon; }
// Entity Object ID
std::string EntityBase::get_object_id() const {

View File

@ -80,7 +80,9 @@ class EntityBase {
StringRef name_;
const char *object_id_c_str_{nullptr};
#ifdef USE_ENTITY_ICON
const char *icon_c_str_{nullptr};
#endif
uint32_t object_id_hash_{};
#ifdef USE_DEVICES
Device *device_{};

View File

@ -1,6 +1,7 @@
from collections.abc import Callable
import logging
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.const import (
CONF_DEVICE_ID,
@ -108,6 +109,8 @@ async def setup_entity(var: MockObj, config: ConfigType, platform: str) -> None:
if CONF_INTERNAL in config:
add(var.set_internal(config[CONF_INTERNAL]))
if CONF_ICON in config:
# Add USE_ENTITY_ICON define when icons are used
cg.add_define("USE_ENTITY_ICON")
add(var.set_icon(config[CONF_ICON]))
if CONF_ENTITY_CATEGORY in config:
add(var.set_entity_category(config[CONF_ENTITY_CATEGORY]))