Make sure OpenAI integration migration is clean (#147627)

This commit is contained in:
Joost Lekkerkerker 2025-06-26 23:03:11 +02:00 committed by Franck Nijhof
parent 3fc154e1d7
commit c2c388e0cc
No known key found for this signature in database
GPG Key ID: AB33ADACE7101952
2 changed files with 16 additions and 0 deletions

View File

@ -346,6 +346,12 @@ async def async_migrate_integration(hass: HomeAssistant) -> None:
device.id,
remove_config_entry_id=entry.entry_id,
)
else:
device_registry.async_update_device(
device.id,
remove_config_entry_id=entry.entry_id,
remove_config_subentry_id=None,
)
if not use_existing:
await hass.config_entries.async_remove(entry.entry_id)

View File

@ -618,6 +618,10 @@ async def test_migration_from_v1_to_v2(
)
assert migrated_device.identifiers == {(DOMAIN, subentry.subentry_id)}
assert migrated_device.id == device.id
assert migrated_device.config_entries == {mock_config_entry.entry_id}
assert migrated_device.config_entries_subentries == {
mock_config_entry.entry_id: {subentry.subentry_id}
}
async def test_migration_from_v1_to_v2_with_multiple_keys(
@ -709,6 +713,8 @@ async def test_migration_from_v1_to_v2_with_multiple_keys(
identifiers={(DOMAIN, list(entry.subentries.values())[0].subentry_id)}
)
assert dev is not None
assert dev.config_entries == {entry.entry_id}
assert dev.config_entries_subentries == {entry.entry_id: {subentry.subentry_id}}
async def test_migration_from_v1_to_v2_with_same_keys(
@ -808,6 +814,10 @@ async def test_migration_from_v1_to_v2_with_same_keys(
identifiers={(DOMAIN, subentry.subentry_id)}
)
assert dev is not None
assert dev.config_entries == {mock_config_entry.entry_id}
assert dev.config_entries_subentries == {
mock_config_entry.entry_id: {subentry.subentry_id}
}
@pytest.mark.parametrize("mock_subentry_data", [{}, {CONF_CHAT_MODEL: "gpt-1o"}])