[api] Add max_data_length proto option and optimize entity name/object_id (#15426)

This commit is contained in:
J. Nick Koston
2026-04-06 17:31:01 -10:00
committed by GitHub
parent b6ef1a58fb
commit 10b38e1588
10 changed files with 321 additions and 231 deletions
@@ -28,6 +28,7 @@ from esphome.core.entity_helpers import (
get_base_entity_object_id,
register_device_class,
register_icon,
register_unit_of_measurement,
setup_device_class,
setup_entity,
setup_unit_of_measurement,
@@ -925,6 +926,22 @@ def test_register_device_class_max_length() -> None:
assert register_device_class("") == 0
def test_register_unit_of_measurement_max_length() -> None:
"""Test register_unit_of_measurement rejects units exceeding 63 characters."""
# 63 chars should succeed
max_uom = "a" * 63
idx = register_unit_of_measurement(max_uom)
assert idx > 0
# 64 chars should fail
too_long = "a" * 64
with pytest.raises(ValueError, match="Unit of measurement string too long"):
register_unit_of_measurement(too_long)
# Empty string returns 0
assert register_unit_of_measurement("") == 0
@pytest.mark.asyncio
async def test_setup_entity_with_entity_category(
setup_test_environment: list[str],