mirror of
https://github.com/esphome/esphome.git
synced 2025-09-11 07:42:26 +01:00
preen
This commit is contained in:
@@ -28,13 +28,6 @@ def yaml_file(tmp_path: Path) -> Callable[[str], str]:
|
|||||||
return _yaml_file
|
return _yaml_file
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
|
||||||
def reset_core():
|
|
||||||
"""Reset CORE after each test."""
|
|
||||||
yield
|
|
||||||
CORE.reset()
|
|
||||||
|
|
||||||
|
|
||||||
def load_config_from_yaml(
|
def load_config_from_yaml(
|
||||||
yaml_file: Callable[[str], str], yaml_content: str
|
yaml_file: Callable[[str], str], yaml_content: str
|
||||||
) -> Config | None:
|
) -> Config | None:
|
||||||
@@ -61,7 +54,7 @@ def load_config_from_fixture(
|
|||||||
|
|
||||||
def test_validate_area_config_with_string() -> None:
|
def test_validate_area_config_with_string() -> None:
|
||||||
"""Test that string area config is converted to structured format."""
|
"""Test that string area config is converted to structured format."""
|
||||||
result: dict[str, Any] = validate_area_config("Living Room")
|
result = validate_area_config("Living Room")
|
||||||
|
|
||||||
assert isinstance(result, dict)
|
assert isinstance(result, dict)
|
||||||
assert "id" in result
|
assert "id" in result
|
||||||
@@ -80,7 +73,7 @@ def test_validate_area_config_with_dict() -> None:
|
|||||||
"name": "Test Area",
|
"name": "Test Area",
|
||||||
}
|
}
|
||||||
|
|
||||||
result: dict[str, Any] = validate_area_config(input_config)
|
result = validate_area_config(input_config)
|
||||||
|
|
||||||
assert result == input_config
|
assert result == input_config
|
||||||
assert result["id"] == area_id
|
assert result["id"] == area_id
|
||||||
|
@@ -13,6 +13,9 @@ from esphome.cpp_generator import MockObj
|
|||||||
from esphome.entity import get_base_entity_object_id, setup_entity
|
from esphome.entity import get_base_entity_object_id, setup_entity
|
||||||
from esphome.helpers import sanitize, snake_case
|
from esphome.helpers import sanitize, snake_case
|
||||||
|
|
||||||
|
# Pre-compiled regex pattern for extracting object IDs from expressions
|
||||||
|
OBJECT_ID_PATTERN = re.compile(r'\.set_object_id\(["\'](.*?)["\']\)')
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def restore_core_state() -> Generator[None, None, None]:
|
def restore_core_state() -> Generator[None, None, None]:
|
||||||
@@ -256,7 +259,7 @@ def extract_object_id_from_expressions(expressions: list[str]) -> str | None:
|
|||||||
for expr in expressions:
|
for expr in expressions:
|
||||||
# Look for set_object_id calls with regex to handle various formats
|
# Look for set_object_id calls with regex to handle various formats
|
||||||
# Matches: var.set_object_id("temperature_2") or var.set_object_id('temperature_2')
|
# Matches: var.set_object_id("temperature_2") or var.set_object_id('temperature_2')
|
||||||
match = re.search(r'\.set_object_id\(["\'](.*?)["\']\)', expr)
|
match = OBJECT_ID_PATTERN.search(expr)
|
||||||
if match:
|
if match:
|
||||||
return match.group(1)
|
return match.group(1)
|
||||||
return None
|
return None
|
||||||
|
Reference in New Issue
Block a user