address bot comments

This commit is contained in:
J. Nick Koston
2026-04-07 16:10:40 -10:00
parent 1d982c47cc
commit 32fcbc8823
2 changed files with 19 additions and 0 deletions
+5
View File
@@ -755,6 +755,11 @@ class ESPHomeDumper(yaml.SafeDumper):
return self.represent_scalar(tag="!remove", value=value.value)
def represent_include_file(self, value):
if value.vars:
mapping = {"file": value.file.as_posix(), "vars": value.vars}
return self.represent_mapping(
tag="!include", mapping=mapping, flow_style=False
)
return self.represent_scalar(tag="!include", value=value.file.as_posix())
def represent_id(self, value):
+14
View File
@@ -516,6 +516,20 @@ def test_represent_include_file() -> None:
assert yaml_util.dump({"key": include}) == "key: !include 'path/to/file.yaml'\n"
def test_represent_include_file_with_vars() -> None:
"""Test that IncludeFile with vars is dumped as !include mapping form."""
include = yaml_util.IncludeFile(
Path("/fake/main.yaml"),
"path/to/file.yaml",
{"key": "value"},
lambda _: {},
)
result = yaml_util.dump({"key": include})
assert "!include" in result
assert "file: path/to/file.yaml" in result
assert "key: value" in result
def test_represent_include_file_with_data_base_mixin() -> None:
"""Test that IncludeFile wrapped with ESPHomeDataBase mixin is also dumped correctly.