diff --git a/homeassistant/components/nordpool/config_flow.py b/homeassistant/components/nordpool/config_flow.py index b3b807badad3..415628cf45da 100644 --- a/homeassistant/components/nordpool/config_flow.py +++ b/homeassistant/components/nordpool/config_flow.py @@ -56,6 +56,8 @@ DATA_SCHEMA = vol.Schema( async def test_api(hass: HomeAssistant, user_input: dict[str, Any]) -> dict[str, str]: """Test fetch data from Nord Pool.""" + if not user_input.get(CONF_AREAS): + return {CONF_AREAS: "no_areas"} client = NordPoolClient(async_get_clientsession(hass)) try: await client.async_get_delivery_period( diff --git a/homeassistant/components/nordpool/strings.json b/homeassistant/components/nordpool/strings.json index 89e99c37908c..88706a9fbbdc 100644 --- a/homeassistant/components/nordpool/strings.json +++ b/homeassistant/components/nordpool/strings.json @@ -5,6 +5,7 @@ }, "error": { "cannot_connect": "[%key:common::config_flow::error::cannot_connect%]", + "no_areas": "No area(s) selected", "no_data": "API connected but the response was empty" }, "step": { diff --git a/tests/components/nordpool/test_config_flow.py b/tests/components/nordpool/test_config_flow.py index 9756c909cf38..73b84430c720 100644 --- a/tests/components/nordpool/test_config_flow.py +++ b/tests/components/nordpool/test_config_flow.py @@ -107,6 +107,39 @@ async def test_cannot_connect( assert result["data"] == {"areas": ["SE3", "SE4"], "currency": "SEK"} +@pytest.mark.freeze_time("2025-10-01T18:00:00+00:00") +async def test_missing_areas( + hass: HomeAssistant, + get_client: NordPoolClient, +) -> None: + """Test cannot connect error.""" + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_USER} + ) + + assert result["type"] is FlowResultType.FORM + assert result["step_id"] == config_entries.SOURCE_USER + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input={ + CONF_CURRENCY: "SEK", + }, + ) + + assert result["errors"] == {CONF_AREAS: "no_areas"} + + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + user_input=ENTRY_CONFIG, + ) + + assert result["type"] is FlowResultType.CREATE_ENTRY + assert result["title"] == "Nord Pool" + assert result["data"] == {"areas": ["SE3", "SE4"], "currency": "SEK"} + + @pytest.mark.freeze_time("2025-10-01T18:00:00+00:00") async def test_reconfigure( hass: HomeAssistant,