Tweaks to options flow (#25969)
parent
9b3aa9bbd1
commit
8a1ab8c0b5
|
@ -187,8 +187,8 @@ class ConfigManagerAvailableFlowView(HomeAssistantView):
|
||||||
class OptionManagerFlowIndexView(FlowManagerIndexView):
|
class OptionManagerFlowIndexView(FlowManagerIndexView):
|
||||||
"""View to create option flows."""
|
"""View to create option flows."""
|
||||||
|
|
||||||
url = "/api/config/config_entries/entry/option/flow"
|
url = "/api/config/config_entries/options/flow"
|
||||||
name = "api:config:config_entries:entry:resource:option:flow"
|
name = "api:config:config_entries:option:flow"
|
||||||
|
|
||||||
# pylint: disable=arguments-differ
|
# pylint: disable=arguments-differ
|
||||||
async def post(self, request):
|
async def post(self, request):
|
||||||
|
|
|
@ -658,6 +658,12 @@ class ConfigFlow(data_entry_flow.FlowHandler):
|
||||||
|
|
||||||
CONNECTION_CLASS = CONN_CLASS_UNKNOWN
|
CONNECTION_CLASS = CONN_CLASS_UNKNOWN
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@callback
|
||||||
|
def async_get_options_flow(config_entry):
|
||||||
|
"""Get the options flow for this handler."""
|
||||||
|
raise data_entry_flow.UnknownHandler
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_current_entries(self):
|
def _async_current_entries(self):
|
||||||
"""Return current entries."""
|
"""Return current entries."""
|
||||||
|
@ -691,7 +697,11 @@ class OptionsFlowManager:
|
||||||
entry = self.hass.config_entries.async_get_entry(entry_id)
|
entry = self.hass.config_entries.async_get_entry(entry_id)
|
||||||
if entry is None:
|
if entry is None:
|
||||||
return
|
return
|
||||||
flow = HANDLERS[entry.domain].async_get_options_flow(entry.data, entry.options)
|
|
||||||
|
if entry.domain not in HANDLERS:
|
||||||
|
raise data_entry_flow.UnknownHandler
|
||||||
|
|
||||||
|
flow = HANDLERS[entry.domain].async_get_options_flow(entry)
|
||||||
return flow
|
return flow
|
||||||
|
|
||||||
async def _async_finish_flow(self, flow, result):
|
async def _async_finish_flow(self, flow, result):
|
||||||
|
@ -706,3 +716,9 @@ class OptionsFlowManager:
|
||||||
|
|
||||||
result["result"] = True
|
result["result"] = True
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
class OptionsFlow(data_entry_flow.FlowHandler):
|
||||||
|
"""Base class for config option flows."""
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
|
@ -488,12 +488,8 @@ async def test_options_flow(hass, client):
|
||||||
class TestFlow(core_ce.ConfigFlow):
|
class TestFlow(core_ce.ConfigFlow):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@callback
|
@callback
|
||||||
def async_get_options_flow(config, options):
|
def async_get_options_flow(config_entry):
|
||||||
class OptionsFlowHandler(data_entry_flow.FlowHandler):
|
class OptionsFlowHandler(data_entry_flow.FlowHandler):
|
||||||
def __init__(self, config, options):
|
|
||||||
self.config = config
|
|
||||||
self.options = options
|
|
||||||
|
|
||||||
async def async_step_init(self, user_input=None):
|
async def async_step_init(self, user_input=None):
|
||||||
schema = OrderedDict()
|
schema = OrderedDict()
|
||||||
schema[vol.Required("enabled")] = bool
|
schema[vol.Required("enabled")] = bool
|
||||||
|
@ -503,7 +499,7 @@ async def test_options_flow(hass, client):
|
||||||
description_placeholders={"enabled": "Set to true to be true"},
|
description_placeholders={"enabled": "Set to true to be true"},
|
||||||
)
|
)
|
||||||
|
|
||||||
return OptionsFlowHandler(config, options)
|
return OptionsFlowHandler()
|
||||||
|
|
||||||
MockConfigEntry(
|
MockConfigEntry(
|
||||||
domain="test",
|
domain="test",
|
||||||
|
@ -514,7 +510,7 @@ async def test_options_flow(hass, client):
|
||||||
entry = hass.config_entries._entries[0]
|
entry = hass.config_entries._entries[0]
|
||||||
|
|
||||||
with patch.dict(HANDLERS, {"test": TestFlow}):
|
with patch.dict(HANDLERS, {"test": TestFlow}):
|
||||||
url = "/api/config/config_entries/entry/option/flow"
|
url = "/api/config/config_entries/options/flow"
|
||||||
resp = await client.post(url, json={"handler": entry.entry_id})
|
resp = await client.post(url, json={"handler": entry.entry_id})
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
|
@ -538,12 +534,8 @@ async def test_two_step_options_flow(hass, client):
|
||||||
class TestFlow(core_ce.ConfigFlow):
|
class TestFlow(core_ce.ConfigFlow):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@callback
|
@callback
|
||||||
def async_get_options_flow(config, options):
|
def async_get_options_flow(config_entry):
|
||||||
class OptionsFlowHandler(data_entry_flow.FlowHandler):
|
class OptionsFlowHandler(data_entry_flow.FlowHandler):
|
||||||
def __init__(self, config, options):
|
|
||||||
self.config = config
|
|
||||||
self.options = options
|
|
||||||
|
|
||||||
async def async_step_init(self, user_input=None):
|
async def async_step_init(self, user_input=None):
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="finish", data_schema=vol.Schema({"enabled": bool})
|
step_id="finish", data_schema=vol.Schema({"enabled": bool})
|
||||||
|
@ -554,7 +546,7 @@ async def test_two_step_options_flow(hass, client):
|
||||||
title="Enable disable", data=user_input
|
title="Enable disable", data=user_input
|
||||||
)
|
)
|
||||||
|
|
||||||
return OptionsFlowHandler(config, options)
|
return OptionsFlowHandler()
|
||||||
|
|
||||||
MockConfigEntry(
|
MockConfigEntry(
|
||||||
domain="test",
|
domain="test",
|
||||||
|
@ -565,7 +557,7 @@ async def test_two_step_options_flow(hass, client):
|
||||||
entry = hass.config_entries._entries[0]
|
entry = hass.config_entries._entries[0]
|
||||||
|
|
||||||
with patch.dict(HANDLERS, {"test": TestFlow}):
|
with patch.dict(HANDLERS, {"test": TestFlow}):
|
||||||
url = "/api/config/config_entries/entry/option/flow"
|
url = "/api/config/config_entries/options/flow"
|
||||||
resp = await client.post(url, json={"handler": entry.entry_id})
|
resp = await client.post(url, json={"handler": entry.entry_id})
|
||||||
|
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
|
|
|
@ -666,12 +666,11 @@ async def test_entry_options(hass, manager):
|
||||||
class TestFlow:
|
class TestFlow:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@callback
|
@callback
|
||||||
def async_get_options_flow(config, options):
|
def async_get_options_flow(config_entry):
|
||||||
class OptionsFlowHandler(data_entry_flow.FlowHandler):
|
class OptionsFlowHandler(data_entry_flow.FlowHandler):
|
||||||
def __init__(self, config, options):
|
pass
|
||||||
pass
|
|
||||||
|
|
||||||
return OptionsFlowHandler(config, options)
|
return OptionsFlowHandler()
|
||||||
|
|
||||||
config_entries.HANDLERS["test"] = TestFlow()
|
config_entries.HANDLERS["test"] = TestFlow()
|
||||||
flow = await manager.options._async_create_flow(
|
flow = await manager.options._async_create_flow(
|
||||||
|
|
Loading…
Reference in New Issue