Remove legacy code. (#54452)
parent
4e07ab1b32
commit
2d669a4613
|
@ -17,7 +17,6 @@ from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.event import async_track_time_interval
|
from homeassistant.helpers.event import async_track_time_interval
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.util.json import load_json
|
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_TRADFRI_GATEWAY,
|
ATTR_TRADFRI_GATEWAY,
|
||||||
|
@ -29,7 +28,6 @@ from .const import (
|
||||||
CONF_IDENTITY,
|
CONF_IDENTITY,
|
||||||
CONF_IMPORT_GROUPS,
|
CONF_IMPORT_GROUPS,
|
||||||
CONF_KEY,
|
CONF_KEY,
|
||||||
CONFIG_FILE,
|
|
||||||
DEFAULT_ALLOW_TRADFRI_GROUPS,
|
DEFAULT_ALLOW_TRADFRI_GROUPS,
|
||||||
DEVICES,
|
DEVICES,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -69,27 +67,10 @@ async def async_setup(hass: HomeAssistant, config: ConfigType):
|
||||||
entry.data.get("host") for entry in hass.config_entries.async_entries(DOMAIN)
|
entry.data.get("host") for entry in hass.config_entries.async_entries(DOMAIN)
|
||||||
]
|
]
|
||||||
|
|
||||||
legacy_hosts = await hass.async_add_executor_job(
|
|
||||||
load_json, hass.config.path(CONFIG_FILE)
|
|
||||||
)
|
|
||||||
|
|
||||||
for host, info in legacy_hosts.items(): # type: ignore
|
|
||||||
if host in configured_hosts:
|
|
||||||
continue
|
|
||||||
|
|
||||||
info[CONF_HOST] = host
|
|
||||||
info[CONF_IMPORT_GROUPS] = conf[CONF_ALLOW_TRADFRI_GROUPS]
|
|
||||||
|
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=info
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
host = conf.get(CONF_HOST)
|
host = conf.get(CONF_HOST)
|
||||||
import_groups = conf[CONF_ALLOW_TRADFRI_GROUPS]
|
import_groups = conf[CONF_ALLOW_TRADFRI_GROUPS]
|
||||||
|
|
||||||
if host is None or host in configured_hosts or host in legacy_hosts:
|
if host is None or host in configured_hosts:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
|
|
|
@ -15,7 +15,6 @@ CONF_IDENTITY = "identity"
|
||||||
CONF_IMPORT_GROUPS = "import_groups"
|
CONF_IMPORT_GROUPS = "import_groups"
|
||||||
CONF_GATEWAY_ID = "gateway_id"
|
CONF_GATEWAY_ID = "gateway_id"
|
||||||
CONF_KEY = "key"
|
CONF_KEY = "key"
|
||||||
CONFIG_FILE = ".tradfri_psk.conf"
|
|
||||||
DEFAULT_ALLOW_TRADFRI_GROUPS = False
|
DEFAULT_ALLOW_TRADFRI_GROUPS = False
|
||||||
DOMAIN = "tradfri"
|
DOMAIN = "tradfri"
|
||||||
KEY_API = "tradfri_api"
|
KEY_API = "tradfri_api"
|
||||||
|
|
|
@ -1,81 +1,12 @@
|
||||||
"""Tests for Tradfri setup."""
|
"""Tests for Tradfri setup."""
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant import config_entries
|
|
||||||
from homeassistant.components import tradfri
|
from homeassistant.components import tradfri
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.setup import async_setup_component
|
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def test_config_yaml_host_not_imported(hass):
|
|
||||||
"""Test that we don't import a configured host."""
|
|
||||||
MockConfigEntry(domain="tradfri", data={"host": "mock-host"}).add_to_hass(hass)
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.tradfri.load_json", return_value={}
|
|
||||||
), patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
|
||||||
assert await async_setup_component(
|
|
||||||
hass, "tradfri", {"tradfri": {"host": "mock-host"}}
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert len(mock_init.mock_calls) == 0
|
|
||||||
|
|
||||||
|
|
||||||
async def test_config_yaml_host_imported(hass):
|
|
||||||
"""Test that we import a configured host."""
|
|
||||||
with patch("homeassistant.components.tradfri.load_json", return_value={}):
|
|
||||||
assert await async_setup_component(
|
|
||||||
hass, "tradfri", {"tradfri": {"host": "mock-host"}}
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
progress = hass.config_entries.flow.async_progress()
|
|
||||||
assert len(progress) == 1
|
|
||||||
assert progress[0]["handler"] == "tradfri"
|
|
||||||
assert progress[0]["context"] == {"source": config_entries.SOURCE_IMPORT}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_config_json_host_not_imported(hass):
|
|
||||||
"""Test that we don't import a configured host."""
|
|
||||||
MockConfigEntry(domain="tradfri", data={"host": "mock-host"}).add_to_hass(hass)
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.tradfri.load_json",
|
|
||||||
return_value={"mock-host": {"key": "some-info"}},
|
|
||||||
), patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
|
||||||
assert await async_setup_component(hass, "tradfri", {"tradfri": {}})
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert len(mock_init.mock_calls) == 0
|
|
||||||
|
|
||||||
|
|
||||||
async def test_config_json_host_imported(
|
|
||||||
hass, mock_gateway_info, mock_entry_setup, gateway_id
|
|
||||||
):
|
|
||||||
"""Test that we import a configured host."""
|
|
||||||
mock_gateway_info.side_effect = lambda hass, host, identity, key: {
|
|
||||||
"host": host,
|
|
||||||
"identity": identity,
|
|
||||||
"key": key,
|
|
||||||
"gateway_id": gateway_id,
|
|
||||||
}
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.tradfri.load_json",
|
|
||||||
return_value={"mock-host": {"key": "some-info"}},
|
|
||||||
):
|
|
||||||
assert await async_setup_component(hass, "tradfri", {"tradfri": {}})
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
config_entry = mock_entry_setup.mock_calls[0][1][1]
|
|
||||||
assert config_entry.domain == "tradfri"
|
|
||||||
assert config_entry.source == config_entries.SOURCE_IMPORT
|
|
||||||
assert config_entry.title == "mock-host"
|
|
||||||
|
|
||||||
|
|
||||||
async def test_entry_setup_unload(hass, api_factory, gateway_id):
|
async def test_entry_setup_unload(hass, api_factory, gateway_id):
|
||||||
"""Test config entry setup and unload."""
|
"""Test config entry setup and unload."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
|
|
Loading…
Reference in New Issue