Remove legacy code. (#54452)

pull/54462/head
jan iversen 2021-08-11 11:07:04 +02:00 committed by GitHub
parent 4e07ab1b32
commit 2d669a4613
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 1 additions and 90 deletions

View File

@ -17,7 +17,6 @@ from homeassistant.exceptions import ConfigEntryNotReady
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.event import async_track_time_interval
from homeassistant.helpers.typing import ConfigType
from homeassistant.util.json import load_json
from .const import (
ATTR_TRADFRI_GATEWAY,
@ -29,7 +28,6 @@ from .const import (
CONF_IDENTITY,
CONF_IMPORT_GROUPS,
CONF_KEY,
CONFIG_FILE,
DEFAULT_ALLOW_TRADFRI_GROUPS,
DEVICES,
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)
]
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)
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
hass.async_create_task(

View File

@ -15,7 +15,6 @@ CONF_IDENTITY = "identity"
CONF_IMPORT_GROUPS = "import_groups"
CONF_GATEWAY_ID = "gateway_id"
CONF_KEY = "key"
CONFIG_FILE = ".tradfri_psk.conf"
DEFAULT_ALLOW_TRADFRI_GROUPS = False
DOMAIN = "tradfri"
KEY_API = "tradfri_api"

View File

@ -1,81 +1,12 @@
"""Tests for Tradfri setup."""
from unittest.mock import patch
from homeassistant import config_entries
from homeassistant.components import tradfri
from homeassistant.helpers import device_registry as dr
from homeassistant.setup import async_setup_component
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):
"""Test config entry setup and unload."""
entry = MockConfigEntry(