From 3c72cd7612705b29be7fb9ffdc6e0361bfc7884b Mon Sep 17 00:00:00 2001 From: Eugenio Panadero Date: Fri, 24 Nov 2023 11:28:49 +0100 Subject: [PATCH] Await step in config-flow instead of moving to another form (#104412) * Await step in config-flow instead of moving to another form * Fix call to step-api-token * Fix condition in step-api-token --- .../pvpc_hourly_pricing/config_flow.py | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/pvpc_hourly_pricing/config_flow.py b/homeassistant/components/pvpc_hourly_pricing/config_flow.py index a98b9faf56e..66092cb9211 100644 --- a/homeassistant/components/pvpc_hourly_pricing/config_flow.py +++ b/homeassistant/components/pvpc_hourly_pricing/config_flow.py @@ -77,13 +77,7 @@ class TariffSelectorConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): self._power = user_input[ATTR_POWER] self._power_p3 = user_input[ATTR_POWER_P3] self._use_api_token = user_input[CONF_USE_API_TOKEN] - return self.async_show_form( - step_id="api_token", - data_schema=vol.Schema( - {vol.Required(CONF_API_TOKEN, default=self._api_token): str} - ), - description_placeholders={"mail_to_link": _MAIL_TO_LINK}, - ) + return await self.async_step_api_token() data_schema = vol.Schema( { @@ -96,14 +90,24 @@ class TariffSelectorConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): ) return self.async_show_form(step_id="user", data_schema=data_schema) - async def async_step_api_token(self, user_input: dict[str, Any]) -> FlowResult: + async def async_step_api_token( + self, user_input: dict[str, Any] | None = None + ) -> FlowResult: """Handle optional step to define API token for extra sensors.""" - self._api_token = user_input[CONF_API_TOKEN] - return await self._async_verify( - "api_token", + if user_input is not None: + self._api_token = user_input[CONF_API_TOKEN] + return await self._async_verify( + "api_token", + data_schema=vol.Schema( + {vol.Required(CONF_API_TOKEN, default=self._api_token): str} + ), + ) + return self.async_show_form( + step_id="api_token", data_schema=vol.Schema( {vol.Required(CONF_API_TOKEN, default=self._api_token): str} ), + description_placeholders={"mail_to_link": _MAIL_TO_LINK}, ) async def _async_verify(self, step_id: str, data_schema: vol.Schema) -> FlowResult: