mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Guard writing automation/scene/script config (#31568)
This commit is contained in:
parent
992484fbe6
commit
966df6a411
@ -94,6 +94,7 @@ class BaseEditConfigView(HomeAssistantView):
|
|||||||
self.data_schema = data_schema
|
self.data_schema = data_schema
|
||||||
self.post_write_hook = post_write_hook
|
self.post_write_hook = post_write_hook
|
||||||
self.data_validator = data_validator
|
self.data_validator = data_validator
|
||||||
|
self.mutation_lock = asyncio.Lock()
|
||||||
|
|
||||||
def _empty_config(self):
|
def _empty_config(self):
|
||||||
"""Empty config if file not found."""
|
"""Empty config if file not found."""
|
||||||
@ -114,8 +115,9 @@ class BaseEditConfigView(HomeAssistantView):
|
|||||||
async def get(self, request, config_key):
|
async def get(self, request, config_key):
|
||||||
"""Fetch device specific config."""
|
"""Fetch device specific config."""
|
||||||
hass = request.app["hass"]
|
hass = request.app["hass"]
|
||||||
current = await self.read_config(hass)
|
async with self.mutation_lock:
|
||||||
value = self._get_value(hass, current, config_key)
|
current = await self.read_config(hass)
|
||||||
|
value = self._get_value(hass, current, config_key)
|
||||||
|
|
||||||
if value is None:
|
if value is None:
|
||||||
return self.json_message("Resource not found", 404)
|
return self.json_message("Resource not found", 404)
|
||||||
@ -148,10 +150,11 @@ class BaseEditConfigView(HomeAssistantView):
|
|||||||
|
|
||||||
path = hass.config.path(self.path)
|
path = hass.config.path(self.path)
|
||||||
|
|
||||||
current = await self.read_config(hass)
|
async with self.mutation_lock:
|
||||||
self._write_value(hass, current, config_key, data)
|
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:
|
if self.post_write_hook is not None:
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
@ -163,15 +166,16 @@ class BaseEditConfigView(HomeAssistantView):
|
|||||||
async def delete(self, request, config_key):
|
async def delete(self, request, config_key):
|
||||||
"""Remove an entry."""
|
"""Remove an entry."""
|
||||||
hass = request.app["hass"]
|
hass = request.app["hass"]
|
||||||
current = await self.read_config(hass)
|
async with self.mutation_lock:
|
||||||
value = self._get_value(hass, current, config_key)
|
current = await self.read_config(hass)
|
||||||
path = hass.config.path(self.path)
|
value = self._get_value(hass, current, config_key)
|
||||||
|
path = hass.config.path(self.path)
|
||||||
|
|
||||||
if value is None:
|
if value is None:
|
||||||
return self.json_message("Resource not found", 404)
|
return self.json_message("Resource not found", 404)
|
||||||
|
|
||||||
self._delete_value(hass, current, config_key)
|
self._delete_value(hass, current, config_key)
|
||||||
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:
|
if self.post_write_hook is not None:
|
||||||
hass.async_create_task(self.post_write_hook(ACTION_DELETE, config_key))
|
hass.async_create_task(self.post_write_hook(ACTION_DELETE, config_key))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user