Guard writing automation/scene/script config (#31568)

This commit is contained in:
Paulus Schoutsen 2020-02-08 17:26:58 -08:00
parent 992484fbe6
commit 966df6a411

View File

@ -94,6 +94,7 @@ class BaseEditConfigView(HomeAssistantView):
self.data_schema = data_schema
self.post_write_hook = post_write_hook
self.data_validator = data_validator
self.mutation_lock = asyncio.Lock()
def _empty_config(self):
"""Empty config if file not found."""
@ -114,6 +115,7 @@ class BaseEditConfigView(HomeAssistantView):
async def get(self, request, config_key):
"""Fetch device specific config."""
hass = request.app["hass"]
async with self.mutation_lock:
current = await self.read_config(hass)
value = self._get_value(hass, current, config_key)
@ -148,6 +150,7 @@ class BaseEditConfigView(HomeAssistantView):
path = hass.config.path(self.path)
async with self.mutation_lock:
current = await self.read_config(hass)
self._write_value(hass, current, config_key, data)
@ -163,6 +166,7 @@ class BaseEditConfigView(HomeAssistantView):
async def delete(self, request, config_key):
"""Remove an entry."""
hass = request.app["hass"]
async with self.mutation_lock:
current = await self.read_config(hass)
value = self._get_value(hass, current, config_key)
path = hass.config.path(self.path)