mirror of
https://github.com/home-assistant/core.git
synced 2025-08-13 17:45:19 +02:00
Use unique ID for Home connect config entry
This commit is contained in:
committed by
GitHub
parent
aa9b526e27
commit
4241317469
@@ -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
|
||||
|
@@ -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)
|
||||
|
@@ -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."""
|
||||
|
@@ -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:
|
||||
|
Reference in New Issue
Block a user