mirror of
https://github.com/home-assistant/core.git
synced 2026-08-31 18:24:50 -05:00
Fix config flow validation in Nord Pool (#169751)
This commit is contained in:
committed by
Paulus Schoutsen
parent
e15852ff38
commit
a7eaa51179
@@ -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(
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user