mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Remove discovery and legacy config file loading for Plex (#32510)
This commit is contained in:
parent
8aea538662
commit
4717d072c9
@ -37,7 +37,6 @@ SERVICE_KONNECTED = "konnected"
|
||||
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 @@ CONFIG_ENTRY_HANDLERS = {
|
||||
SERVICE_DAIKIN: "daikin",
|
||||
SERVICE_TELLDUSLIVE: "tellduslive",
|
||||
SERVICE_IGD: "upnp",
|
||||
SERVICE_PLEX: "plex",
|
||||
}
|
||||
|
||||
SERVICE_HANDLERS = {
|
||||
|
@ -11,11 +11,10 @@ import voluptuous as vol
|
||||
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 @@ from .const import ( # pylint: disable=unused-import
|
||||
CONF_USE_EPISODE_ART,
|
||||
DEFAULT_VERIFY_SSL,
|
||||
DOMAIN,
|
||||
PLEX_CONFIG_FILE,
|
||||
PLEX_SERVER_CONFIG,
|
||||
SERVERS,
|
||||
X_PLEX_DEVICE_NAME,
|
||||
@ -180,29 +178,6 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
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")
|
||||
|
@ -15,7 +15,6 @@ PLATFORMS_COMPLETED = "platforms_completed"
|
||||
SERVERS = "servers"
|
||||
WEBSOCKETS = "websockets"
|
||||
|
||||
PLEX_CONFIG_FILE = "plex.conf"
|
||||
PLEX_MEDIA_PLAYER_OPTIONS = "plex_mp_options"
|
||||
PLEX_SERVER_CONFIG = "server_config"
|
||||
|
||||
|
@ -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",
|
||||
|
@ -7,7 +7,7 @@ import plexapi.exceptions
|
||||
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."""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user