move icons to progmem

This commit is contained in:
J. Nick Koston
2026-03-03 08:06:55 -10:00
parent 807e3f9efc
commit 1108511c63
3 changed files with 30 additions and 1 deletions
+1 -1
View File
@@ -349,7 +349,7 @@ class APIConnection final : public APIServerConnectionBase {
// Set common EntityBase properties
#ifdef USE_ENTITY_ICON
char icon_buf[MAX_ICON_LENGTH];
msg.icon = entity->get_icon_to(icon_buf);
msg.icon = StringRef(entity->get_icon_to(icon_buf));
#endif
msg.disabled_by_default = entity->is_disabled_by_default();
msg.entity_category = static_cast<enums::EntityCategory>(entity->get_entity_category());
@@ -23,6 +23,7 @@ from esphome.core.entity_helpers import (
_setup_entity_impl,
entity_duplicate_validator,
get_base_entity_object_id,
register_icon,
setup_entity,
)
from esphome.cpp_generator import MockObj
@@ -909,6 +910,22 @@ def test_register_string_overflow() -> None:
_register_string("overflow", category, 3, "test")
def test_register_icon_max_length() -> None:
"""Test register_icon rejects icons exceeding 63 characters."""
# 63 chars should succeed
max_icon = "mdi:" + "a" * 59 # 63 total
idx = register_icon(max_icon)
assert idx > 0
# 64 chars should fail
too_long = "mdi:" + "a" * 60 # 64 total
with pytest.raises(ValueError, match="Icon string too long"):
register_icon(too_long)
# Empty string returns 0
assert register_icon("") == 0
@pytest.mark.asyncio
async def test_setup_entity_with_entity_category(
setup_test_environment: list[str],
@@ -148,6 +148,18 @@ def test_icon__invalid():
config_validation.icon("foo")
def test_icon__max_length():
"""Test that icons exceeding 63 characters are rejected."""
# Exactly 63 chars should pass
max_icon = "mdi:" + "a" * 59 # 63 chars total
assert config_validation.icon(max_icon) == max_icon
# 64 chars should fail
too_long = "mdi:" + "a" * 60 # 64 chars total
with pytest.raises(Invalid, match="Icon string is too long"):
config_validation.icon(too_long)
@pytest.mark.parametrize("value", ("True", "YES", "on", "enAblE", True))
def test_boolean__valid_true(value):
assert config_validation.boolean(value) is True