Config entry options (#18929)
Add support for options flow for config entries
This commit is contained in:
1 parent
caa3b123ae
commit
d9712027e8
5 files changed
+365
-24
No files matched your search
@@ -17,6 +17,10 @@ async def async_setup(hass):
|
||||
hass.http.register_view(
|
||||
ConfigManagerFlowResourceView(hass.config_entries.flow))
|
||||
hass.http.register_view(ConfigManagerAvailableFlowView)
|
||||
hass.http.register_view(
|
||||
OptionManagerFlowIndexView(hass.config_entries.options.flow))
|
||||
hass.http.register_view(
|
||||
OptionManagerFlowResourceView(hass.config_entries.options.flow))
|
||||
return True
|
||||
|
||||
|
||||
@@ -45,8 +49,9 @@ class ConfigManagerEntryIndexView(HomeAssistantView):
|
||||
name = 'api:config:config_entries:entry'
|
||||
|
||||
async def get(self, request):
|
||||
"""List flows in progress."""
|
||||
"""List available config entries."""
|
||||
hass = request.app['hass']
|
||||
|
||||
return self.json([{
|
||||
'entry_id': entry.entry_id,
|
||||
'domain': entry.domain,
|
||||
@@ -54,6 +59,9 @@ class ConfigManagerEntryIndexView(HomeAssistantView):
|
||||
'source': entry.source,
|
||||
'state': entry.state,
|
||||
'connection_class': entry.connection_class,
|
||||
'supports_options': hasattr(
|
||||
config_entries.HANDLERS[entry.domain],
|
||||
'async_get_options_flow'),
|
||||
} for entry in hass.config_entries.async_entries()])
|
||||
|
||||
|
||||
@@ -145,3 +153,48 @@ class ConfigManagerAvailableFlowView(HomeAssistantView):
|
||||
async def get(self, request):
|
||||
"""List available flow handlers."""
|
||||
return self.json(config_entries.FLOWS)
|
||||
|
||||
|
||||
class OptionManagerFlowIndexView(FlowManagerIndexView):
|
||||
"""View to create option flows."""
|
||||
|
||||
url = '/api/config/config_entries/entry/option/flow'
|
||||
name = 'api:config:config_entries:entry:resource:option:flow'
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
async def post(self, request):
|
||||
"""Handle a POST request.
|
||||
|
||||
handler in request is entry_id.
|
||||
"""
|
||||
if not request['hass_user'].is_admin:
|
||||
raise Unauthorized(
|
||||
perm_category=CAT_CONFIG_ENTRIES, permission='edit')
|
||||
|
||||
# pylint: disable=no-value-for-parameter
|
||||
return await super().post(request)
|
||||
|
||||
|
||||
class OptionManagerFlowResourceView(ConfigManagerFlowResourceView):
|
||||
"""View to interact with the option flow manager."""
|
||||
|
||||
url = '/api/config/config_entries/options/flow/{flow_id}'
|
||||
name = 'api:config:config_entries:options:flow:resource'
|
||||
|
||||
async def get(self, request, flow_id):
|
||||
"""Get the current state of a data_entry_flow."""
|
||||
if not request['hass_user'].is_admin:
|
||||
raise Unauthorized(
|
||||
perm_category=CAT_CONFIG_ENTRIES, permission='edit')
|
||||
|
||||
return await super().get(request, flow_id)
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
async def post(self, request, flow_id):
|
||||
"""Handle a POST request."""
|
||||
if not request['hass_user'].is_admin:
|
||||
raise Unauthorized(
|
||||
perm_category=CAT_CONFIG_ENTRIES, permission='edit')
|
||||
|
||||
# pylint: disable=no-value-for-parameter
|
||||
return await super().post(request, flow_id)
|
||||
Reference in new issue
Block a user