mirror of
https://github.com/esphome/esphome.git
synced 2026-05-27 11:56:11 +08:00
[api] Add max_data_length proto option and optimize entity name/object_id (#15426)
This commit is contained in:
@@ -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],
|
||||
|
||||
Reference in New Issue
Block a user