move ICON_MAX_LENGTH to esphome/core/config.py alongside other max length constants

This commit is contained in:
J. Nick Koston
2026-03-03 11:55:26 -10:00
parent afb8ba6813
commit c639accdfd
3 changed files with 9 additions and 7 deletions
+2 -5
View File
@@ -398,13 +398,10 @@ def string_strict(value):
)
# Max icon string length (63 chars + null = 64-byte PROGMEM buffer)
# Keep in sync with MAX_ICON_LENGTH in esphome/core/entity_base.h
ICON_MAX_LENGTH = 63
def icon(value):
"""Validate that a given config value is a valid icon."""
from esphome.core.config import ICON_MAX_LENGTH
value = string_strict(value)
if not value:
return value
+4
View File
@@ -188,6 +188,10 @@ else:
# Keep in sync with ESPHOME_FRIENDLY_NAME_MAX_LEN in esphome/core/entity_base.h
FRIENDLY_NAME_MAX_LEN = 120
# Max icon string length (63 chars + null = 64-byte PROGMEM buffer)
# Keep in sync with MAX_ICON_LENGTH in esphome/core/entity_base.h
ICON_MAX_LENGTH = 63
AREA_SCHEMA = cv.Schema(
{
cv.GenerateID(CONF_ID): cv.declare_id(Area),
+3 -2
View File
@@ -17,6 +17,7 @@ from esphome.const import (
CONF_UNIT_OF_MEASUREMENT,
)
from esphome.core import CORE, ID, CoroPriority, coroutine_with_priority
from esphome.core.config import ICON_MAX_LENGTH
from esphome.cpp_generator import MockObj, RawStatement, add, get_variable
import esphome.final_validate as fv
from esphome.helpers import cpp_string_escape, fnv1_hash_object_id, sanitize, snake_case
@@ -190,9 +191,9 @@ def register_unit_of_measurement(value: str) -> int:
def register_icon(value: str) -> int:
"""Register an icon string and return its 1-based index."""
if value and len(value) > cv.ICON_MAX_LENGTH:
if value and len(value) > ICON_MAX_LENGTH:
raise ValueError(
f"Icon string too long ({len(value)} chars, max {cv.ICON_MAX_LENGTH}): '{value}'"
f"Icon string too long ({len(value)} chars, max {ICON_MAX_LENGTH}): '{value}'"
)
return _register_string(value, _get_pool().icons, _MAX_ICONS, "icon")