Add api to reload config entries (#39068)
This commit is contained in:
1 parent
11f121b008
commit
e109b04efe
4 files changed
+129
-8
No files matched your search
@@ -7,7 +7,7 @@ from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant.auth.permissions.const import CAT_CONFIG_ENTRIES, POLICY_EDIT
|
||||
from homeassistant.components import websocket_api
|
||||
from homeassistant.components.http import HomeAssistantView
|
||||
from homeassistant.const import HTTP_NOT_FOUND
|
||||
from homeassistant.const import HTTP_FORBIDDEN, HTTP_NOT_FOUND
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import Unauthorized
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
@@ -22,6 +22,7 @@ async def async_setup(hass):
|
||||
"""Enable the Home Assistant views."""
|
||||
hass.http.register_view(ConfigManagerEntryIndexView)
|
||||
hass.http.register_view(ConfigManagerEntryResourceView)
|
||||
hass.http.register_view(ConfigManagerEntryResourceReloadView)
|
||||
hass.http.register_view(ConfigManagerFlowIndexView(hass.config_entries.flow))
|
||||
hass.http.register_view(ConfigManagerFlowResourceView(hass.config_entries.flow))
|
||||
hass.http.register_view(ConfigManagerAvailableFlowView)
|
||||
@@ -92,6 +93,29 @@ class ConfigManagerEntryResourceView(HomeAssistantView):
|
||||
return self.json(result)
|
||||
|
||||
|
||||
class ConfigManagerEntryResourceReloadView(HomeAssistantView):
|
||||
"""View to reload a config entry."""
|
||||
|
||||
url = "/api/config/config_entries/entry/{entry_id}/reload"
|
||||
name = "api:config:config_entries:entry:resource:reload"
|
||||
|
||||
async def post(self, request, entry_id):
|
||||
"""Reload a config entry."""
|
||||
if not request["hass_user"].is_admin:
|
||||
raise Unauthorized(config_entry_id=entry_id, permission="remove")
|
||||
|
||||
hass = request.app["hass"]
|
||||
|
||||
try:
|
||||
result = await hass.config_entries.async_reload(entry_id)
|
||||
except config_entries.OperationNotAllowed:
|
||||
return self.json_message("Entry cannot be reloaded", HTTP_FORBIDDEN)
|
||||
except config_entries.UnknownEntry:
|
||||
return self.json_message("Invalid entry specified", HTTP_NOT_FOUND)
|
||||
|
||||
return self.json({"require_restart": not result})
|
||||
|
||||
|
||||
class ConfigManagerFlowIndexView(FlowManagerIndexView):
|
||||
"""View to create config flows."""
|
||||
|
||||
@@ -345,4 +369,5 @@ def entry_json(entry: config_entries.ConfigEntry) -> dict:
|
||||
"state": entry.state,
|
||||
"connection_class": entry.connection_class,
|
||||
"supports_options": supports_options,
|
||||
"supports_unload": entry.supports_unload,
|
||||
}
|
||||
Reference in new issue
Block a user