mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Fix saving YAML as JSON with empty array (#19057)
* Fix saving YAML as JSON with empty array * Lint
This commit is contained in:
parent
b71d65015a
commit
b9ed4b7a76
@ -267,6 +267,8 @@ def add_card(fname: str, view_id: str, card_config: str,
|
|||||||
if str(view.get('id', '')) != view_id:
|
if str(view.get('id', '')) != view_id:
|
||||||
continue
|
continue
|
||||||
cards = view.get('cards', [])
|
cards = view.get('cards', [])
|
||||||
|
if not cards and 'cards' in view:
|
||||||
|
del view['cards']
|
||||||
if data_format == FORMAT_YAML:
|
if data_format == FORMAT_YAML:
|
||||||
card_config = yaml.yaml_to_object(card_config)
|
card_config = yaml.yaml_to_object(card_config)
|
||||||
if 'id' not in card_config:
|
if 'id' not in card_config:
|
||||||
@ -275,6 +277,8 @@ def add_card(fname: str, view_id: str, card_config: str,
|
|||||||
cards.append(card_config)
|
cards.append(card_config)
|
||||||
else:
|
else:
|
||||||
cards.insert(position, card_config)
|
cards.insert(position, card_config)
|
||||||
|
if 'cards' not in view:
|
||||||
|
view['cards'] = cards
|
||||||
yaml.save_yaml(fname, config)
|
yaml.save_yaml(fname, config)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -402,6 +406,8 @@ def add_view(fname: str, view_config: str,
|
|||||||
views.append(view_config)
|
views.append(view_config)
|
||||||
else:
|
else:
|
||||||
views.insert(position, view_config)
|
views.insert(position, view_config)
|
||||||
|
if 'views' not in config:
|
||||||
|
config['views'] = views
|
||||||
yaml.save_yaml(fname, config)
|
yaml.save_yaml(fname, config)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user