Skip to content

Commit

Permalink
Use reauth_confirm in co2signal (#124781)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Aug 28, 2024
1 parent 7d61dd1 commit 2900fa7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
11 changes: 9 additions & 2 deletions homeassistant/components/co2signal/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,23 @@ async def async_step_reauth(
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] = {}
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/co2signal/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"country_code": "Country code"
}
},
"reauth": {
"reauth_confirm": {
"data": {
"api_key": "[%key:common::config_flow::data::access_token%]"
}
Expand Down
11 changes: 2 additions & 9 deletions tests/components/co2signal/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/components/co2signal/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 2900fa7

Please sign in to comment.