Skip to content

Commit e636745

Browse files
zanixludeeus
andauthored
Update yaml.dump to preserve order and indentation of dashboard files (#20)
Co-authored-by: Joshua Clark <[email protected]> Co-authored-by: ludeeus <[email protected]>
1 parent 3141b1c commit e636745

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

custom_components/readme/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ def read():
126126
return await hass.async_add_executor_job(read)
127127

128128

129+
class IndentDumper(yaml.Dumper):
130+
def increase_indent(self, flow=False, indentless=False):
131+
return super(IndentDumper, self).increase_indent(flow, False)
132+
133+
129134
async def write_file(
130135
hass: HomeAssistant, path: str, content: Any, as_yaml=False
131136
) -> None:
@@ -135,7 +140,12 @@ def write():
135140
with open(hass.config.path(path), "w") as open_file:
136141
if as_yaml:
137142
yaml.dump(
138-
content, open_file, default_flow_style=False, allow_unicode=True
143+
content,
144+
open_file,
145+
default_flow_style=False,
146+
allow_unicode=True,
147+
sort_keys=False,
148+
Dumper=IndentDumper,
139149
)
140150
else:
141151
open_file.write(content)

0 commit comments

Comments
 (0)