diff --git a/homeassistant/components/tradfri/__init__.py b/homeassistant/components/tradfri/__init__.py index 8508dab5b96..e2c90098314 100644 --- a/homeassistant/components/tradfri/__init__.py +++ b/homeassistant/components/tradfri/__init__.py @@ -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( diff --git a/homeassistant/components/tradfri/const.py b/homeassistant/components/tradfri/const.py index f7c2bf6cbe5..1f382548263 100644 --- a/homeassistant/components/tradfri/const.py +++ b/homeassistant/components/tradfri/const.py @@ -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" diff --git a/tests/components/tradfri/test_init.py b/tests/components/tradfri/test_init.py index 8e11ab06f34..e8cc83a456c 100644 --- a/tests/components/tradfri/test_init.py +++ b/tests/components/tradfri/test_init.py @@ -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(