From 2880adc96f034b2ee91b3a60bebf8ef9e5298ac6 Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 14 Apr 2021 10:43:07 +0200 Subject: [PATCH 1/4] Allow data entry flows to hint for additional steps --- homeassistant/components/mqtt/config_flow.py | 3 ++- homeassistant/data_entry_flow.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/mqtt/config_flow.py b/homeassistant/components/mqtt/config_flow.py index 5e5b8c54cf2493..20ea94a3ebbe63 100644 --- a/homeassistant/components/mqtt/config_flow.py +++ b/homeassistant/components/mqtt/config_flow.py @@ -158,7 +158,7 @@ async def async_step_init(self, user_input=None): return await self.async_step_broker() async def async_step_broker(self, user_input=None): - """Manage the MQTT options.""" + """Manage the MQTT broker configuration.""" errors = {} current_config = self.config_entry.data yaml_config = self.hass.data.get(DATA_MQTT_CONFIG, {}) @@ -201,6 +201,7 @@ async def async_step_broker(self, user_input=None): step_id="broker", data_schema=vol.Schema(fields), errors=errors, + last_step=False, ) async def async_step_options(self, user_input=None): diff --git a/homeassistant/data_entry_flow.py b/homeassistant/data_entry_flow.py index b75d956c5273ff..dd76e48f40fbec 100644 --- a/homeassistant/data_entry_flow.py +++ b/homeassistant/data_entry_flow.py @@ -345,6 +345,7 @@ def async_show_form( data_schema: vol.Schema = None, errors: dict[str, str] | None = None, description_placeholders: dict[str, Any] | None = None, + last_step: bool = True, ) -> FlowResultDict: """Return the definition of a form to gather user input.""" return { @@ -355,6 +356,7 @@ def async_show_form( "data_schema": data_schema, "errors": errors, "description_placeholders": description_placeholders, + "last_step": last_step, # Display next or submit button in frontend } @callback From 128b1f8e9d6acc0f92bd9d904e2f99ae9847233e Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 14 Apr 2021 16:17:10 +0200 Subject: [PATCH 2/4] Update tests --- tests/components/config/test_config_entries.py | 5 +++++ tests/components/subaru/test_config_flow.py | 1 + 2 files changed, 6 insertions(+) diff --git a/tests/components/config/test_config_entries.py b/tests/components/config/test_config_entries.py index 128d0798b660f4..43631f4f5dd70c 100644 --- a/tests/components/config/test_config_entries.py +++ b/tests/components/config/test_config_entries.py @@ -235,6 +235,7 @@ async def async_step_user(self, user_input=None): "show_advanced_options": True, }, "errors": {"username": "Should be unique."}, + "last_step": True, } @@ -370,6 +371,7 @@ async def async_step_account(self, user_input=None): "data_schema": [{"name": "user_title", "type": "string"}], "description_placeholders": None, "errors": None, + "last_step": True, } with patch.dict(HANDLERS, {"test": TestFlow}): @@ -439,6 +441,7 @@ async def async_step_account(self, user_input=None): "data_schema": [{"name": "user_title", "type": "string"}], "description_placeholders": None, "errors": None, + "last_step": True, } hass_admin_user.groups = [] @@ -606,6 +609,7 @@ async def async_step_init(self, user_input=None): "data_schema": [{"name": "enabled", "required": True, "type": "boolean"}], "description_placeholders": {"enabled": "Set to true to be true"}, "errors": None, + "last_step": True, } @@ -654,6 +658,7 @@ async def async_step_finish(self, user_input=None): "data_schema": [{"name": "enabled", "type": "boolean"}], "description_placeholders": None, "errors": None, + "last_step": True, } with patch.dict(HANDLERS, {"test": TestFlow}): diff --git a/tests/components/subaru/test_config_flow.py b/tests/components/subaru/test_config_flow.py index 35e254fe3026ea..3d3ddb672ac88b 100644 --- a/tests/components/subaru/test_config_flow.py +++ b/tests/components/subaru/test_config_flow.py @@ -131,6 +131,7 @@ async def test_pin_form_init(pin_form): "handler": DOMAIN, "step_id": "pin", "type": "form", + "last_step": True, } assert pin_form == expected From 72f3c5c90fd439faa76d28755da3062f559e55d0 Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 21 Apr 2021 08:27:17 +0200 Subject: [PATCH 3/4] Fix typing --- homeassistant/data_entry_flow.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/data_entry_flow.py b/homeassistant/data_entry_flow.py index dd76e48f40fbec..27b5d0189d6159 100644 --- a/homeassistant/data_entry_flow.py +++ b/homeassistant/data_entry_flow.py @@ -72,6 +72,7 @@ class FlowResultDict(TypedDict, total=False): reason: str context: dict[str, Any] result: Any + last_step: bool class FlowManager(abc.ABC): From 45aae6dd8949e52accc7e0fa7fb0ec1b44cc18dd Mon Sep 17 00:00:00 2001 From: Erik Date: Fri, 23 Apr 2021 14:15:49 +0200 Subject: [PATCH 4/4] Make last_step default to None --- homeassistant/components/mqtt/config_flow.py | 1 + homeassistant/data_entry_flow.py | 4 ++-- tests/components/config/test_config_entries.py | 10 +++++----- tests/components/subaru/test_config_flow.py | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/mqtt/config_flow.py b/homeassistant/components/mqtt/config_flow.py index 20ea94a3ebbe63..11f9a39782363a 100644 --- a/homeassistant/components/mqtt/config_flow.py +++ b/homeassistant/components/mqtt/config_flow.py @@ -322,6 +322,7 @@ async def async_step_options(self, user_input=None): step_id="options", data_schema=vol.Schema(fields), errors=errors, + last_step=True, ) diff --git a/homeassistant/data_entry_flow.py b/homeassistant/data_entry_flow.py index 27b5d0189d6159..a43f30354260f0 100644 --- a/homeassistant/data_entry_flow.py +++ b/homeassistant/data_entry_flow.py @@ -72,7 +72,7 @@ class FlowResultDict(TypedDict, total=False): reason: str context: dict[str, Any] result: Any - last_step: bool + last_step: bool | None class FlowManager(abc.ABC): @@ -346,7 +346,7 @@ def async_show_form( data_schema: vol.Schema = None, errors: dict[str, str] | None = None, description_placeholders: dict[str, Any] | None = None, - last_step: bool = True, + last_step: bool | None = None, ) -> FlowResultDict: """Return the definition of a form to gather user input.""" return { diff --git a/tests/components/config/test_config_entries.py b/tests/components/config/test_config_entries.py index 43631f4f5dd70c..fbf78aa7a735c5 100644 --- a/tests/components/config/test_config_entries.py +++ b/tests/components/config/test_config_entries.py @@ -235,7 +235,7 @@ async def async_step_user(self, user_input=None): "show_advanced_options": True, }, "errors": {"username": "Should be unique."}, - "last_step": True, + "last_step": None, } @@ -371,7 +371,7 @@ async def async_step_account(self, user_input=None): "data_schema": [{"name": "user_title", "type": "string"}], "description_placeholders": None, "errors": None, - "last_step": True, + "last_step": None, } with patch.dict(HANDLERS, {"test": TestFlow}): @@ -441,7 +441,7 @@ async def async_step_account(self, user_input=None): "data_schema": [{"name": "user_title", "type": "string"}], "description_placeholders": None, "errors": None, - "last_step": True, + "last_step": None, } hass_admin_user.groups = [] @@ -609,7 +609,7 @@ async def async_step_init(self, user_input=None): "data_schema": [{"name": "enabled", "required": True, "type": "boolean"}], "description_placeholders": {"enabled": "Set to true to be true"}, "errors": None, - "last_step": True, + "last_step": None, } @@ -658,7 +658,7 @@ async def async_step_finish(self, user_input=None): "data_schema": [{"name": "enabled", "type": "boolean"}], "description_placeholders": None, "errors": None, - "last_step": True, + "last_step": None, } with patch.dict(HANDLERS, {"test": TestFlow}): diff --git a/tests/components/subaru/test_config_flow.py b/tests/components/subaru/test_config_flow.py index 3d3ddb672ac88b..031b9c29d09de4 100644 --- a/tests/components/subaru/test_config_flow.py +++ b/tests/components/subaru/test_config_flow.py @@ -131,7 +131,7 @@ async def test_pin_form_init(pin_form): "handler": DOMAIN, "step_id": "pin", "type": "form", - "last_step": True, + "last_step": None, } assert pin_form == expected