Skip to content

Commit

Permalink
Remove discovery and legacy config file loading for Plex (home-assist…
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob authored Mar 5, 2020
1 parent 8aea538 commit 4717d07
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 102 deletions.
2 changes: 0 additions & 2 deletions homeassistant/components/discovery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -51,7 +50,6 @@
SERVICE_DAIKIN: "daikin",
SERVICE_TELLDUSLIVE: "tellduslive",
SERVICE_IGD: "upnp",
SERVICE_PLEX: "plex",
}

SERVICE_HANDLERS = {
Expand Down
27 changes: 1 addition & 26 deletions homeassistant/components/plex/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -28,7 +27,6 @@
CONF_USE_EPISODE_ART,
DEFAULT_VERIFY_SSL,
DOMAIN,
PLEX_CONFIG_FILE,
PLEX_SERVER_CONFIG,
SERVERS,
X_PLEX_DEVICE_NAME,
Expand Down Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/plex/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 0 additions & 1 deletion homeassistant/components/plex/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
73 changes: 1 addition & 72 deletions tests/components/plex/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""

Expand Down

0 comments on commit 4717d07

Please sign in to comment.