Exemple #1
0
async def async_migrate_entry(hass: HomeAssistant,
                              config_entry: ConfigEntry) -> bool:
    """Migrate old entry."""
    _LOGGER.debug("Migrating from version %d", config_entry.version)

    if config_entry.version == 1:
        new: Dict[str, Any] = {**config_entry.data, CONF_VERIFY_SSL: True}

        device_id = "deviceid"
        devices = new.pop(device_id, {})
        new.pop("show_color_rooms")
        new.pop("live_map")

        new[CONF_DEVICES] = devices.get(device_id, [])

        config_entry.data = {**new}
        config_entry.version = 2

    if config_entry.version == 2:
        new = {**config_entry.data}

        if new.get(CONF_USERNAME) == CONF_BUMPER:
            new[CONF_CLIENT_DEVICE_ID] = get_bumper_device_id(hass)

        config_entry.data = {**new}
        config_entry.version = 3

    _LOGGER.info("Migration to version %d successful", config_entry.version)

    return True
Exemple #2
0
async def async_migrate_entry(hass, config_entry: ConfigEntry):
    """Migrate old entry."""
    LOGGER.debug("Migrating from version %s", config_entry.version)

    if config_entry.version == 1:

        new = {**config_entry.data}
        new[ENABLE_MOTION_SENSOR] = True
        new[CLOUD_PASSWORD] = ""

        config_entry.data = {**new}

        config_entry.version = 2

    if config_entry.version == 2:

        new = {**config_entry.data}
        new[CLOUD_PASSWORD] = ""

        config_entry.data = {**new}

        config_entry.version = 3

    LOGGER.info("Migration to version %s successful", config_entry.version)

    return True
Exemple #3
0
async def async_migrate_entry(hass: HomeAssistant,
                              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 = hass.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
        hass.config_entries.async_update_entry(config_entry, data=data)

    if config_entry.version == 2:
        data = {**config_entry.data}

        if data[CONF_RADIO_TYPE] == "ti_cc":
            data[CONF_RADIO_TYPE] = "znp"

        config_entry.version = 3
        hass.config_entries.async_update_entry(config_entry, data=data)

    _LOGGER.info("Migration to version %s successful", config_entry.version)
    return True
async def async_migrate_entry(hass, config_entry: ConfigEntry):
    """Migrate old entry."""
    LOGGER.debug("Migrating from version %s", config_entry.version)

    if config_entry.version == 1:

        new = {**config_entry.data}
        new[ENABLE_MOTION_SENSOR] = True
        new[CLOUD_PASSWORD] = ""

        config_entry.data = {**new}

        config_entry.version = 2

    if config_entry.version == 2:

        new = {**config_entry.data}
        new[CLOUD_PASSWORD] = ""

        config_entry.data = {**new}

        config_entry.version = 3

    if config_entry.version == 3:

        new = {**config_entry.data}
        new[ENABLE_STREAM] = True

        config_entry.data = {**new}

        config_entry.version = 4

    if config_entry.version == 4:

        new = {**config_entry.data}
        new[ENABLE_TIME_SYNC] = False

        config_entry.data = {**new}

        config_entry.version = 5

    if config_entry.version == 5:

        new = {**config_entry.data}
        new[ENABLE_SOUND_DETECTION] = False
        new[SOUND_DETECTION_PEAK] = -50
        new[SOUND_DETECTION_DURATION] = 1
        new[SOUND_DETECTION_RESET] = 10

        config_entry.data = {**new}

        config_entry.version = 6

    LOGGER.info("Migration to version %s successful", config_entry.version)

    return True
async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry):
    """Migrate old entry."""
    _LOGGER.debug("Migrating from version %s", config_entry.version)

    if config_entry.version == 1:

        MAPPING = {
            "Cozytouch": "atlantic_cozytouch",
            "eedomus": "nexity",
            "Hi Kumo": "hi_kumo_europe",
            "Rexel Energeasy Connect": "rexel",
            "Somfy Connexoon IO": "somfy_europe",
            "Somfy Connexoon RTS": "somfy_oceania",
            "Somfy TaHoma": "somfy_europe",
        }

        entry_data = {**config_entry.data}
        old_hub = entry_data.get(CONF_HUB, "Somfy TaHoma")
        entry_data[CONF_HUB] = MAPPING[old_hub]

        _LOGGER.debug("Migrated %s to %s", old_hub, entry_data[CONF_HUB])

        config_entry.data = {**entry_data}
        config_entry.version = 2

    _LOGGER.debug("Migration to version %s successful", config_entry.version)

    return True
Exemple #6
0
async def async_migrate_entry(
        hass: HomeAssistantType,
        config_entry: config_entries.ConfigEntry) -> bool:
    current_version = config_entry.version
    update_args = {}
    old_data = config_entry.data

    _LOGGER.debug('Migrating entry "%s" (type="%s") from version %s',
                  config_entry.entry_id, config_entry.source, current_version)

    if current_version == 1:
        if config_entry.source != SOURCE_IMPORT:
            new_data = update_args.setdefault('data', {})
            new_data[CONF_USERNAME] = old_data[CONF_USERNAME]
            new_data[CONF_PASSWORD] = old_data[CONF_PASSWORD]

            if CONF_INVERT_INVOICES in old_data:
                new_options = update_args.setdefault('options', {})
                new_options[CONF_INVERT_INVOICES] = old_data[
                    CONF_INVERT_INVOICES]

        current_version = 2

    config_entry.version = current_version

    if update_args:
        _LOGGER.debug('Updating configuration entry "%s" with new data')
        hass.config_entries.async_update_entry(config_entry, **update_args)

    _LOGGER.debug('Migration of entry "%s" to version %s successful',
                  config_entry.entry_id, current_version)
    return True
async def async_migrate_entry(hass: HomeAssistant,
                              config_entry: ConfigEntry) -> bool:
    """Migrate old entry."""
    _LOGGER.debug("Migrating from version %s", config_entry.version)

    #  Flatten configuration but keep old data if user rollbacks HASS prior to 0.106
    if config_entry.version == 1:
        unique_id = config_entry.data[CONF_MAC]
        data = {**config_entry.data, **config_entry.data[CONF_DEVICE]}
        hass.config_entries.async_update_entry(config_entry,
                                               unique_id=unique_id,
                                               data=data)
        config_entry.version = 2

    # Normalise MAC address of device which also affects entity unique IDs
    if config_entry.version == 2 and (old_unique_id := config_entry.unique_id):
        new_unique_id = format_mac(old_unique_id)

        @callback
        def update_unique_id(entity_entry):
            """Update unique ID of entity entry."""
            return {
                "new_unique_id":
                entity_entry.unique_id.replace(old_unique_id, new_unique_id)
            }

        if old_unique_id != new_unique_id:
            await async_migrate_entries(hass, config_entry.entry_id,
                                        update_unique_id)

            hass.config_entries.async_update_entry(config_entry,
                                                   unique_id=new_unique_id)
async def async_migrate_entry(hass, config_entry: ConfigEntry):
    """Migrate old entry."""
    _LOGGER.debug("Migrating from version %s", config_entry.version)

    #  Flatten configuration but keep old data if user rollbacks HASS
    if config_entry.version == 1:

        options = {**config_entry.options}
        options.setdefault(
            OPTIONS_GENERAL, {
                OPTIONS_GENERAL_POLL_INTERVAL:
                config_entry.data.get(CONF_POLL_INTERVAL,
                                      DEFAULT_POLL_INTERVAL)
            })
        config_entry.options = {**options}

        new = {**config_entry.data}
        try:
            new.pop(CONF_POLL_INTERVAL)
            new.pop(
                CONF_OPTIONS
            )  # get rid of errorneously migrated options from integration 1.0
        except:
            pass
        config_entry.data = {**new}

        config_entry.version = 2

    _LOGGER.info("Migration to version %s successful", config_entry.version)

    return True
async def async_migrate_entry(hass: HomeAssistant, 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
        hass.config_entries.async_update_entry(config_entry, options=options)
        _LOGGER.info("Migrated config entry to version %d", config_entry.version)
    if config_entry.version == 2:
        config_entry.version = 3
        data = dict(config_entry.data)
        data[CONF_MAC] = []
        hass.config_entries.async_update_entry(config_entry, data=data)
        _LOGGER.info("Migrated config entry to version %d", config_entry.version)
    return True
Exemple #10
0
async def async_migrate_entry(hass, config_entry: ConfigEntry):
    """Migrate old entry."""
    _LOGGER.debug("Migrating from version %s", config_entry.version)

    if config_entry.version == 1:
        new = {**config_entry.data}
        new[CONF_WEATHER_INTERVAL] = 24
        config_entry.data = {**new}
        config_entry.version = 2

    if config_entry.version == 2:
        new = {**config_entry.data}
        new[CONF_WIND_DIRECTION_TYPE] = DEFAULT_WIND_DIRECTION_TYPE
        config_entry.data = {**new}
        config_entry.version = 3

    _LOGGER.info("Migration to version %s successful", config_entry.version)
    return True
async def async_migrate_entry(hass, config_entry: ConfigEntry):
    """Migrate old entry."""
    _LOGGER.debug("Migrating from version %s", config_entry.version)

    if config_entry.version == 1:
        config_entry.version = 2
        config_entry.data = {"migrate_entities": True}

    return True
Exemple #12
0
async def async_migrate_entry(hass: HomeAssistant, 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
        hass.config_entries.async_update_entry(config_entry, options=options)
        _LOGGER.info("Migrated config entry to version %d", config_entry.version)
    if config_entry.version == 2:
        config_entry.version = 3
        data = dict(config_entry.data)
        data[CONF_MAC] = []
        hass.config_entries.async_update_entry(config_entry, data=data)
        _LOGGER.info("Migrated config entry to version %d", config_entry.version)
    # There can be no longer needed *_from_yaml data and options things left behind
    # from pre-2022.4ish; they can be removed while at it when/if we eventually bump and
    # migrate to version > 3 for some other reason.
    return True
Exemple #13
0
async def async_migrate_entry(hass: HomeAssistantType, config_entry: ConfigEntry):
    """Migrate config entry to new version."""
    if config_entry.version == 1:
        options = config_entry.options
        recipient = options[CONF_RECIPIENT]
        if isinstance(recipient, str):
            options[CONF_RECIPIENT] = [x.strip() for x in recipient.split(",")]
        config_entry.version = 2
        hass.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_config_entry(
    hass: HomeAssistantType, config_entry: ConfigEntry
) -> bool:
    """Migrate config when ConfigFlow version has changed."""
    initial_version = config_entry.version
    current_data = config_entry.data
    _LOGGER.debug("Check for config entry migration of version %d", initial_version)

    if config_entry.version == 1:
        await _async_migrate_entries(
            hass, config_entry.entry_id, _migrate_entity_entry_from_v1_to_v2
        )
        config_entry.version = 2
        current_data = {
            CONF_CONNECTION_TYPE: (
                ConnectionType.MQTT
                if CONF_MQTT_TOPICS in config_entry.data
                else ConnectionType.NETWORK
                if CONF_TCP_HOST in config_entry.data
                else ConnectionType.SERIAL
            ).value,
            CONF_CONNECTION_CONFIG: {**current_data},
        }
        _LOGGER.debug("Config entry migrated to version 2")

    if config_entry.version == 2:
        config_entry.version = 3
        await _async_migrate_entries(
            hass, config_entry.entry_id, _migrate_entity_entry_from_v2_to_v3
        )
        _LOGGER.debug("Config entry migrated to version 3")

    hass.config_entries.async_update_entry(config_entry, data=current_data)
    _LOGGER.debug(
        "Config entry migration from %d to %d successfull.",
        initial_version,
        config_entry.version,
    )

    return True
Exemple #15
0
async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry):
    """Migrate old Config entries."""
    LOGGER.debug("Migrating from version %s", config_entry.version)

    if config_entry.version == 1:
        entry_data = {**config_entry.data}
        entry_data[CONF_ACCOUNT_TYPE] = "production"

        config_entry.data = {**entry_data}
        config_entry.version = 2

    LOGGER.debug("Migration to version %s successful", config_entry.version)

    return True
Exemple #16
0
async def async_migrate_entry(hass, config_entry: ConfigEntry):
    """Migrate old entry."""
    _LOGGER.debug("Migrating from version %s", config_entry.version)

    if config_entry.version == 1:

        new = {**config_entry.data}
        new[CONF_CLIENT_ID] = f"{uuid.uuid4()}"

        config_entry.version = 2
        hass.config_entries.async_update_entry(config_entry, data=new)

    _LOGGER.debug("Migration to version %s successful", config_entry.version)

    return True
Exemple #17
0
async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry):
    """Migrate old entry."""
    _LOGGER.debug("Migrating from version %s", config_entry.version)

    if config_entry.version == 1:

        new = {**config_entry.data}
        new[CONF_REGION] = "US"

        config_entry.version = 2
        hass.config_entries.async_update_entry(config_entry, data=new)

    _LOGGER.info("Migration to version %s successful", config_entry.version)

    return True    
async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry):
    """Migrate old entry."""
    _LOGGER.debug("Migrating from version %s", config_entry.version)

    if config_entry.version == 1:

        new = {**config_entry.data}
        if CONF_FORECASTS_BASENAME in new:
            new[CONF_WEATHER_NAME] = config_entry.data[CONF_FORECASTS_BASENAME]

        config_entry.version = 2
        hass.config_entries.async_update_entry(config_entry, data=new)

    _LOGGER.info("Migration to version %s successful", config_entry.version)
    return True
Exemple #19
0
async def async_migrate_entry(hass, config_entry: ConfigEntry) -> bool:
    """Migrate old schema configuration entry to new."""
    # This function is called when I change VERSION in the ConfigFlow
    # If the config schema ever changes then use this function to convert from old to new config parameters
    _LOGGER.debug("Migrating from version %s", config_entry.version)

    if config_entry.version == 1:
        new = {**config_entry.data}
        # TODO: modify Config Entry data

        config_entry.data = {**new}
        config_entry.version = 2

    _LOGGER.info("Migration to version %s successful", config_entry.version)

    return True
Exemple #20
0
async def async_migrate_entry(hass: HomeAssistant,
                              config_entry: ConfigEntry) -> bool:
    """Migrate config entry."""
    _LOGGER.debug("Migrating from version %s", config_entry.version)

    if config_entry.version == 1:
        config_entry.version = 2
        hass.config_entries.async_update_entry(
            config_entry,
            options={
                CONF_CONSIDER_HOME: DEFAULT_CONSIDER_HOME.total_seconds()
            },
        )

    _LOGGER.info("Migration to version %s successful", config_entry.version)

    return True
Exemple #21
0
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)
    hub = await get_hub(hass, config_entry)
    new = dict(config_entry.data)
    await hub.start()
    cfg = await hub.get_config()
    await hub.stop()
    new.update(cfg)
    _LOGGER.debug(f'new config: %s', new)
    config_entry.data = new
    config_entry.version = ConfigFlow.VERSION

    _LOGGER.info("Migration to version %s successful", config_entry.version)

    return True
Exemple #22
0
async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    """Migrate old entry."""
    if entry.version == 1:
        new_data = {
            CONF_NAME: entry.data[CONF_NAME],
            CONF_LOCATION: {
                CONF_LATITUDE: entry.data[CONF_LATITUDE],
                CONF_LONGITUDE: entry.data[CONF_LONGITUDE],
            },
        }

        if not hass.config_entries.async_update_entry(entry, data=new_data):
            return False

        entry.version = 2

    return True
async def async_migrate_entry(hass, config_entry: ConfigEntry):
    """Migrate old entry."""
    _LOGGER.debug("Migrating from version %s", config_entry.version)

    if config_entry.version == 1:
        new = {
            CONF_NAME: config_entry.data[CONF_NAME],
            CONF_HOST: config_entry.data[CONF_HOST],
            CONF_PORT: config_entry.data[CONF_PORT],
            CONF_SERVER_TYPE: CONF_SERVER_TYPE_JAVA,
        }

        config_entry.data = {**new}
        config_entry.version = 2

    _LOGGER.info("Migration to version %s successful", config_entry.version)

    return True
Exemple #24
0
async def async_migrate_entry(hass, config_entry: ConfigEntry):
    """Migrate old entry."""
    _LOGGER.info("Migrating from version %s", config_entry.version)

    if config_entry.version < 3:
        # save mqtt configuration add bridge definition
        ais_global.save_ais_mqtt_connection_settings(
            ais_global.G_AIS_SUPLA_MQTT_CONFIG_FILE_NAME, config_entry.data)

        # restart mqtt broker
        await hass.services.async_call("ais_shell_command",
                                       "restart_pm2_service",
                                       {"service": "mqtt"})
        config_entry.version = 3

    _LOGGER.info("Migration to version %s successful", config_entry.version)

    return True
Exemple #25
0
async def async_migrate_entry(hass: HomeAssistant,
                              config_entry: ConfigEntry) -> bool:
    """Migrate old entry."""
    _LOGGER.debug("Migrating from version %s", config_entry.version)

    if config_entry.version == 1:
        new = {**config_entry.data}
        # keep verify SSL false for anyone migrating to maintain backwards compatibility
        new[CONF_VERIFY_SSL] = False
        if CONF_DOORBELL_TEXT in new:
            del new[CONF_DOORBELL_TEXT]

        config_entry.version = 2
        hass.config_entries.async_update_entry(config_entry, data=new)

    _LOGGER.info("Migration to version %s successful", config_entry.version)

    return True
Exemple #26
0
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
Exemple #27
0
async def async_migrate_entry(hass, config_entry: ConfigEntry):
    """Migrate old entries merging all of them in one."""
    new_version = ENTRIES_VERSION
    stored_entries = hass.config_entries.async_entries(DOMAIN)
    if config_entry.version == 1:
        _LOGGER.debug("Migrating config entry from version %s",
                      config_entry.version)

        if config_entry.entry_id == stored_entries[0].entry_id:
            _LOGGER.debug("Migrating the first config entry (%s)",
                          config_entry.entry_id)
            new_data = {}
            new_data[CONF_REGION] = "eu"
            new_data[CONF_CLIENT_ID] = ""
            new_data[CONF_CLIENT_SECRET] = ""
            new_data[CONF_USER_ID] = ""
            new_data[CONF_USERNAME] = DOMAIN
            new_data[CONF_NO_CLOUD] = True
            new_data[CONF_DEVICES] = {
                config_entry.data[CONF_DEVICE_ID]: config_entry.data.copy()
            }
            new_data[ATTR_UPDATED_AT] = str(int(time.time() * 1000))
            config_entry.version = new_version
            hass.config_entries.async_update_entry(config_entry,
                                                   title=DOMAIN,
                                                   data=new_data)
        else:
            _LOGGER.debug("Merging the config entry %s into the main one",
                          config_entry.entry_id)
            new_data = stored_entries[0].data.copy()
            new_data[CONF_DEVICES].update(
                {config_entry.data[CONF_DEVICE_ID]: config_entry.data.copy()})
            new_data[ATTR_UPDATED_AT] = str(int(time.time() * 1000))
            hass.config_entries.async_update_entry(stored_entries[0],
                                                   data=new_data)
            await hass.config_entries.async_remove(config_entry.entry_id)

    _LOGGER.info(
        "Entry %s successfully migrated to version %s.",
        config_entry.entry_id,
        new_version,
    )

    return True
Exemple #28
0
async def async_migrate_entry(hass: HomeAssistant,
                              config_entry: ConfigEntry) -> bool:
    """Migrate old entry."""
    _LOGGER.debug("Migrating from version %s", config_entry.version)

    if config_entry.version == 1:
        # Version 1 only accepted username and password auth
        data = {**config_entry.data}

        data[CONF_AUTH_MODE] = CONF_AUTH_PASSWORD
        data[CONF_API_KEY] = None

        hass.config_entries.async_update_entry(config_entry, data=data)

        config_entry.version = 2

    _LOGGER.info("Migration to version %s successful", config_entry.version)

    return True
Exemple #29
0
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, config_entry: ConfigEntry) -> bool:
    """Migrate configuration."""

    version = config_entry.version

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

        data[CONF_CREATION_DATETIME] = str(dt.now())
        hass.config_entries.async_update_entry(
            entry=config_entry,
            unique_id=gen_uuid(data[CONF_CREATION_DATETIME]),
            data=data,
        )
        config_entry.version = 2
        _LOGGER.debug("Migration of to version %s complete", config_entry.version)

    return True