Skip to content

Commit

Permalink
Use reauth helpers in electric_kiwi config flow (#127414)
Browse files Browse the repository at this point in the history
* Mark electric_kiwi as single_config_entry

* Adjust

* Use reauth helpers in electric_kiwi config flow
  • Loading branch information
epenet authored Oct 3, 2024
1 parent 153b3fb commit f837369
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
14 changes: 2 additions & 12 deletions homeassistant/components/electric_kiwi/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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
Expand All @@ -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."""
Expand All @@ -38,9 +33,6 @@ async def async_step_reauth(
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(
Expand All @@ -55,7 +47,5 @@ async def async_oauth_create_entry(self, data: dict) -> ConfigFlowResult:
"""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)
2 changes: 2 additions & 0 deletions tests/components/electric_kiwi/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

0 comments on commit f837369

Please sign in to comment.