Skip to content

Commit

Permalink
Store toon flow data in flow handler attributes (home-assistant#127180)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored Oct 1, 2024
1 parent eb1fe93 commit d9bba25
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions homeassistant/components/toon/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ToonFlowHandler(AbstractOAuth2FlowHandler, domain=DOMAIN):

agreements: list[Agreement]
data: dict[str, Any]
migrate_entry: str | None = None

@property
def logger(self) -> logging.Logger:
Expand Down Expand Up @@ -58,7 +59,7 @@ async def async_step_import(
"""

if import_data is not None and CONF_MIGRATE in import_data:
self.context.update({CONF_MIGRATE: import_data[CONF_MIGRATE]})
self.migrate_entry = import_data[CONF_MIGRATE]
else:
await self._async_handle_discovery_without_unique_id()

Expand Down Expand Up @@ -88,8 +89,8 @@ async def async_step_agreement(
return await self._create_entry(self.agreements[agreement_index])

async def _create_entry(self, agreement: Agreement) -> ConfigFlowResult:
if CONF_MIGRATE in self.context:
await self.hass.config_entries.async_remove(self.context[CONF_MIGRATE])
if self.migrate_entry:
await self.hass.config_entries.async_remove(self.migrate_entry)

await self.async_set_unique_id(agreement.agreement_id)
self._abort_if_unique_id_configured()
Expand Down
5 changes: 3 additions & 2 deletions tests/components/toon/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest
from toonapi import Agreement, ToonError

from homeassistant.components.toon.const import CONF_AGREEMENT, CONF_MIGRATE, DOMAIN
from homeassistant.components.toon.const import CONF_AGREEMENT, DOMAIN
from homeassistant.config import async_process_ha_core_config
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
Expand Down Expand Up @@ -324,7 +324,8 @@ async def test_import_migration(

flows = hass.config_entries.flow.async_progress()
assert len(flows) == 1
assert flows[0]["context"][CONF_MIGRATE] == old_entry.entry_id
flow = hass.config_entries.flow._progress[flows[0]["flow_id"]]
assert flow.migrate_entry == old_entry.entry_id

state = config_entry_oauth2_flow._encode_jwt(
hass,
Expand Down

0 comments on commit d9bba25

Please sign in to comment.