async def async_migrate_entry(hass, config_entry: ConfigEntry): """Migrate old entry.""" _LOGGER.debug("Migrating from version %s", config_entry.version) update = False new = {**config_entry.data} if config_entry.version == 1: config_entry.unique_id = f'{DOMAIN}_{config_entry.data[CONF_HOST]}_{config_entry.data[CONF_PORT]}' update = True if update: _LOGGER.info("Migration from version %s to %s successful", config_entry.version, CONFIG_VERSION) config_entry.version = CONFIG_VERSION hass.config_entries.async_update_entry(config_entry, data=new) return True
async def async_migrate_entry(hass, config_entry: ConfigEntry): """Migrate old entry.""" _LOGGER.debug("Migrating from version %s to version %s", config_entry.version, CONFIGFLOW_VERSION) new_data = {**config_entry.data} new_options = {**config_entry.options} if config_entry.version == 1: config_entry.unique_id = config_entry.data["unique_id"] del new_data["unique_id"] config_entry.version = CONFIGFLOW_VERSION config_entry.data = {**new_data} _LOGGER.info("Migration of entry %s done to version %s", config_entry.title, config_entry.version) return True _LOGGER.info("Migration not required") return True
async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Migrate old entry.""" LOGGER.debug("Migrating from version %s", entry.version) if entry.version == 1: # Change unique id @callback def update_unique_id(entry): return {"new_unique_id": entry.entry_id} await async_migrate_entries(hass, entry.entry_id, update_unique_id) entry.unique_id = None # Get RTSP port from the camera or use the fallback one and store it in data camera = FoscamCamera( entry.data[CONF_HOST], entry.data[CONF_PORT], entry.data[CONF_USERNAME], entry.data[CONF_PASSWORD], verbose=False, ) ret, response = await hass.async_add_executor_job(camera.get_port_info) rtsp_port = DEFAULT_RTSP_PORT if ret != 0: rtsp_port = response.get("rtspPort") or response.get("mediaPort") hass.config_entries.async_update_entry( entry, data={ **entry.data, CONF_RTSP_PORT: rtsp_port }) # Change entry version entry.version = 2 LOGGER.info("Migration to version %s successful", entry.version) return True
async def async_migrate_entry(hass, config_entry: ConfigEntry): """Migrate old entry.""" _LOGGER.debug("Migrating from version %s to version %s", config_entry.version, CONFIGFLOW_VERSION) new_data = {**config_entry.data} new_options = {**config_entry.options} if config_entry.version <= 2: _LOGGER.warning( "Impossible to migrate config version from version %s to version %s.\r\nPlease consider to delete and recreate the entry.", config_entry.version, CONFIGFLOW_VERSION) return False elif config_entry.version == 3: config_entry.unique_id = config_entry.data["unique_id"] del new_data["unique_id"] config_entry.version = CONFIGFLOW_VERSION config_entry.data = {**new_data} _LOGGER.info("Migration of entry %s done to version %s", config_entry.title, config_entry.version) return True _LOGGER.info("Migration not required") return True