mirror of
https://github.com/esphome/esphome.git
synced 2025-09-24 06:02:21 +01:00
cleanup
This commit is contained in:
@@ -14,7 +14,7 @@ from esphome.core.entity_helpers import get_base_entity_object_id, setup_entity
|
|||||||
from esphome.cpp_generator import MockObj
|
from esphome.cpp_generator import MockObj
|
||||||
from esphome.helpers import sanitize, snake_case
|
from esphome.helpers import sanitize, snake_case
|
||||||
|
|
||||||
from .common import load_config_from_yaml
|
from .common import load_config_from_fixture
|
||||||
|
|
||||||
# Pre-compiled regex pattern for extracting object IDs from expressions
|
# Pre-compiled regex pattern for extracting object IDs from expressions
|
||||||
OBJECT_ID_PATTERN = re.compile(r'\.set_object_id\(["\'](.*?)["\']\)')
|
OBJECT_ID_PATTERN = re.compile(r'\.set_object_id\(["\'](.*?)["\']\)')
|
||||||
@@ -559,22 +559,7 @@ def test_duplicate_entity_yaml_validation(
|
|||||||
yaml_file: Callable[[str], str], capsys: pytest.CaptureFixture[str]
|
yaml_file: Callable[[str], str], capsys: pytest.CaptureFixture[str]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that duplicate entity names are caught during YAML config validation."""
|
"""Test that duplicate entity names are caught during YAML config validation."""
|
||||||
yaml_content = """
|
result = load_config_from_fixture(yaml_file, "duplicate_entity.yaml", FIXTURES_DIR)
|
||||||
esphome:
|
|
||||||
name: test-duplicate
|
|
||||||
|
|
||||||
esp32:
|
|
||||||
board: esp32dev
|
|
||||||
|
|
||||||
sensor:
|
|
||||||
- platform: template
|
|
||||||
name: "Temperature"
|
|
||||||
lambda: return 21.0;
|
|
||||||
- platform: template
|
|
||||||
name: "Temperature" # Duplicate - should fail
|
|
||||||
lambda: return 22.0;
|
|
||||||
"""
|
|
||||||
result = load_config_from_yaml(yaml_file, yaml_content)
|
|
||||||
assert result is None
|
assert result is None
|
||||||
|
|
||||||
# Check for the duplicate entity error message
|
# Check for the duplicate entity error message
|
||||||
@@ -586,35 +571,9 @@ def test_duplicate_entity_with_devices_yaml_validation(
|
|||||||
yaml_file: Callable[[str], str], capsys: pytest.CaptureFixture[str]
|
yaml_file: Callable[[str], str], capsys: pytest.CaptureFixture[str]
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test duplicate entity validation with devices."""
|
"""Test duplicate entity validation with devices."""
|
||||||
yaml_content = """
|
result = load_config_from_fixture(
|
||||||
esphome:
|
yaml_file, "duplicate_entity_with_devices.yaml", FIXTURES_DIR
|
||||||
name: test-duplicate-devices
|
)
|
||||||
devices:
|
|
||||||
- id: device1
|
|
||||||
name: "Device 1"
|
|
||||||
- id: device2
|
|
||||||
name: "Device 2"
|
|
||||||
|
|
||||||
esp32:
|
|
||||||
board: esp32dev
|
|
||||||
|
|
||||||
sensor:
|
|
||||||
# Same name on different devices - should pass
|
|
||||||
- platform: template
|
|
||||||
device_id: device1
|
|
||||||
name: "Temperature"
|
|
||||||
lambda: return 21.0;
|
|
||||||
- platform: template
|
|
||||||
device_id: device2
|
|
||||||
name: "Temperature"
|
|
||||||
lambda: return 22.0;
|
|
||||||
# Duplicate on same device - should fail
|
|
||||||
- platform: template
|
|
||||||
device_id: device1
|
|
||||||
name: "Temperature"
|
|
||||||
lambda: return 23.0;
|
|
||||||
"""
|
|
||||||
result = load_config_from_yaml(yaml_file, yaml_content)
|
|
||||||
assert result is None
|
assert result is None
|
||||||
|
|
||||||
# Check for the duplicate entity error message with device
|
# Check for the duplicate entity error message with device
|
||||||
@@ -629,28 +588,8 @@ def test_entity_different_platforms_yaml_validation(
|
|||||||
yaml_file: Callable[[str], str],
|
yaml_file: Callable[[str], str],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that same entity name on different platforms is allowed."""
|
"""Test that same entity name on different platforms is allowed."""
|
||||||
yaml_content = """
|
result = load_config_from_fixture(
|
||||||
esphome:
|
yaml_file, "entity_different_platforms.yaml", FIXTURES_DIR
|
||||||
name: test-different-platforms
|
)
|
||||||
|
|
||||||
esp32:
|
|
||||||
board: esp32dev
|
|
||||||
|
|
||||||
sensor:
|
|
||||||
- platform: template
|
|
||||||
name: "Status"
|
|
||||||
lambda: return 1.0;
|
|
||||||
|
|
||||||
binary_sensor:
|
|
||||||
- platform: template
|
|
||||||
name: "Status" # Same name, different platform - should pass
|
|
||||||
lambda: return true;
|
|
||||||
|
|
||||||
text_sensor:
|
|
||||||
- platform: template
|
|
||||||
name: "Status" # Same name, different platform - should pass
|
|
||||||
lambda: return {"OK"};
|
|
||||||
"""
|
|
||||||
result = load_config_from_yaml(yaml_file, yaml_content)
|
|
||||||
# This should succeed
|
# This should succeed
|
||||||
assert result is not None
|
assert result is not None
|
||||||
|
Reference in New Issue
Block a user