mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +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:
|
||||
continue
|
||||
cards = view.get('cards', [])
|
||||
if not cards and 'cards' in view:
|
||||
del view['cards']
|
||||
if data_format == FORMAT_YAML:
|
||||
card_config = yaml.yaml_to_object(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)
|
||||
else:
|
||||
cards.insert(position, card_config)
|
||||
if 'cards' not in view:
|
||||
view['cards'] = cards
|
||||
yaml.save_yaml(fname, config)
|
||||
return
|
||||
|
||||
@ -402,6 +406,8 @@ def add_view(fname: str, view_config: str,
|
||||
views.append(view_config)
|
||||
else:
|
||||
views.insert(position, view_config)
|
||||
if 'views' not in config:
|
||||
config['views'] = views
|
||||
yaml.save_yaml(fname, config)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user