Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions homeassistant/data_entry_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ class FlowHandler:
# Set by developer
VERSION = 1

@property
def source(self) -> Optional[str]:
"""Source that initialized the flow."""
return self.context.get("source", None)

@property
def show_advanced_options(self) -> bool:
"""If we should show advanced options."""
return self.context.get("show_advanced_options", False)

@callback
def async_show_form(
self,
Expand Down
14 changes: 12 additions & 2 deletions homeassistant/helpers/data_entry_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ class FlowManagerIndexView(_BaseFlowManagerView):
"""View to create config flows."""

@RequestDataValidator(
vol.Schema({vol.Required("handler"): vol.Any(str, list)}, extra=vol.ALLOW_EXTRA)
vol.Schema(
{
vol.Required("handler"): vol.Any(str, list),
vol.Optional("show_advanced_options", default=False): cv.boolean,
},
extra=vol.ALLOW_EXTRA,
)
)
async def post(self, request, data):
"""Handle a POST request."""
Expand All @@ -60,7 +66,11 @@ async def post(self, request, data):

try:
result = await self._flow_mgr.async_init(
handler, context={"source": config_entries.SOURCE_USER}
handler,
context={
"source": config_entries.SOURCE_USER,
"show_advanced_options": data["show_advanced_options"],
},
)
except data_entry_flow.UnknownHandler:
return self.json_message("Invalid handler specified", HTTP_NOT_FOUND)
Expand Down
13 changes: 10 additions & 3 deletions tests/components/config/test_config_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,17 @@ async def async_step_user(self, user_input=None):
return self.async_show_form(
step_id="user",
data_schema=schema,
description_placeholders={"url": "https://example.com"},
description_placeholders={
"url": "https://example.com",
"show_advanced_options": self.show_advanced_options,
},
errors={"username": "Should be unique."},
)

with patch.dict(HANDLERS, {"test": TestFlow}):
resp = await client.post(
"/api/config/config_entries/flow", json={"handler": "test"}
"/api/config/config_entries/flow",
json={"handler": "test", "show_advanced_options": True},
)

assert resp.status == 200
Expand All @@ -163,7 +167,10 @@ async def async_step_user(self, user_input=None):
{"name": "username", "required": True, "type": "string"},
{"name": "password", "required": True, "type": "string"},
],
"description_placeholders": {"url": "https://example.com"},
"description_placeholders": {
"url": "https://example.com",
"show_advanced_options": True,
},
"errors": {"username": "Should be unique."},
}

Expand Down
1 change: 0 additions & 1 deletion tests/test_data_entry_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ async def async_create_flow(self, handler_key, *, context, data):

flow = handler()
flow.init_step = context.get("init_step", "init")
flow.source = context.get("source")
return flow

async def async_finish_flow(self, flow, result):
Expand Down