mirror of
https://github.com/esphome/esphome.git
synced 2026-09-11 23:37:34 +00:00
move ICON_MAX_LENGTH to esphome/core/config.py alongside other max length constants
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user