mirror of
https://github.com/home-assistant/core
synced 2024-09-15 17:29:45 +02:00
Migrate tplink hosts that were previously imported from yaml (#57308)
This commit is contained in:
parent
ba83433c64
commit
e77fae56d9
@ -120,6 +120,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
async_migrate_legacy_entries(
|
||||
hass, hosts_by_mac, config_entries_by_mac, legacy_entry
|
||||
)
|
||||
# Migrate the yaml entry that was previously imported
|
||||
async_migrate_yaml_entries(hass, legacy_entry.data)
|
||||
|
||||
if conf is not None:
|
||||
async_migrate_yaml_entries(hass, conf)
|
||||
|
@ -2,6 +2,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from types import MappingProxyType
|
||||
from typing import Any
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
@ -65,7 +67,9 @@ def async_migrate_legacy_entries(
|
||||
|
||||
|
||||
@callback
|
||||
def async_migrate_yaml_entries(hass: HomeAssistant, conf: ConfigType) -> None:
|
||||
def async_migrate_yaml_entries(
|
||||
hass: HomeAssistant, conf: ConfigType | MappingProxyType[str, Any]
|
||||
) -> None:
|
||||
"""Migrate yaml to config entries."""
|
||||
for device_type in (CONF_LIGHT, CONF_SWITCH, CONF_STRIP, CONF_DIMMER):
|
||||
for device in conf.get(device_type, []):
|
||||
|
@ -239,3 +239,25 @@ async def test_migrate_from_yaml(hass: HomeAssistant):
|
||||
|
||||
assert migrated_entry is not None
|
||||
assert migrated_entry.data[CONF_HOST] == IP_ADDRESS
|
||||
|
||||
|
||||
async def test_migrate_from_legacy_entry(hass: HomeAssistant):
|
||||
"""Test migrate from legacy entry that was already imported from yaml."""
|
||||
data = {
|
||||
CONF_DISCOVERY: False,
|
||||
CONF_SWITCH: [{CONF_HOST: IP_ADDRESS}],
|
||||
}
|
||||
config_entry = MockConfigEntry(domain=DOMAIN, data=data, unique_id=DOMAIN)
|
||||
config_entry.add_to_hass(hass)
|
||||
with _patch_discovery(), _patch_single_discovery():
|
||||
await setup.async_setup_component(hass, DOMAIN, {})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
migrated_entry = None
|
||||
for entry in hass.config_entries.async_entries(DOMAIN):
|
||||
if entry.unique_id == MAC_ADDRESS:
|
||||
migrated_entry = entry
|
||||
break
|
||||
|
||||
assert migrated_entry is not None
|
||||
assert migrated_entry.data[CONF_HOST] == IP_ADDRESS
|
||||
|
Loading…
Reference in New Issue
Block a user