diff --git a/homeassistant/components/discovery/__init__.py b/homeassistant/components/discovery/__init__.py index 1e29d066f2d7d..d12e9d2c54bfa 100644 --- a/homeassistant/components/discovery/__init__.py +++ b/homeassistant/components/discovery/__init__.py @@ -37,7 +37,6 @@ SERVICE_MOBILE_APP = "hass_mobile_app" SERVICE_NETGEAR = "netgear_router" SERVICE_OCTOPRINT = "octoprint" -SERVICE_PLEX = "plex_mediaserver" SERVICE_ROKU = "roku" SERVICE_SABNZBD = "sabnzbd" SERVICE_SAMSUNG_PRINTER = "samsung_printer" @@ -51,7 +50,6 @@ SERVICE_DAIKIN: "daikin", SERVICE_TELLDUSLIVE: "tellduslive", SERVICE_IGD: "upnp", - SERVICE_PLEX: "plex", } SERVICE_HANDLERS = { diff --git a/homeassistant/components/plex/config_flow.py b/homeassistant/components/plex/config_flow.py index d61da8609a9a4..84b16817ca89d 100644 --- a/homeassistant/components/plex/config_flow.py +++ b/homeassistant/components/plex/config_flow.py @@ -11,11 +11,10 @@ from homeassistant import config_entries from homeassistant.components.http.view import HomeAssistantView from homeassistant.components.media_player import DOMAIN as MP_DOMAIN -from homeassistant.const import CONF_SSL, CONF_TOKEN, CONF_URL, CONF_VERIFY_SSL +from homeassistant.const import CONF_TOKEN, CONF_URL, CONF_VERIFY_SSL from homeassistant.core import callback from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv -from homeassistant.util.json import load_json from .const import ( # pylint: disable=unused-import AUTH_CALLBACK_NAME, @@ -28,7 +27,6 @@ CONF_USE_EPISODE_ART, DEFAULT_VERIFY_SSL, DOMAIN, - PLEX_CONFIG_FILE, PLEX_SERVER_CONFIG, SERVERS, X_PLEX_DEVICE_NAME, @@ -180,29 +178,6 @@ async def async_step_select_server(self, user_input=None): errors={}, ) - async def async_step_discovery(self, discovery_info): - """Set default host and port from discovery.""" - if self._async_current_entries() or self._async_in_progress(): - # Skip discovery if a config already exists or is in progress. - return self.async_abort(reason="already_configured") - - json_file = self.hass.config.path(PLEX_CONFIG_FILE) - file_config = await self.hass.async_add_executor_job(load_json, json_file) - - if file_config: - host_and_port, host_config = file_config.popitem() - prefix = "https" if host_config[CONF_SSL] else "http" - - server_config = { - CONF_URL: f"{prefix}://{host_and_port}", - CONF_TOKEN: host_config[CONF_TOKEN], - CONF_VERIFY_SSL: host_config["verify"], - } - _LOGGER.info("Imported legacy config, file can be removed: %s", json_file) - return await self.async_step_server_validate(server_config) - - return self.async_abort(reason="discovery_no_file") - async def async_step_import(self, import_config): """Import from Plex configuration.""" _LOGGER.debug("Imported Plex configuration") diff --git a/homeassistant/components/plex/const.py b/homeassistant/components/plex/const.py index 7d6812674ca9a..d5cb3db3aba74 100644 --- a/homeassistant/components/plex/const.py +++ b/homeassistant/components/plex/const.py @@ -15,7 +15,6 @@ SERVERS = "servers" WEBSOCKETS = "websockets" -PLEX_CONFIG_FILE = "plex.conf" PLEX_MEDIA_PLAYER_OPTIONS = "plex_mp_options" PLEX_SERVER_CONFIG = "server_config" diff --git a/homeassistant/components/plex/strings.json b/homeassistant/components/plex/strings.json index cf91b8b6fb7f5..43dc47bec1040 100644 --- a/homeassistant/components/plex/strings.json +++ b/homeassistant/components/plex/strings.json @@ -23,7 +23,6 @@ "all_configured": "All linked servers already configured", "already_configured": "This Plex server is already configured", "already_in_progress": "Plex is being configured", - "discovery_no_file": "No legacy configuration file found", "invalid_import": "Imported configuration is invalid", "non-interactive": "Non-interactive import", "token_request_timeout": "Timed out obtaining token", diff --git a/tests/components/plex/test_config_flow.py b/tests/components/plex/test_config_flow.py index da4c95c145fc3..c131a123dc9fa 100644 --- a/tests/components/plex/test_config_flow.py +++ b/tests/components/plex/test_config_flow.py @@ -7,7 +7,7 @@ import requests.exceptions from homeassistant.components.plex import config_flow -from homeassistant.const import CONF_HOST, CONF_PORT, CONF_SSL, CONF_TOKEN, CONF_URL +from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TOKEN, CONF_URL from homeassistant.setup import async_setup_component from .mock_classes import MOCK_SERVERS, MockPlexAccount, MockPlexServer @@ -65,77 +65,6 @@ async def test_bad_credentials(hass): assert result["errors"]["base"] == "faulty_credentials" -async def test_import_file_from_discovery(hass): - """Test importing a legacy file during discovery.""" - - file_host_and_port, file_config = list(MOCK_FILE_CONTENTS.items())[0] - file_use_ssl = file_config[CONF_SSL] - file_prefix = "https" if file_use_ssl else "http" - used_url = f"{file_prefix}://{file_host_and_port}" - - mock_plex_server = MockPlexServer(ssl=file_use_ssl) - - with patch("plexapi.server.PlexServer", return_value=mock_plex_server), patch( - "homeassistant.components.plex.config_flow.load_json", - return_value=MOCK_FILE_CONTENTS, - ): - - result = await hass.config_entries.flow.async_init( - config_flow.DOMAIN, - context={"source": "discovery"}, - data={ - CONF_HOST: MOCK_SERVERS[0][CONF_HOST], - CONF_PORT: MOCK_SERVERS[0][CONF_PORT], - }, - ) - assert result["type"] == "create_entry" - assert result["title"] == mock_plex_server.friendlyName - assert result["data"][config_flow.CONF_SERVER] == mock_plex_server.friendlyName - assert ( - result["data"][config_flow.CONF_SERVER_IDENTIFIER] - == mock_plex_server.machineIdentifier - ) - assert result["data"][config_flow.PLEX_SERVER_CONFIG][CONF_URL] == used_url - assert ( - result["data"][config_flow.PLEX_SERVER_CONFIG][CONF_TOKEN] - == file_config[CONF_TOKEN] - ) - - -async def test_discovery(hass): - """Test starting a flow from discovery.""" - with patch("homeassistant.components.plex.config_flow.load_json", return_value={}): - result = await hass.config_entries.flow.async_init( - config_flow.DOMAIN, - context={"source": "discovery"}, - data={ - CONF_HOST: MOCK_SERVERS[0][CONF_HOST], - CONF_PORT: MOCK_SERVERS[0][CONF_PORT], - }, - ) - assert result["type"] == "abort" - assert result["reason"] == "discovery_no_file" - - -async def test_discovery_while_in_progress(hass): - """Test starting a flow from discovery.""" - - await hass.config_entries.flow.async_init( - config_flow.DOMAIN, context={"source": "user"} - ) - - result = await hass.config_entries.flow.async_init( - config_flow.DOMAIN, - context={"source": "discovery"}, - data={ - CONF_HOST: MOCK_SERVERS[0][CONF_HOST], - CONF_PORT: MOCK_SERVERS[0][CONF_PORT], - }, - ) - assert result["type"] == "abort" - assert result["reason"] == "already_configured" - - async def test_import_success(hass): """Test a successful configuration import."""