revent saving/deleting Lovelace config in safe mode (#32319)

This commit is contained in:
Paulus Schoutsen 2020-02-28 11:12:16 -08:00
parent 430fa24acd
commit c43b7d10d8
2 changed files with 16 additions and 0 deletions

View File

@ -104,6 +104,9 @@ class LovelaceStorage:
async def async_save(self, config): async def async_save(self, config):
"""Save config.""" """Save config."""
if self._hass.config.safe_mode:
raise HomeAssistantError("Deleting not supported in safe mode")
if self._data is None: if self._data is None:
await self._load() await self._load()
self._data["config"] = config self._data["config"] = config
@ -112,6 +115,9 @@ class LovelaceStorage:
async def async_delete(self): async def async_delete(self):
"""Delete config.""" """Delete config."""
if self._hass.config.safe_mode:
raise HomeAssistantError("Deleting not supported in safe mode")
await self.async_save(None) await self.async_save(None)
async def _load(self): async def _load(self):

View File

@ -45,6 +45,16 @@ async def test_lovelace_from_storage(hass, hass_ws_client, hass_storage):
assert not response["success"] assert not response["success"]
assert response["error"]["code"] == "config_not_found" assert response["error"]["code"] == "config_not_found"
await client.send_json(
{"id": 9, "type": "lovelace/config/save", "config": {"yo": "hello"}}
)
response = await client.receive_json()
assert not response["success"]
await client.send_json({"id": 10, "type": "lovelace/config/delete"})
response = await client.receive_json()
assert not response["success"]
async def test_lovelace_from_storage_save_before_load( async def test_lovelace_from_storage_save_before_load(
hass, hass_ws_client, hass_storage hass, hass_ws_client, hass_storage