Use reauth helpers in airvisual (#128335)

* Use reauth helpers in airvisual

* Cleanup unused code in tests
This commit is contained in:
epenet 2024-10-14 11:46:14 +02:00 committed by GitHub
parent a53e02b51b
commit 6d72391ee1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 7 deletions

View file

@ -16,7 +16,12 @@ from pyairvisual.cloud_api import (
from pyairvisual.errors import AirVisualError
import voluptuous as vol
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
from homeassistant.config_entries import (
SOURCE_REAUTH,
ConfigEntry,
ConfigFlow,
ConfigFlowResult,
)
from homeassistant.const import (
CONF_API_KEY,
CONF_COUNTRY,
@ -140,8 +145,11 @@ class AirVisualFlowHandler(ConfigFlow, domain=DOMAIN):
valid_keys.add(user_input[CONF_API_KEY])
if existing_entry := await self.async_set_unique_id(self._geo_id):
return self.async_update_reload_and_abort(existing_entry, data=user_input)
if self.source == SOURCE_REAUTH:
return self.async_update_reload_and_abort(
self._get_reauth_entry(),
data_updates={CONF_API_KEY: user_input[CONF_API_KEY]},
)
return self.async_create_entry(
title=f"Cloud API ({self._geo_id})",

View file

@ -155,10 +155,6 @@ async def test_step_reauth(
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
result = await hass.config_entries.flow.async_configure(result["flow_id"])
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
new_api_key = "defgh67890"
result = await hass.config_entries.flow.async_configure(