Use reauth helpers in electric_kiwi config flow (#127414)

* Mark electric_kiwi as single_config_entry

* Adjust

* Use reauth helpers in electric_kiwi config flow
This commit is contained in:
epenet 2024-10-03 18:02:55 +02:00 committed by GitHub
parent 153b3fbfc8
commit f837369ef0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 12 deletions

View File

@ -6,7 +6,7 @@ from collections.abc import Mapping
import logging
from typing import Any
from homeassistant.config_entries import ConfigEntry, ConfigFlowResult
from homeassistant.config_entries import ConfigFlowResult
from homeassistant.helpers import config_entry_oauth2_flow
from .const import DOMAIN, SCOPE_VALUES
@ -19,11 +19,6 @@ class ElectricKiwiOauth2FlowHandler(
DOMAIN = DOMAIN
def __init__(self) -> None:
"""Set up instance."""
super().__init__()
self._reauth_entry: ConfigEntry | None = None
@property
def logger(self) -> logging.Logger:
"""Return logger."""
@ -38,9 +33,6 @@ class ElectricKiwiOauth2FlowHandler(
self, entry_data: Mapping[str, Any]
) -> ConfigFlowResult:
"""Perform reauth upon an API authentication error."""
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(
@ -55,7 +47,5 @@ class ElectricKiwiOauth2FlowHandler(
"""Create an entry for Electric Kiwi."""
existing_entry = await self.async_set_unique_id(DOMAIN)
if existing_entry:
self.hass.config_entries.async_update_entry(existing_entry, data=data)
await self.hass.config_entries.async_reload(existing_entry.entry_id)
return self.async_abort(reason="reauth_successful")
return self.async_update_reload_and_abort(existing_entry, data=data)
return await super().async_oauth_create_entry(data)

View File

@ -159,6 +159,7 @@ async def test_reauthentication(
setup_credentials: None,
) -> None:
"""Test Electric Kiwi reauthentication."""
config_entry.add_to_hass(hass)
result = await config_entry.start_reauth_flow(hass)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
@ -189,6 +190,7 @@ async def test_reauthentication(
)
await hass.config_entries.flow.async_configure(result["flow_id"])
await hass.async_block_till_done()
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert len(mock_setup_entry.mock_calls) == 1