From 2900fa733d97ac649ce2da8551cefbe88d3ac190 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 28 Aug 2024 20:43:11 +0200 Subject: [PATCH] Use reauth_confirm in co2signal (#124781) --- homeassistant/components/co2signal/config_flow.py | 11 +++++++++-- homeassistant/components/co2signal/strings.json | 2 +- tests/components/co2signal/test_config_flow.py | 11 ++--------- tests/components/co2signal/test_sensor.py | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/co2signal/config_flow.py b/homeassistant/components/co2signal/config_flow.py index bf5d645638f..3313d01be85 100644 --- a/homeassistant/components/co2signal/config_flow.py +++ b/homeassistant/components/co2signal/config_flow.py @@ -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] = {} diff --git a/homeassistant/components/co2signal/strings.json b/homeassistant/components/co2signal/strings.json index 7444cde73d7..a4ec916bd42 100644 --- a/homeassistant/components/co2signal/strings.json +++ b/homeassistant/components/co2signal/strings.json @@ -19,7 +19,7 @@ "country_code": "Country code" } }, - "reauth": { + "reauth_confirm": { "data": { "api_key": "[%key:common::config_flow::data::access_token%]" } diff --git a/tests/components/co2signal/test_config_flow.py b/tests/components/co2signal/test_config_flow.py index 7397b6e2355..ad61ae4f897 100644 --- a/tests/components/co2signal/test_config_flow.py +++ b/tests/components/co2signal/test_config_flow.py @@ -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", diff --git a/tests/components/co2signal/test_sensor.py b/tests/components/co2signal/test_sensor.py index e9f46e483d1..fddda17f3ed 100644 --- a/tests/components/co2signal/test_sensor.py +++ b/tests/components/co2signal/test_sensor.py @@ -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"