diff --git a/homeassistant/components/home_connect/__init__.py b/homeassistant/components/home_connect/__init__.py index becc78cef90..9f88c6eec68 100644 --- a/homeassistant/components/home_connect/__init__.py +++ b/homeassistant/components/home_connect/__init__.py @@ -378,5 +378,8 @@ async def async_migrate_entry( hass.config_entries.async_update_entry(entry, minor_version=2) + if entry.version == 1 and entry.minor_version == 2: + hass.config_entries.async_update_entry(entry, minor_version=3, unique_id=DOMAIN) + _LOGGER.debug("Migration to version %s successful", entry.version) return True diff --git a/homeassistant/components/home_connect/config_flow.py b/homeassistant/components/home_connect/config_flow.py index 444ea24cb6b..37d6efd4a91 100644 --- a/homeassistant/components/home_connect/config_flow.py +++ b/homeassistant/components/home_connect/config_flow.py @@ -2,6 +2,7 @@ import logging +from homeassistant.config_entries import ConfigFlowResult from homeassistant.helpers import config_entry_oauth2_flow from .const import DOMAIN @@ -14,9 +15,16 @@ class OAuth2FlowHandler( DOMAIN = DOMAIN - MINOR_VERSION = 2 + MINOR_VERSION = 3 @property def logger(self) -> logging.Logger: """Return logger.""" return logging.getLogger(__name__) + + 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: + return self.async_update_reload_and_abort(existing_entry, data=data) + return await super().async_oauth_create_entry(data) diff --git a/tests/components/home_connect/conftest.py b/tests/components/home_connect/conftest.py index ae98c69d242..2342995b749 100644 --- a/tests/components/home_connect/conftest.py +++ b/tests/components/home_connect/conftest.py @@ -84,7 +84,8 @@ def mock_config_entry(token_entry: dict[str, Any]) -> MockConfigEntry: "auth_implementation": FAKE_AUTH_IMPL, "token": token_entry, }, - minor_version=2, + minor_version=3, + unique_id=DOMAIN, ) @@ -101,6 +102,19 @@ def mock_config_entry_v1_1(token_entry: dict[str, Any]) -> MockConfigEntry: ) +@pytest.fixture(name="config_entry_v1_2") +def mock_config_entry_v1_2(token_entry: dict[str, Any]) -> MockConfigEntry: + """Fixture for a config entry.""" + return MockConfigEntry( + domain=DOMAIN, + data={ + "auth_implementation": FAKE_AUTH_IMPL, + "token": token_entry, + }, + minor_version=2, + ) + + @pytest.fixture async def setup_credentials(hass: HomeAssistant) -> None: """Fixture to setup credentials.""" diff --git a/tests/components/home_connect/test_init.py b/tests/components/home_connect/test_init.py index b3d1c4e531f..6534425b329 100644 --- a/tests/components/home_connect/test_init.py +++ b/tests/components/home_connect/test_init.py @@ -406,7 +406,29 @@ async def test_entity_migration( assert entity_registry.async_get_entity_id( domain, DOMAIN, f"{appliance_ha_id}-{expected_unique_id_suffix}" ) - assert config_entry_v1_1.minor_version == 2 + assert config_entry_v1_1.minor_version == 3 + assert config_entry_v1_1.unique_id == DOMAIN + + +async def test_entry_migration( + hass: HomeAssistant, + device_registry: dr.DeviceRegistry, + entity_registry: er.EntityRegistry, + config_entry_v1_2: MockConfigEntry, + appliance_ha_id: str, + platforms: list[Platform], +) -> None: + """Test entity migration.""" + + config_entry_v1_2.add_to_hass(hass) + assert config_entry_v1_2.unique_id != DOMAIN + + with patch("homeassistant.components.home_connect.PLATFORMS", platforms): + await hass.config_entries.async_setup(config_entry_v1_2.entry_id) + await hass.async_block_till_done() + + assert config_entry_v1_2.minor_version == 3 + assert config_entry_v1_2.unique_id == DOMAIN async def test_bsh_key_transformations() -> None: