From 97b7fc68785d699fdbfcc42d37475ef4a05f059d Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 30 Aug 2026 13:02:19 +0200 Subject: [PATCH] Split the Amber Electric user flow init from its data (#180766) --- .../amberelectric/test_config_flow.py | 84 ++++++++++++++----- 1 file changed, 63 insertions(+), 21 deletions(-) diff --git a/tests/components/amberelectric/test_config_flow.py b/tests/components/amberelectric/test_config_flow.py index bffd064cfc02..0f1f00b7bfde 100644 --- a/tests/components/amberelectric/test_config_flow.py +++ b/tests/components/amberelectric/test_config_flow.py @@ -161,9 +161,15 @@ async def test_single_pending_site( # Test filling in API key enter_api_key_result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_USER}, - data={CONF_API_TOKEN: API_KEY}, + DOMAIN, context={"source": SOURCE_USER} + ) + + assert enter_api_key_result["type"] is FlowResultType.FORM + assert enter_api_key_result["step_id"] == "user" + + enter_api_key_result = await hass.config_entries.flow.async_configure( + enter_api_key_result["flow_id"], + user_input={CONF_API_TOKEN: API_KEY}, ) assert enter_api_key_result.get("type") is FlowResultType.FORM assert enter_api_key_result.get("step_id") == "site" @@ -192,9 +198,15 @@ async def test_single_site(hass: HomeAssistant, single_site_api: Mock) -> None: # Test filling in API key enter_api_key_result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_USER}, - data={CONF_API_TOKEN: API_KEY}, + DOMAIN, context={"source": SOURCE_USER} + ) + + assert enter_api_key_result["type"] is FlowResultType.FORM + assert enter_api_key_result["step_id"] == "user" + + enter_api_key_result = await hass.config_entries.flow.async_configure( + enter_api_key_result["flow_id"], + user_input={CONF_API_TOKEN: API_KEY}, ) assert enter_api_key_result.get("type") is FlowResultType.FORM assert enter_api_key_result.get("step_id") == "site" @@ -218,9 +230,15 @@ async def test_single_closed_site_no_closed_date( ) -> None: """Test single closed site with no closed date is filtered out.""" enter_api_key_result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_USER}, - data={CONF_API_TOKEN: API_KEY}, + DOMAIN, context={"source": SOURCE_USER} + ) + + assert enter_api_key_result["type"] is FlowResultType.FORM + assert enter_api_key_result["step_id"] == "user" + + enter_api_key_result = await hass.config_entries.flow.async_configure( + enter_api_key_result["flow_id"], + user_input={CONF_API_TOKEN: API_KEY}, ) assert enter_api_key_result.get("type") is FlowResultType.FORM assert enter_api_key_result.get("step_id") == "user" @@ -239,9 +257,15 @@ async def test_single_site_rejoin( # Test filling in API key enter_api_key_result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_USER}, - data={CONF_API_TOKEN: API_KEY}, + DOMAIN, context={"source": SOURCE_USER} + ) + + assert enter_api_key_result["type"] is FlowResultType.FORM + assert enter_api_key_result["step_id"] == "user" + + enter_api_key_result = await hass.config_entries.flow.async_configure( + enter_api_key_result["flow_id"], + user_input={CONF_API_TOKEN: API_KEY}, ) assert enter_api_key_result.get("type") is FlowResultType.FORM assert enter_api_key_result.get("step_id") == "site" @@ -263,9 +287,15 @@ async def test_single_site_rejoin( async def test_no_site(hass: HomeAssistant, no_site_api: Mock) -> None: """Test no site.""" result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_USER}, - data={CONF_API_TOKEN: "psk_123456789"}, + DOMAIN, context={"source": SOURCE_USER} + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "user" + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input={CONF_API_TOKEN: "psk_123456789"}, ) assert result.get("type") is FlowResultType.FORM @@ -284,9 +314,15 @@ async def test_invalid_key(hass: HomeAssistant, invalid_key_api: Mock) -> None: # Test filling in API key result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_USER}, - data={CONF_API_TOKEN: "psk_123456789"}, + DOMAIN, context={"source": SOURCE_USER} + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "user" + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input={CONF_API_TOKEN: "psk_123456789"}, ) assert result.get("type") is FlowResultType.FORM # Goes back to the user step @@ -304,9 +340,15 @@ async def test_unknown_error(hass: HomeAssistant, api_error: Mock) -> None: # Test filling in API key result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_USER}, - data={CONF_API_TOKEN: "psk_123456789"}, + DOMAIN, context={"source": SOURCE_USER} + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == "user" + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input={CONF_API_TOKEN: "psk_123456789"}, ) assert result.get("type") is FlowResultType.FORM # Goes back to the user step