custom_components/keymaster/__init__.py
async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
    """Migrate an old config entry."""
    version = config_entry.version

    # 1 -> 2: Migrate to new keys
    if version == 1:
        _LOGGER.debug("Migrating from version %s", version)
        data = config_entry.data.copy()

        data[CONF_ALARM_LEVEL_OR_USER_CODE_ENTITY_ID] = data.pop(CONF_ALARM_LEVEL, None)
        data[CONF_ALARM_TYPE_OR_ACCESS_CONTROL_ENTITY_ID] = data.pop(
            CONF_ALARM_TYPE, None
        )
        data[CONF_LOCK_ENTITY_ID] = data.pop(CONF_ENTITY_ID)
        if CONF_HIDE_PINS not in data:
            data[CONF_HIDE_PINS] = DEFAULT_HIDE_PINS
        data[CONF_CHILD_LOCKS_FILE] = data.get(CONF_CHILD_LOCKS_FILE, "")

        hass.config_entries.async_update_entry(entry=config_entry, data=data)
        config_entry.version = 2
        _LOGGER.debug("Migration to version %s complete", config_entry.version)

    return True
Migrate an old config entry.
Migrate an old config entry.
Migrate an old config entry .
async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
    version = config_entry.version
    if version == 1:
        _LOGGER.debug("Migrating from version %s", version)
        data = config_entry.data.copy()
        data[CONF_ALARM_LEVEL_OR_USER_CODE_ENTITY_ID] = data.pop(CONF_ALARM_LEVEL, None)
        data[CONF_ALARM_TYPE_OR_ACCESS_CONTROL_ENTITY_ID] = data.pop(
            CONF_ALARM_TYPE, None
        )
        data[CONF_LOCK_ENTITY_ID] = data.pop(CONF_ENTITY_ID)
        if CONF_HIDE_PINS not in data:
            data[CONF_HIDE_PINS] = DEFAULT_HIDE_PINS
        data[CONF_CHILD_LOCKS_FILE] = data.get(CONF_CHILD_LOCKS_FILE, "")
        hass.config_entries.async_update_entry(entry=config_entry, data=data)
        config_entry.version = 2
        _LOGGER.debug("Migration to version %s complete", config_entry.version)
    return True
async def async_migrate_entry ( hass : HomeAssistant , config_entry : ConfigEntry ) -> bool : version = config_entry . version if version == 1 : _LOGGER . debug ( "Migrating from version %s" , version ) data = config_entry . data . copy ( ) data [ CONF_ALARM_LEVEL_OR_USER_CODE_ENTITY_ID ] = data . pop ( CONF_ALARM_LEVEL , None ) data [ CONF_ALARM_TYPE_OR_ACCESS_CONTROL_ENTITY_ID ] = data . pop ( CONF_ALARM_TYPE , None ) data [ CONF_LOCK_ENTITY_ID ] = data . pop ( CONF_ENTITY_ID ) if CONF_HIDE_PINS not in data : data [ CONF_HIDE_PINS ] = DEFAULT_HIDE_PINS data [ CONF_CHILD_LOCKS_FILE ] = data . get ( CONF_CHILD_LOCKS_FILE , "" ) hass . config_entries . async_update_entry ( entry = config_entry , data = data ) config_entry . version = 2 _LOGGER . debug ( "Migration to version %s complete" , config_entry . version ) return True
Migrate an old config entry.
Migrate an old config entry .
"""Migrate an old config entry.""" # 1 -> 2: Migrate to new keys
hass
HomeAssistant
config_entry
ConfigEntry