mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Add name to description placeholders automatically for reauth flows (#129232)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
b8ddfd642e
commit
3db6d82904
@ -27,10 +27,16 @@ from typing import TYPE_CHECKING, Any, Generic, Self, cast
|
|||||||
from async_interrupt import interrupt
|
from async_interrupt import interrupt
|
||||||
from propcache import cached_property
|
from propcache import cached_property
|
||||||
from typing_extensions import TypeVar
|
from typing_extensions import TypeVar
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
from . import data_entry_flow, loader
|
from . import data_entry_flow, loader
|
||||||
from .components import persistent_notification
|
from .components import persistent_notification
|
||||||
from .const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP, Platform
|
from .const import (
|
||||||
|
CONF_NAME,
|
||||||
|
EVENT_HOMEASSISTANT_STARTED,
|
||||||
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
|
Platform,
|
||||||
|
)
|
||||||
from .core import (
|
from .core import (
|
||||||
CALLBACK_TYPE,
|
CALLBACK_TYPE,
|
||||||
DOMAIN as HOMEASSISTANT_DOMAIN,
|
DOMAIN as HOMEASSISTANT_DOMAIN,
|
||||||
@ -2882,6 +2888,38 @@ class ConfigFlow(ConfigEntryBaseFlow):
|
|||||||
reason = "reconfigure_successful"
|
reason = "reconfigure_successful"
|
||||||
return self.async_abort(reason=reason)
|
return self.async_abort(reason=reason)
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def async_show_form(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
step_id: str | None = None,
|
||||||
|
data_schema: vol.Schema | None = None,
|
||||||
|
errors: dict[str, str] | None = None,
|
||||||
|
description_placeholders: Mapping[str, str | None] | None = None,
|
||||||
|
last_step: bool | None = None,
|
||||||
|
preview: str | None = None,
|
||||||
|
) -> ConfigFlowResult:
|
||||||
|
"""Return the definition of a form to gather user input.
|
||||||
|
|
||||||
|
The step_id parameter is deprecated and will be removed in a future release.
|
||||||
|
"""
|
||||||
|
if self.source == SOURCE_REAUTH and "entry_id" in self.context:
|
||||||
|
# If the integration does not provide a name for the reauth title,
|
||||||
|
# we append it to the description placeholders.
|
||||||
|
# We also need to check entry_id as some integrations bypass the
|
||||||
|
# reauth helpers and create a flow without it.
|
||||||
|
description_placeholders = dict(description_placeholders or {})
|
||||||
|
if description_placeholders.get(CONF_NAME) is None:
|
||||||
|
description_placeholders[CONF_NAME] = self._get_reauth_entry().title
|
||||||
|
return super().async_show_form(
|
||||||
|
step_id=step_id,
|
||||||
|
data_schema=data_schema,
|
||||||
|
errors=errors,
|
||||||
|
description_placeholders=description_placeholders,
|
||||||
|
last_step=last_step,
|
||||||
|
preview=preview,
|
||||||
|
)
|
||||||
|
|
||||||
def is_matching(self, other_flow: Self) -> bool:
|
def is_matching(self, other_flow: Self) -> bool:
|
||||||
"""Return True if other_flow is matching this flow."""
|
"""Return True if other_flow is matching this flow."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
@ -16,6 +16,7 @@ from homeassistant.components.apple_tv.const import (
|
|||||||
CONF_START_OFF,
|
CONF_START_OFF,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
|
from homeassistant.const import CONF_NAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
|
|
||||||
@ -1196,7 +1197,10 @@ async def test_reconfigure_update_credentials(hass: HomeAssistant) -> None:
|
|||||||
{},
|
{},
|
||||||
)
|
)
|
||||||
assert result2["type"] is FlowResultType.FORM
|
assert result2["type"] is FlowResultType.FORM
|
||||||
assert result2["description_placeholders"] == {"protocol": "MRP"}
|
assert result2["description_placeholders"] == {
|
||||||
|
CONF_NAME: "Mock Title",
|
||||||
|
"protocol": "MRP",
|
||||||
|
}
|
||||||
|
|
||||||
result3 = await hass.config_entries.flow.async_configure(
|
result3 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], {"pin": 1111}
|
result["flow_id"], {"pin": 1111}
|
||||||
|
@ -11,6 +11,7 @@ import pytest
|
|||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components import glances
|
from homeassistant.components import glances
|
||||||
|
from homeassistant.const import CONF_NAME, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
|
|
||||||
@ -92,7 +93,10 @@ async def test_reauth_success(hass: HomeAssistant) -> None:
|
|||||||
result = await entry.start_reauth_flow(hass)
|
result = await entry.start_reauth_flow(hass)
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "reauth_confirm"
|
assert result["step_id"] == "reauth_confirm"
|
||||||
assert result["description_placeholders"] == {"username": "username"}
|
assert result["description_placeholders"] == {
|
||||||
|
CONF_NAME: "Mock Title",
|
||||||
|
CONF_USERNAME: "username",
|
||||||
|
}
|
||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
@ -123,7 +127,10 @@ async def test_reauth_fails(
|
|||||||
result = await entry.start_reauth_flow(hass)
|
result = await entry.start_reauth_flow(hass)
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "reauth_confirm"
|
assert result["step_id"] == "reauth_confirm"
|
||||||
assert result["description_placeholders"] == {"username": "username"}
|
assert result["description_placeholders"] == {
|
||||||
|
CONF_NAME: "Mock Title",
|
||||||
|
CONF_USERNAME: "username",
|
||||||
|
}
|
||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
|
@ -14,6 +14,7 @@ from homeassistant.components.mikrotik.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
|
CONF_NAME,
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
@ -179,7 +180,10 @@ async def test_reauth_success(hass: HomeAssistant, api) -> None:
|
|||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "reauth_confirm"
|
assert result["step_id"] == "reauth_confirm"
|
||||||
assert result["description_placeholders"] == {CONF_USERNAME: "username"}
|
assert result["description_placeholders"] == {
|
||||||
|
CONF_NAME: "Mock Title",
|
||||||
|
CONF_USERNAME: "username",
|
||||||
|
}
|
||||||
|
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
|
@ -9,7 +9,7 @@ from homeassistant import config_entries
|
|||||||
from homeassistant.components import dhcp
|
from homeassistant.components import dhcp
|
||||||
from homeassistant.components.onvif import DOMAIN, config_flow
|
from homeassistant.components.onvif import DOMAIN, config_flow
|
||||||
from homeassistant.config_entries import SOURCE_DHCP
|
from homeassistant.config_entries import SOURCE_DHCP
|
||||||
from homeassistant.const import CONF_HOST, CONF_USERNAME
|
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
@ -803,7 +803,8 @@ async def test_form_reauth(hass: HomeAssistant) -> None:
|
|||||||
assert result2["step_id"] == "reauth_confirm"
|
assert result2["step_id"] == "reauth_confirm"
|
||||||
assert result2["errors"] == {config_flow.CONF_PASSWORD: "auth_failed"}
|
assert result2["errors"] == {config_flow.CONF_PASSWORD: "auth_failed"}
|
||||||
assert result2["description_placeholders"] == {
|
assert result2["description_placeholders"] == {
|
||||||
"error": "not authorized (subcodes:NotAuthorized)"
|
CONF_NAME: "Mock Title",
|
||||||
|
"error": "not authorized (subcodes:NotAuthorized)",
|
||||||
}
|
}
|
||||||
|
|
||||||
with (
|
with (
|
||||||
|
@ -13,7 +13,7 @@ from homeassistant.components.renault.const import (
|
|||||||
CONF_LOCALE,
|
CONF_LOCALE,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_NAME, CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
from homeassistant.helpers import aiohttp_client
|
from homeassistant.helpers import aiohttp_client
|
||||||
@ -224,7 +224,10 @@ async def test_reauth(hass: HomeAssistant, config_entry: MockConfigEntry) -> Non
|
|||||||
result = await config_entry.start_reauth_flow(hass)
|
result = await config_entry.start_reauth_flow(hass)
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["description_placeholders"] == {CONF_USERNAME: "email@test.com"}
|
assert result["description_placeholders"] == {
|
||||||
|
CONF_NAME: "Mock Title",
|
||||||
|
CONF_USERNAME: "email@test.com",
|
||||||
|
}
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
# Failed credentials
|
# Failed credentials
|
||||||
@ -238,7 +241,10 @@ async def test_reauth(hass: HomeAssistant, config_entry: MockConfigEntry) -> Non
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert result2["type"] is FlowResultType.FORM
|
assert result2["type"] is FlowResultType.FORM
|
||||||
assert result2["description_placeholders"] == {CONF_USERNAME: "email@test.com"}
|
assert result2["description_placeholders"] == {
|
||||||
|
CONF_NAME: "Mock Title",
|
||||||
|
CONF_USERNAME: "email@test.com",
|
||||||
|
}
|
||||||
assert result2["errors"] == {"base": "invalid_credentials"}
|
assert result2["errors"] == {"base": "invalid_credentials"}
|
||||||
|
|
||||||
# Valid credentials
|
# Valid credentials
|
||||||
|
@ -18,6 +18,7 @@ from homeassistant import config_entries, data_entry_flow, loader
|
|||||||
from homeassistant.components import dhcp
|
from homeassistant.components import dhcp
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
CONF_NAME,
|
||||||
EVENT_COMPONENT_LOADED,
|
EVENT_COMPONENT_LOADED,
|
||||||
EVENT_HOMEASSISTANT_STARTED,
|
EVENT_HOMEASSISTANT_STARTED,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
@ -85,8 +86,27 @@ def mock_handlers() -> Generator[None]:
|
|||||||
"""Mock Reauth."""
|
"""Mock Reauth."""
|
||||||
return await self.async_step_reauth_confirm()
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
|
class MockFlowHandler2(config_entries.ConfigFlow):
|
||||||
|
"""Define a second mock flow handler."""
|
||||||
|
|
||||||
|
VERSION = 1
|
||||||
|
|
||||||
|
async def async_step_reauth(self, data):
|
||||||
|
"""Mock Reauth."""
|
||||||
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
|
async def async_step_reauth_confirm(self, user_input=None):
|
||||||
|
"""Test reauth confirm step."""
|
||||||
|
if user_input is None:
|
||||||
|
return self.async_show_form(
|
||||||
|
step_id="reauth_confirm",
|
||||||
|
description_placeholders={CONF_NAME: "Custom title"},
|
||||||
|
)
|
||||||
|
return self.async_abort(reason="test")
|
||||||
|
|
||||||
with patch.dict(
|
with patch.dict(
|
||||||
config_entries.HANDLERS, {"comp": MockFlowHandler, "test": MockFlowHandler}
|
config_entries.HANDLERS,
|
||||||
|
{"comp": MockFlowHandler, "test": MockFlowHandler, "test2": MockFlowHandler2},
|
||||||
):
|
):
|
||||||
yield
|
yield
|
||||||
|
|
||||||
@ -1157,6 +1177,9 @@ async def test_reauth_notification(hass: HomeAssistant) -> None:
|
|||||||
mock_integration(hass, MockModule("test"))
|
mock_integration(hass, MockModule("test"))
|
||||||
mock_platform(hass, "test.config_flow", None)
|
mock_platform(hass, "test.config_flow", None)
|
||||||
|
|
||||||
|
entry = MockConfigEntry(title="test_title", domain="test")
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
class TestFlow(config_entries.ConfigFlow):
|
class TestFlow(config_entries.ConfigFlow):
|
||||||
"""Test flow."""
|
"""Test flow."""
|
||||||
|
|
||||||
@ -1190,7 +1213,11 @@ async def test_reauth_notification(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
# Start first reauth flow to assert that reconfigure notification fires
|
# Start first reauth flow to assert that reconfigure notification fires
|
||||||
flow1 = await hass.config_entries.flow.async_init(
|
flow1 = await hass.config_entries.flow.async_init(
|
||||||
"test", context={"source": config_entries.SOURCE_REAUTH}
|
"test",
|
||||||
|
context={
|
||||||
|
"source": config_entries.SOURCE_REAUTH,
|
||||||
|
"entry_id": entry.entry_id,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -1200,7 +1227,11 @@ async def test_reauth_notification(hass: HomeAssistant) -> None:
|
|||||||
# Start a second reauth flow so we can finish the first and assert that
|
# Start a second reauth flow so we can finish the first and assert that
|
||||||
# the reconfigure notification persists until the second one is complete
|
# the reconfigure notification persists until the second one is complete
|
||||||
flow2 = await hass.config_entries.flow.async_init(
|
flow2 = await hass.config_entries.flow.async_init(
|
||||||
"test", context={"source": config_entries.SOURCE_REAUTH}
|
"test",
|
||||||
|
context={
|
||||||
|
"source": config_entries.SOURCE_REAUTH,
|
||||||
|
"entry_id": entry.entry_id,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
flow1 = await hass.config_entries.flow.async_configure(flow1["flow_id"], {})
|
flow1 = await hass.config_entries.flow.async_configure(flow1["flow_id"], {})
|
||||||
@ -5382,25 +5413,25 @@ async def test_hashable_non_string_unique_id(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("source", "user_input", "expected_result"),
|
("context", "user_input", "expected_result"),
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
config_entries.SOURCE_IGNORE,
|
{"source": config_entries.SOURCE_IGNORE},
|
||||||
{"unique_id": "blah", "title": "blah"},
|
{"unique_id": "blah", "title": "blah"},
|
||||||
{"type": data_entry_flow.FlowResultType.CREATE_ENTRY},
|
{"type": data_entry_flow.FlowResultType.CREATE_ENTRY},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
config_entries.SOURCE_REAUTH,
|
{"source": config_entries.SOURCE_REAUTH, "entry_id": "1234"},
|
||||||
None,
|
None,
|
||||||
{"type": data_entry_flow.FlowResultType.FORM, "step_id": "reauth_confirm"},
|
{"type": data_entry_flow.FlowResultType.FORM, "step_id": "reauth_confirm"},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
config_entries.SOURCE_RECONFIGURE,
|
{"source": config_entries.SOURCE_RECONFIGURE, "entry_id": "1234"},
|
||||||
None,
|
None,
|
||||||
{"type": data_entry_flow.FlowResultType.FORM, "step_id": "reauth_confirm"},
|
{"type": data_entry_flow.FlowResultType.FORM, "step_id": "reauth_confirm"},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
config_entries.SOURCE_USER,
|
{"source": config_entries.SOURCE_USER},
|
||||||
None,
|
None,
|
||||||
{
|
{
|
||||||
"type": data_entry_flow.FlowResultType.ABORT,
|
"type": data_entry_flow.FlowResultType.ABORT,
|
||||||
@ -5413,7 +5444,7 @@ async def test_hashable_non_string_unique_id(
|
|||||||
async def test_starting_config_flow_on_single_config_entry(
|
async def test_starting_config_flow_on_single_config_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
manager: config_entries.ConfigEntries,
|
manager: config_entries.ConfigEntries,
|
||||||
source: str,
|
context: dict[str, Any],
|
||||||
user_input: dict,
|
user_input: dict,
|
||||||
expected_result: dict,
|
expected_result: dict,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -5436,6 +5467,7 @@ async def test_starting_config_flow_on_single_config_entry(
|
|||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain="comp",
|
domain="comp",
|
||||||
unique_id="1234",
|
unique_id="1234",
|
||||||
|
entry_id="1234",
|
||||||
title="Test",
|
title="Test",
|
||||||
data={"vendor": "data"},
|
data={"vendor": "data"},
|
||||||
options={"vendor": "options"},
|
options={"vendor": "options"},
|
||||||
@ -5444,6 +5476,7 @@ async def test_starting_config_flow_on_single_config_entry(
|
|||||||
ignored_entry = MockConfigEntry(
|
ignored_entry = MockConfigEntry(
|
||||||
domain="comp",
|
domain="comp",
|
||||||
unique_id="2345",
|
unique_id="2345",
|
||||||
|
entry_id="2345",
|
||||||
title="Test",
|
title="Test",
|
||||||
data={"vendor": "data"},
|
data={"vendor": "data"},
|
||||||
options={"vendor": "options"},
|
options={"vendor": "options"},
|
||||||
@ -5458,7 +5491,7 @@ async def test_starting_config_flow_on_single_config_entry(
|
|||||||
return_value=integration,
|
return_value=integration,
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
"comp", context={"source": source}, data=user_input
|
"comp", context=context, data=user_input
|
||||||
)
|
)
|
||||||
|
|
||||||
for key in expected_result:
|
for key in expected_result:
|
||||||
@ -5466,25 +5499,25 @@ async def test_starting_config_flow_on_single_config_entry(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("source", "user_input", "expected_result"),
|
("context", "user_input", "expected_result"),
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
config_entries.SOURCE_IGNORE,
|
{"source": config_entries.SOURCE_IGNORE},
|
||||||
{"unique_id": "blah", "title": "blah"},
|
{"unique_id": "blah", "title": "blah"},
|
||||||
{"type": data_entry_flow.FlowResultType.CREATE_ENTRY},
|
{"type": data_entry_flow.FlowResultType.CREATE_ENTRY},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
config_entries.SOURCE_REAUTH,
|
{"source": config_entries.SOURCE_REAUTH, "entry_id": "2345"},
|
||||||
None,
|
None,
|
||||||
{"type": data_entry_flow.FlowResultType.FORM, "step_id": "reauth_confirm"},
|
{"type": data_entry_flow.FlowResultType.FORM, "step_id": "reauth_confirm"},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
config_entries.SOURCE_RECONFIGURE,
|
{"source": config_entries.SOURCE_RECONFIGURE, "entry_id": "2345"},
|
||||||
None,
|
None,
|
||||||
{"type": data_entry_flow.FlowResultType.FORM, "step_id": "reauth_confirm"},
|
{"type": data_entry_flow.FlowResultType.FORM, "step_id": "reauth_confirm"},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
config_entries.SOURCE_USER,
|
{"source": config_entries.SOURCE_USER},
|
||||||
None,
|
None,
|
||||||
{"type": data_entry_flow.FlowResultType.ABORT, "reason": "not_implemented"},
|
{"type": data_entry_flow.FlowResultType.ABORT, "reason": "not_implemented"},
|
||||||
),
|
),
|
||||||
@ -5493,7 +5526,7 @@ async def test_starting_config_flow_on_single_config_entry(
|
|||||||
async def test_starting_config_flow_on_single_config_entry_2(
|
async def test_starting_config_flow_on_single_config_entry_2(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
manager: config_entries.ConfigEntries,
|
manager: config_entries.ConfigEntries,
|
||||||
source: str,
|
context: dict[str, Any],
|
||||||
user_input: dict,
|
user_input: dict,
|
||||||
expected_result: dict,
|
expected_result: dict,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -5516,6 +5549,7 @@ async def test_starting_config_flow_on_single_config_entry_2(
|
|||||||
ignored_entry = MockConfigEntry(
|
ignored_entry = MockConfigEntry(
|
||||||
domain="comp",
|
domain="comp",
|
||||||
unique_id="2345",
|
unique_id="2345",
|
||||||
|
entry_id="2345",
|
||||||
title="Test",
|
title="Test",
|
||||||
data={"vendor": "data"},
|
data={"vendor": "data"},
|
||||||
options={"vendor": "options"},
|
options={"vendor": "options"},
|
||||||
@ -5530,7 +5564,7 @@ async def test_starting_config_flow_on_single_config_entry_2(
|
|||||||
return_value=integration,
|
return_value=integration,
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
"comp", context={"source": source}, data=user_input
|
"comp", context=context, data=user_input
|
||||||
)
|
)
|
||||||
|
|
||||||
for key in expected_result:
|
for key in expected_result:
|
||||||
@ -7096,3 +7130,51 @@ async def test_context_no_leak(hass: HomeAssistant) -> None:
|
|||||||
assert entry.state is config_entries.ConfigEntryState.LOADED
|
assert entry.state is config_entries.ConfigEntryState.LOADED
|
||||||
assert entry.runtime_data is entry
|
assert entry.runtime_data is entry
|
||||||
assert config_entries.current_entry.get() is None
|
assert config_entries.current_entry.get() is None
|
||||||
|
|
||||||
|
|
||||||
|
async def test_add_description_placeholder_automatically(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
manager: config_entries.ConfigEntries,
|
||||||
|
) -> None:
|
||||||
|
"""Test entry title is added automatically to reauth flows description placeholder."""
|
||||||
|
|
||||||
|
entry = MockConfigEntry(title="test_title", domain="test")
|
||||||
|
|
||||||
|
mock_setup_entry = AsyncMock(side_effect=ConfigEntryAuthFailed())
|
||||||
|
mock_integration(hass, MockModule("test", async_setup_entry=mock_setup_entry))
|
||||||
|
mock_platform(hass, "test.config_flow", None)
|
||||||
|
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
await manager.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
flows = hass.config_entries.flow.async_progress_by_handler("test")
|
||||||
|
assert len(flows) == 1
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(flows[0]["flow_id"], None)
|
||||||
|
assert result["type"] == FlowResultType.FORM
|
||||||
|
assert result["description_placeholders"] == {"name": "test_title"}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_add_description_placeholder_automatically_not_overwrites(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
manager: config_entries.ConfigEntries,
|
||||||
|
) -> None:
|
||||||
|
"""Test entry title is not added automatically to reauth flows when custom name exist."""
|
||||||
|
|
||||||
|
entry = MockConfigEntry(title="test_title", domain="test2")
|
||||||
|
|
||||||
|
mock_setup_entry = AsyncMock(side_effect=ConfigEntryAuthFailed())
|
||||||
|
mock_integration(hass, MockModule("test2", async_setup_entry=mock_setup_entry))
|
||||||
|
mock_platform(hass, "test2.config_flow", None)
|
||||||
|
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
await manager.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
flows = hass.config_entries.flow.async_progress_by_handler("test2")
|
||||||
|
assert len(flows) == 1
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(flows[0]["flow_id"], None)
|
||||||
|
assert result["type"] == FlowResultType.FORM
|
||||||
|
assert result["description_placeholders"] == {"name": "Custom title"}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user