diff --git a/homeassistant/data_entry_flow.py b/homeassistant/data_entry_flow.py index 51f083b7eeb..340ec671eda 100644 --- a/homeassistant/data_entry_flow.py +++ b/homeassistant/data_entry_flow.py @@ -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, diff --git a/homeassistant/helpers/data_entry_flow.py b/homeassistant/helpers/data_entry_flow.py index 951b6d4c748..fe6420750c6 100644 --- a/homeassistant/helpers/data_entry_flow.py +++ b/homeassistant/helpers/data_entry_flow.py @@ -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.""" @@ -60,7 +66,11 @@ class FlowManagerIndexView(_BaseFlowManagerView): 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) diff --git a/tests/components/config/test_config_entries.py b/tests/components/config/test_config_entries.py index 9eb9a741da0..358f952e191 100644 --- a/tests/components/config/test_config_entries.py +++ b/tests/components/config/test_config_entries.py @@ -141,13 +141,17 @@ async def test_initialize_flow(hass, client): 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 @@ -163,7 +167,10 @@ async def test_initialize_flow(hass, client): {"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."}, } diff --git a/tests/test_data_entry_flow.py b/tests/test_data_entry_flow.py index 664304c9ef6..ad63dae6ee6 100644 --- a/tests/test_data_entry_flow.py +++ b/tests/test_data_entry_flow.py @@ -26,7 +26,6 @@ def manager(): 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):