mirror of
https://github.com/home-assistant/core
synced 2024-09-06 10:29:55 +02:00
Calling save before load would crash Lovelace storage (#20368)
This commit is contained in:
parent
af3afb673a
commit
5580bec1d3
@ -101,6 +101,8 @@ class LovelaceStorage:
|
||||
|
||||
async def async_save(self, config):
|
||||
"""Save config."""
|
||||
if self._data is None:
|
||||
self._data = {'config': None}
|
||||
self._data['config'] = config
|
||||
await self._store.async_save(self._data)
|
||||
|
||||
|
@ -50,6 +50,27 @@ async def test_lovelace_from_storage(hass, hass_ws_client, hass_storage):
|
||||
}
|
||||
|
||||
|
||||
async def test_lovelace_from_storage_save_before_load(hass, hass_ws_client,
|
||||
hass_storage):
|
||||
"""Test we can load lovelace config from storage."""
|
||||
assert await async_setup_component(hass, 'lovelace', {})
|
||||
client = await hass_ws_client(hass)
|
||||
|
||||
# Store new config
|
||||
await client.send_json({
|
||||
'id': 6,
|
||||
'type': 'lovelace/config/save',
|
||||
'config': {
|
||||
'yo': 'hello'
|
||||
}
|
||||
})
|
||||
response = await client.receive_json()
|
||||
assert response['success']
|
||||
assert hass_storage[lovelace.STORAGE_KEY]['data'] == {
|
||||
'config': {'yo': 'hello'}
|
||||
}
|
||||
|
||||
|
||||
async def test_lovelace_from_yaml(hass, hass_ws_client):
|
||||
"""Test we load lovelace config from yaml."""
|
||||
assert await async_setup_component(hass, 'lovelace', {
|
||||
|
Loading…
Reference in New Issue
Block a user