async def async_migrate_entry(opp: OpenPeerPower, config_entry: ConfigEntry) -> bool: """Migrate config entry to new version.""" if config_entry.version == 1: options = dict(config_entry.options) recipient = options.get(CONF_RECIPIENT) if isinstance(recipient, str): options[CONF_RECIPIENT] = [x.strip() for x in recipient.split(",")] config_entry.version = 2 opp.config_entries.async_update_entry(config_entry, options=options) _LOGGER.info("Migrated config entry to version %d", config_entry.version) return True
async def async_migrate_entry(opp, config_entry: ConfigEntry): """Migrate old entry.""" LOGGER.debug("Migrating from version %s", config_entry.version) if config_entry.version == 1: # Change unique id @callback def update_unique_id(entry): return {"new_unique_id": config_entry.entry_id} await async_migrate_entries(opp, config_entry.entry_id, update_unique_id) config_entry.unique_id = None # Get RTSP port from the camera or use the fallback one and store it in data camera = FoscamCamera( config_entry.data[CONF_HOST], config_entry.data[CONF_PORT], config_entry.data[CONF_USERNAME], config_entry.data[CONF_PASSWORD], verbose=False, ) ret, response = await opp.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") config_entry.data = {**config_entry.data, CONF_RTSP_PORT: rtsp_port} # Change entry version config_entry.version = 2 LOGGER.info("Migration to version %s successful", config_entry.version) return True
async def async_migrate_entry(opp: OpenPeerPower, config_entry: config_entries.ConfigEntry): """Migrate old entry.""" _LOGGER.debug("Migrating from version %s", config_entry.version) if config_entry.version == 1: data = { CONF_RADIO_TYPE: config_entry.data[CONF_RADIO_TYPE], CONF_DEVICE: { CONF_DEVICE_PATH: config_entry.data[CONF_USB_PATH] }, } baudrate = opp.data[DATA_ZHA].get(DATA_ZHA_CONFIG, {}).get(CONF_BAUDRATE) if data[CONF_RADIO_TYPE] != RadioType.deconz and baudrate in BAUD_RATES: data[CONF_DEVICE][CONF_BAUDRATE] = baudrate config_entry.version = 2 opp.config_entries.async_update_entry(config_entry, data=data) _LOGGER.info("Migration to version %s successful", config_entry.version) return True