Use reauth_confirm in co2signal (#124781)

This commit is contained in:
epenet 2024-08-28 20:43:11 +02:00 committed by GitHub
parent 7d61dd13d9
commit 2900fa733d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 13 deletions

View File

@ -131,16 +131,23 @@ class ElectricityMapsConfigFlow(ConfigFlow, domain=DOMAIN):
self._reauth_entry = self.hass.config_entries.async_get_entry(
self.context["entry_id"]
)
return await self.async_step_reauth_confirm()
async def async_step_reauth_confirm(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle the reauth step."""
data_schema = vol.Schema(
{
vol.Required(CONF_API_KEY): cv.string,
}
)
return await self._validate_and_create("reauth", data_schema, entry_data)
return await self._validate_and_create(
"reauth_confirm", data_schema, user_input
)
async def _validate_and_create(
self, step_id: str, data_schema: vol.Schema, data: Mapping[str, Any]
self, step_id: str, data_schema: vol.Schema, data: Mapping[str, Any] | None
) -> ConfigFlowResult:
"""Validate data and show form if it is invalid."""
errors: dict[str, str] = {}

View File

@ -19,7 +19,7 @@
"country_code": "Country code"
}
},
"reauth": {
"reauth_confirm": {
"data": {
"api_key": "[%key:common::config_flow::data::access_token%]"
}

View File

@ -198,17 +198,10 @@ async def test_reauth(
"""Test reauth flow."""
config_entry.add_to_hass(hass)
init_result = await hass.config_entries.flow.async_init(
DOMAIN,
context={
"source": config_entries.SOURCE_REAUTH,
"entry_id": config_entry.entry_id,
},
data=None,
)
init_result = await config_entry.start_reauth_flow(hass)
assert init_result["type"] is FlowResultType.FORM
assert init_result["step_id"] == "reauth"
assert init_result["step_id"] == "reauth_confirm"
with patch(
"homeassistant.components.co2signal.async_setup_entry",

View File

@ -109,4 +109,4 @@ async def test_sensor_reauth_triggered(
assert (flows := hass.config_entries.flow.async_progress())
assert len(flows) == 1
assert flows[0]["step_id"] == "reauth"
assert flows[0]["step_id"] == "reauth_confirm"