mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Allow options flows to be aborted (#41875)
This commit is contained in:
parent
0f46916f9e
commit
a416a9e046
@ -1075,6 +1075,9 @@ class OptionsFlowManager(data_entry_flow.FlowManager):
|
||||
"""
|
||||
flow = cast(OptionsFlow, flow)
|
||||
|
||||
if result["type"] != data_entry_flow.RESULT_TYPE_CREATE_ENTRY:
|
||||
return result
|
||||
|
||||
entry = self.hass.config_entries.async_get_entry(flow.handler)
|
||||
if entry is None:
|
||||
raise UnknownEntry(flow.handler)
|
||||
|
@ -861,12 +861,45 @@ async def test_entry_options(hass, manager):
|
||||
|
||||
flow.handler = entry.entry_id # Used to keep reference to config entry
|
||||
|
||||
await manager.options.async_finish_flow(flow, {"data": {"second": True}})
|
||||
await manager.options.async_finish_flow(
|
||||
flow,
|
||||
{"data": {"second": True}, "type": data_entry_flow.RESULT_TYPE_CREATE_ENTRY},
|
||||
)
|
||||
|
||||
assert entry.data == {"first": True}
|
||||
assert entry.options == {"second": True}
|
||||
|
||||
|
||||
async def test_entry_options_abort(hass, manager):
|
||||
"""Test that we can abort options flow."""
|
||||
entry = MockConfigEntry(domain="test", data={"first": True}, options=None)
|
||||
entry.add_to_manager(manager)
|
||||
|
||||
class TestFlow:
|
||||
"""Test flow."""
|
||||
|
||||
@staticmethod
|
||||
@callback
|
||||
def async_get_options_flow(config_entry):
|
||||
"""Test options flow."""
|
||||
|
||||
class OptionsFlowHandler(data_entry_flow.FlowHandler):
|
||||
"""Test options flow handler."""
|
||||
|
||||
return OptionsFlowHandler()
|
||||
|
||||
config_entries.HANDLERS["test"] = TestFlow()
|
||||
flow = await manager.options.async_create_flow(
|
||||
entry.entry_id, context={"source": "test"}, data=None
|
||||
)
|
||||
|
||||
flow.handler = entry.entry_id # Used to keep reference to config entry
|
||||
|
||||
assert await manager.options.async_finish_flow(
|
||||
flow, {"type": data_entry_flow.RESULT_TYPE_ABORT, "reason": "test"}
|
||||
)
|
||||
|
||||
|
||||
async def test_entry_setup_succeed(hass, manager):
|
||||
"""Test that we can setup an entry."""
|
||||
entry = MockConfigEntry(domain="comp", state=config_entries.ENTRY_STATE_NOT_LOADED)
|
||||
|
Loading…
x
Reference in New Issue
Block a user