Skip to content

Commit

Permalink
Update yaml.dump to preserve order and indentation of dashboard files (
Browse files Browse the repository at this point in the history
…#20)

Co-authored-by: Joshua Clark <[email protected]>
Co-authored-by: ludeeus <[email protected]>
  • Loading branch information
3 people authored Jul 23, 2024
1 parent 3141b1c commit e636745
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion custom_components/readme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ def read():
return await hass.async_add_executor_job(read)


class IndentDumper(yaml.Dumper):
def increase_indent(self, flow=False, indentless=False):
return super(IndentDumper, self).increase_indent(flow, False)


async def write_file(
hass: HomeAssistant, path: str, content: Any, as_yaml=False
) -> None:
Expand All @@ -135,7 +140,12 @@ def write():
with open(hass.config.path(path), "w") as open_file:
if as_yaml:
yaml.dump(
content, open_file, default_flow_style=False, allow_unicode=True
content,
open_file,
default_flow_style=False,
allow_unicode=True,
sort_keys=False,
Dumper=IndentDumper,
)
else:
open_file.write(content)
Expand Down

0 comments on commit e636745

Please sign in to comment.