Guard writing automation/scene/script config (#31568)
This commit is contained in:
parent
992484fbe6
commit
966df6a411
1 changed files with 16 additions and 12 deletions
|
@ -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,8 +115,9 @@ class BaseEditConfigView(HomeAssistantView):
|
|||
async def get(self, request, config_key):
|
||||
"""Fetch device specific config."""
|
||||
hass = request.app["hass"]
|
||||
current = await self.read_config(hass)
|
||||
value = self._get_value(hass, current, config_key)
|
||||
async with self.mutation_lock:
|
||||
current = await self.read_config(hass)
|
||||
value = self._get_value(hass, current, config_key)
|
||||
|
||||
if value is None:
|
||||
return self.json_message("Resource not found", 404)
|
||||
|
@ -148,10 +150,11 @@ class BaseEditConfigView(HomeAssistantView):
|
|||
|
||||
path = hass.config.path(self.path)
|
||||
|
||||
current = await self.read_config(hass)
|
||||
self._write_value(hass, current, config_key, data)
|
||||
async with self.mutation_lock:
|
||||
current = await self.read_config(hass)
|
||||
self._write_value(hass, current, config_key, data)
|
||||
|
||||
await hass.async_add_executor_job(_write, path, current)
|
||||
await hass.async_add_executor_job(_write, path, current)
|
||||
|
||||
if self.post_write_hook is not None:
|
||||
hass.async_create_task(
|
||||
|
@ -163,15 +166,16 @@ class BaseEditConfigView(HomeAssistantView):
|
|||
async def delete(self, request, config_key):
|
||||
"""Remove an entry."""
|
||||
hass = request.app["hass"]
|
||||
current = await self.read_config(hass)
|
||||
value = self._get_value(hass, current, config_key)
|
||||
path = hass.config.path(self.path)
|
||||
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)
|
||||
|
||||
if value is None:
|
||||
return self.json_message("Resource not found", 404)
|
||||
if value is None:
|
||||
return self.json_message("Resource not found", 404)
|
||||
|
||||
self._delete_value(hass, current, config_key)
|
||||
await hass.async_add_executor_job(_write, path, current)
|
||||
self._delete_value(hass, current, config_key)
|
||||
await hass.async_add_executor_job(_write, path, current)
|
||||
|
||||
if self.post_write_hook is not None:
|
||||
hass.async_create_task(self.post_write_hook(ACTION_DELETE, config_key))
|
||||
|
|
Loading…
Add table
Reference in a new issue