mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
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:
parent
153b3fbfc8
commit
f837369ef0
@ -6,7 +6,7 @@ from collections.abc import Mapping
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any
|
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 homeassistant.helpers import config_entry_oauth2_flow
|
||||||
|
|
||||||
from .const import DOMAIN, SCOPE_VALUES
|
from .const import DOMAIN, SCOPE_VALUES
|
||||||
@ -19,11 +19,6 @@ class ElectricKiwiOauth2FlowHandler(
|
|||||||
|
|
||||||
DOMAIN = DOMAIN
|
DOMAIN = DOMAIN
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
"""Set up instance."""
|
|
||||||
super().__init__()
|
|
||||||
self._reauth_entry: ConfigEntry | None = None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def logger(self) -> logging.Logger:
|
def logger(self) -> logging.Logger:
|
||||||
"""Return logger."""
|
"""Return logger."""
|
||||||
@ -38,9 +33,6 @@ class ElectricKiwiOauth2FlowHandler(
|
|||||||
self, entry_data: Mapping[str, Any]
|
self, entry_data: Mapping[str, Any]
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Perform reauth upon an API authentication error."""
|
"""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()
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
async def async_step_reauth_confirm(
|
async def async_step_reauth_confirm(
|
||||||
@ -55,7 +47,5 @@ class ElectricKiwiOauth2FlowHandler(
|
|||||||
"""Create an entry for Electric Kiwi."""
|
"""Create an entry for Electric Kiwi."""
|
||||||
existing_entry = await self.async_set_unique_id(DOMAIN)
|
existing_entry = await self.async_set_unique_id(DOMAIN)
|
||||||
if existing_entry:
|
if existing_entry:
|
||||||
self.hass.config_entries.async_update_entry(existing_entry, data=data)
|
return self.async_update_reload_and_abort(existing_entry, data=data)
|
||||||
await self.hass.config_entries.async_reload(existing_entry.entry_id)
|
|
||||||
return self.async_abort(reason="reauth_successful")
|
|
||||||
return await super().async_oauth_create_entry(data)
|
return await super().async_oauth_create_entry(data)
|
||||||
|
@ -159,6 +159,7 @@ async def test_reauthentication(
|
|||||||
setup_credentials: None,
|
setup_credentials: None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test Electric Kiwi reauthentication."""
|
"""Test Electric Kiwi reauthentication."""
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
result = await config_entry.start_reauth_flow(hass)
|
result = await config_entry.start_reauth_flow(hass)
|
||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["step_id"] == "reauth_confirm"
|
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.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(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user