From b8da3b32656fe8b7620ea68134550b6ac76f43ea Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 7 Jan 2026 20:00:40 -1000 Subject: [PATCH] [web_server] Use centralized length constants for buffer sizing --- esphome/components/web_server/web_server.cpp | 3 ++- esphome/core/entity_base.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/esphome/components/web_server/web_server.cpp b/esphome/components/web_server/web_server.cpp index 8ea1cf98c2..cab177c182 100644 --- a/esphome/components/web_server/web_server.cpp +++ b/esphome/components/web_server/web_server.cpp @@ -499,7 +499,8 @@ static void set_json_id(JsonObject &root, EntityBase *obj, const char *prefix, J // Build id into stack buffer - ArduinoJson copies the string // Format: {prefix}/{device?}/{name} // Buffer sizes use constants from entity_base.h validated in core/config.py - // Note: Device name (USE_DEVICES) uses ESPHOME_FRIENDLY_NAME_MAX_LEN, not ESPHOME_DEVICE_NAME_MAX_LEN + // Note: Device name uses ESPHOME_FRIENDLY_NAME_MAX_LEN (sub-device max 120), not ESPHOME_DEVICE_NAME_MAX_LEN + // (hostname) #ifdef USE_DEVICES static constexpr size_t ID_BUF_SIZE = ESPHOME_DOMAIN_MAX_LEN + 1 + ESPHOME_FRIENDLY_NAME_MAX_LEN + 1 + ESPHOME_FRIENDLY_NAME_MAX_LEN + 1; diff --git a/esphome/core/entity_base.h b/esphome/core/entity_base.h index 4ed6a8024a..dc961c3d84 100644 --- a/esphome/core/entity_base.h +++ b/esphome/core/entity_base.h @@ -16,7 +16,8 @@ namespace esphome { // Maximum device name length - keep in sync with validate_hostname() in esphome/core/config.py static constexpr size_t ESPHOME_DEVICE_NAME_MAX_LEN = 31; -// Maximum friendly name length - keep in sync with friendly_name cv.Length(max=120) in esphome/core/config.py +// Maximum friendly name length for entities and sub-devices - keep in sync with cv.Length(max=120) in +// esphome/core/config.py static constexpr size_t ESPHOME_FRIENDLY_NAME_MAX_LEN = 120; // Maximum domain length (longest: "alarm_control_panel" = 19)