Fix Verisure config entry migration (#98546)

This commit is contained in:
G Johansson 2023-08-17 08:51:59 +02:00 committed by GitHub
parent fde498586e
commit 6faa9abc75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 13 deletions

View File

@ -83,21 +83,22 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
LOGGER.debug("Migrating from version %s", entry.version)
if entry.version == 1:
config_entry_default_code = entry.options.get(CONF_LOCK_DEFAULT_CODE)
entity_reg = er.async_get(hass)
entries = er.async_entries_for_config_entry(entity_reg, entry.entry_id)
for entity in entries:
if entity.entity_id.startswith("lock"):
entity_reg.async_update_entity_options(
entity.entity_id,
LOCK_DOMAIN,
{CONF_DEFAULT_CODE: config_entry_default_code},
)
new_options = entry.options.copy()
del new_options[CONF_LOCK_DEFAULT_CODE]
if config_entry_default_code := entry.options.get(CONF_LOCK_DEFAULT_CODE):
entity_reg = er.async_get(hass)
entries = er.async_entries_for_config_entry(entity_reg, entry.entry_id)
for entity in entries:
if entity.entity_id.startswith("lock"):
entity_reg.async_update_entity_options(
entity.entity_id,
LOCK_DOMAIN,
{CONF_DEFAULT_CODE: config_entry_default_code},
)
new_options = entry.options.copy()
del new_options[CONF_LOCK_DEFAULT_CODE]
hass.config_entries.async_update_entry(entry, options=new_options)
entry.version = 2
hass.config_entries.async_update_entry(entry, options=new_options)
LOGGER.info("Migration to version %s successful", entry.version)