Remove manual config flow step (#27291)
This commit is contained in:
parent
73aa341ed8
commit
463c2e8d45
3 changed files with 66 additions and 199 deletions
|
@ -12,14 +12,7 @@ from homeassistant.components.http.view import HomeAssistantView
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
|
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
|
||||||
from homeassistant.const import (
|
from homeassistant.const import CONF_URL, CONF_TOKEN, CONF_SSL, CONF_VERIFY_SSL
|
||||||
CONF_HOST,
|
|
||||||
CONF_PORT,
|
|
||||||
CONF_URL,
|
|
||||||
CONF_TOKEN,
|
|
||||||
CONF_SSL,
|
|
||||||
CONF_VERIFY_SSL,
|
|
||||||
)
|
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.util.json import load_json
|
from homeassistant.util.json import load_json
|
||||||
|
|
||||||
|
@ -30,8 +23,6 @@ from .const import ( # pylint: disable=unused-import
|
||||||
CONF_SERVER_IDENTIFIER,
|
CONF_SERVER_IDENTIFIER,
|
||||||
CONF_USE_EPISODE_ART,
|
CONF_USE_EPISODE_ART,
|
||||||
CONF_SHOW_ALL_CONTROLS,
|
CONF_SHOW_ALL_CONTROLS,
|
||||||
DEFAULT_PORT,
|
|
||||||
DEFAULT_SSL,
|
|
||||||
DEFAULT_VERIFY_SSL,
|
DEFAULT_VERIFY_SSL,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
PLEX_CONFIG_FILE,
|
PLEX_CONFIG_FILE,
|
||||||
|
@ -44,8 +35,6 @@ from .const import ( # pylint: disable=unused-import
|
||||||
from .errors import NoServersFound, ServerNotSpecified
|
from .errors import NoServersFound, ServerNotSpecified
|
||||||
from .server import PlexServer
|
from .server import PlexServer
|
||||||
|
|
||||||
USER_SCHEMA = vol.Schema({vol.Optional("manual_setup"): bool})
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__package__)
|
_LOGGER = logging.getLogger(__package__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,23 +62,17 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Initialize the Plex flow."""
|
"""Initialize the Plex flow."""
|
||||||
self.current_login = {}
|
self.current_login = {}
|
||||||
self.discovery_info = {}
|
|
||||||
self.available_servers = None
|
self.available_servers = None
|
||||||
self.plexauth = None
|
self.plexauth = None
|
||||||
self.token = None
|
self.token = None
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(self, user_input=None):
|
||||||
"""Handle a flow initialized by the user."""
|
"""Handle a flow initialized by the user."""
|
||||||
errors = {}
|
return self.async_show_form(step_id="start_website_auth")
|
||||||
if user_input is not None:
|
|
||||||
if user_input.pop("manual_setup", False):
|
|
||||||
return await self.async_step_manual_setup(user_input)
|
|
||||||
|
|
||||||
return await self.async_step_plex_website_auth()
|
async def async_step_start_website_auth(self, user_input=None):
|
||||||
|
"""Show a form before starting external authentication."""
|
||||||
return self.async_show_form(
|
return await self.async_step_plex_website_auth()
|
||||||
step_id="user", data_schema=USER_SCHEMA, errors=errors
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_step_server_validate(self, server_config):
|
async def async_step_server_validate(self, server_config):
|
||||||
"""Validate a provided configuration."""
|
"""Validate a provided configuration."""
|
||||||
|
@ -120,9 +103,7 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
return self.async_abort(reason="unknown")
|
return self.async_abort(reason="unknown")
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
return self.async_show_form(
|
return self.async_show_form(step_id="start_website_auth", errors=errors)
|
||||||
step_id="user", data_schema=USER_SCHEMA, errors=errors
|
|
||||||
)
|
|
||||||
|
|
||||||
server_id = plex_server.machine_identifier
|
server_id = plex_server.machine_identifier
|
||||||
|
|
||||||
|
@ -152,30 +133,6 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_manual_setup(self, user_input=None):
|
|
||||||
"""Begin manual configuration."""
|
|
||||||
if len(user_input) > 1:
|
|
||||||
host = user_input.pop(CONF_HOST)
|
|
||||||
port = user_input.pop(CONF_PORT)
|
|
||||||
prefix = "https" if user_input.pop(CONF_SSL) else "http"
|
|
||||||
user_input[CONF_URL] = f"{prefix}://{host}:{port}"
|
|
||||||
return await self.async_step_server_validate(user_input)
|
|
||||||
|
|
||||||
data_schema = vol.Schema(
|
|
||||||
{
|
|
||||||
vol.Required(
|
|
||||||
CONF_HOST, default=self.discovery_info.get(CONF_HOST)
|
|
||||||
): str,
|
|
||||||
vol.Required(
|
|
||||||
CONF_PORT, default=self.discovery_info.get(CONF_PORT, DEFAULT_PORT)
|
|
||||||
): int,
|
|
||||||
vol.Optional(CONF_SSL, default=DEFAULT_SSL): bool,
|
|
||||||
vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL): bool,
|
|
||||||
vol.Optional(CONF_TOKEN, default=user_input.get(CONF_TOKEN, "")): str,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return self.async_show_form(step_id="manual_setup", data_schema=data_schema)
|
|
||||||
|
|
||||||
async def async_step_select_server(self, user_input=None):
|
async def async_step_select_server(self, user_input=None):
|
||||||
"""Use selected Plex server."""
|
"""Use selected Plex server."""
|
||||||
config = dict(self.current_login)
|
config = dict(self.current_login)
|
||||||
|
@ -210,8 +167,6 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
# Skip discovery if a config already exists or is in progress.
|
# Skip discovery if a config already exists or is in progress.
|
||||||
return self.async_abort(reason="already_configured")
|
return self.async_abort(reason="already_configured")
|
||||||
|
|
||||||
discovery_info[CONF_PORT] = int(discovery_info[CONF_PORT])
|
|
||||||
self.discovery_info = discovery_info
|
|
||||||
json_file = self.hass.config.path(PLEX_CONFIG_FILE)
|
json_file = self.hass.config.path(PLEX_CONFIG_FILE)
|
||||||
file_config = await self.hass.async_add_executor_job(load_json, json_file)
|
file_config = await self.hass.async_add_executor_job(load_json, json_file)
|
||||||
|
|
||||||
|
@ -227,7 +182,7 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
_LOGGER.info("Imported legacy config, file can be removed: %s", json_file)
|
_LOGGER.info("Imported legacy config, file can be removed: %s", json_file)
|
||||||
return await self.async_step_server_validate(server_config)
|
return await self.async_step_server_validate(server_config)
|
||||||
|
|
||||||
return await self.async_step_user()
|
return self.async_abort(reason="discovery_no_file")
|
||||||
|
|
||||||
async def async_step_import(self, import_config):
|
async def async_step_import(self, import_config):
|
||||||
"""Import from Plex configuration."""
|
"""Import from Plex configuration."""
|
||||||
|
|
|
@ -2,16 +2,6 @@
|
||||||
"config": {
|
"config": {
|
||||||
"title": "Plex",
|
"title": "Plex",
|
||||||
"step": {
|
"step": {
|
||||||
"manual_setup": {
|
|
||||||
"title": "Plex server",
|
|
||||||
"data": {
|
|
||||||
"host": "Host",
|
|
||||||
"port": "Port",
|
|
||||||
"ssl": "Use SSL",
|
|
||||||
"verify_ssl": "Verify SSL certificate",
|
|
||||||
"token": "Token (if required)"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"select_server": {
|
"select_server": {
|
||||||
"title": "Select Plex server",
|
"title": "Select Plex server",
|
||||||
"description": "Multiple servers available, select one:",
|
"description": "Multiple servers available, select one:",
|
||||||
|
@ -19,12 +9,9 @@
|
||||||
"server": "Server"
|
"server": "Server"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"user": {
|
"start_website_auth": {
|
||||||
"title": "Connect Plex server",
|
"title": "Connect Plex server",
|
||||||
"description": "Continue to authorize at plex.tv or manually configure a server.",
|
"description": "Continue to authorize at plex.tv."
|
||||||
"data": {
|
|
||||||
"manual_setup": "Manual setup"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
|
@ -36,6 +23,7 @@
|
||||||
"all_configured": "All linked servers already configured",
|
"all_configured": "All linked servers already configured",
|
||||||
"already_configured": "This Plex server is already configured",
|
"already_configured": "This Plex server is already configured",
|
||||||
"already_in_progress": "Plex is being configured",
|
"already_in_progress": "Plex is being configured",
|
||||||
|
"discovery_no_file": "No legacy config file found",
|
||||||
"invalid_import": "Imported configuration is invalid",
|
"invalid_import": "Imported configuration is invalid",
|
||||||
"token_request_timeout": "Timed out obtaining token",
|
"token_request_timeout": "Timed out obtaining token",
|
||||||
"unknown": "Failed for unknown reason"
|
"unknown": "Failed for unknown reason"
|
||||||
|
|
|
@ -6,14 +6,7 @@ import plexapi.exceptions
|
||||||
import requests.exceptions
|
import requests.exceptions
|
||||||
|
|
||||||
from homeassistant.components.plex import config_flow
|
from homeassistant.components.plex import config_flow
|
||||||
from homeassistant.const import (
|
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_TOKEN, CONF_URL
|
||||||
CONF_HOST,
|
|
||||||
CONF_PORT,
|
|
||||||
CONF_SSL,
|
|
||||||
CONF_VERIFY_SSL,
|
|
||||||
CONF_TOKEN,
|
|
||||||
CONF_URL,
|
|
||||||
)
|
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
@ -48,34 +41,32 @@ def init_config_flow(hass):
|
||||||
|
|
||||||
async def test_bad_credentials(hass):
|
async def test_bad_credentials(hass):
|
||||||
"""Test when provided credentials are rejected."""
|
"""Test when provided credentials are rejected."""
|
||||||
|
mock_connections = MockConnections()
|
||||||
|
mm_plex_account = MagicMock()
|
||||||
|
mm_plex_account.resources = Mock(return_value=[MOCK_SERVER_1])
|
||||||
|
mm_plex_account.resource = Mock(return_value=mock_connections)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
with patch("plexapi.myplex.MyPlexAccount", return_value=mm_plex_account), patch(
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
|
||||||
)
|
|
||||||
assert result["type"] == "form"
|
|
||||||
assert result["step_id"] == "user"
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
|
||||||
result["flow_id"], user_input={"manual_setup": True}
|
|
||||||
)
|
|
||||||
assert result["type"] == "form"
|
|
||||||
assert result["step_id"] == "manual_setup"
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"plexapi.server.PlexServer", side_effect=plexapi.exceptions.Unauthorized
|
"plexapi.server.PlexServer", side_effect=plexapi.exceptions.Unauthorized
|
||||||
|
), asynctest.patch("plexauth.PlexAuth.initiate_auth"), asynctest.patch(
|
||||||
|
"plexauth.PlexAuth.token", return_value="BAD TOKEN"
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_init(
|
||||||
result["flow_id"],
|
config_flow.DOMAIN, context={"source": "user"}
|
||||||
user_input={
|
|
||||||
CONF_HOST: MOCK_HOST_1,
|
|
||||||
CONF_PORT: MOCK_PORT_1,
|
|
||||||
CONF_SSL: False,
|
|
||||||
CONF_VERIFY_SSL: False,
|
|
||||||
CONF_TOKEN: "BAD TOKEN",
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
assert result["type"] == "form"
|
assert result["type"] == "form"
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "start_website_auth"
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
|
assert result["type"] == "external"
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
|
assert result["type"] == "external_done"
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
|
|
||||||
|
assert result["type"] == "form"
|
||||||
|
assert result["step_id"] == "start_website_auth"
|
||||||
assert result["errors"]["base"] == "faulty_credentials"
|
assert result["errors"]["base"] == "faulty_credentials"
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,8 +114,8 @@ async def test_discovery(hass):
|
||||||
context={"source": "discovery"},
|
context={"source": "discovery"},
|
||||||
data={CONF_HOST: MOCK_HOST_1, CONF_PORT: MOCK_PORT_1},
|
data={CONF_HOST: MOCK_HOST_1, CONF_PORT: MOCK_PORT_1},
|
||||||
)
|
)
|
||||||
assert result["type"] == "form"
|
assert result["type"] == "abort"
|
||||||
assert result["step_id"] == "user"
|
assert result["reason"] == "discovery_no_file"
|
||||||
|
|
||||||
|
|
||||||
async def test_discovery_while_in_progress(hass):
|
async def test_discovery_while_in_progress(hass):
|
||||||
|
@ -201,7 +192,7 @@ async def test_import_bad_hostname(hass):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
assert result["type"] == "form"
|
assert result["type"] == "form"
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "start_website_auth"
|
||||||
assert result["errors"]["base"] == "not_found"
|
assert result["errors"]["base"] == "not_found"
|
||||||
|
|
||||||
|
|
||||||
|
@ -212,26 +203,25 @@ async def test_unknown_exception(hass):
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
config_flow.DOMAIN, context={"source": "user"}
|
||||||
)
|
)
|
||||||
assert result["type"] == "form"
|
assert result["type"] == "form"
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "start_website_auth"
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
mock_connections = MockConnections()
|
||||||
result["flow_id"], user_input={"manual_setup": True}
|
mm_plex_account = MagicMock()
|
||||||
)
|
mm_plex_account.resources = Mock(return_value=[MOCK_SERVER_1])
|
||||||
assert result["type"] == "form"
|
mm_plex_account.resource = Mock(return_value=mock_connections)
|
||||||
assert result["step_id"] == "manual_setup"
|
|
||||||
|
|
||||||
with patch("plexapi.server.PlexServer", side_effect=Exception):
|
with patch("plexapi.myplex.MyPlexAccount", return_value=mm_plex_account), patch(
|
||||||
result = await hass.config_entries.flow.async_configure(
|
"plexapi.server.PlexServer", side_effect=Exception
|
||||||
result["flow_id"],
|
), asynctest.patch("plexauth.PlexAuth.initiate_auth"), asynctest.patch(
|
||||||
user_input={
|
"plexauth.PlexAuth.token", return_value="MOCK_TOKEN"
|
||||||
CONF_HOST: MOCK_HOST_1,
|
):
|
||||||
CONF_PORT: MOCK_PORT_1,
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
CONF_SSL: True,
|
assert result["type"] == "external"
|
||||||
CONF_VERIFY_SSL: True,
|
|
||||||
CONF_TOKEN: MOCK_TOKEN,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
|
assert result["type"] == "external_done"
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
assert result["type"] == "abort"
|
assert result["type"] == "abort"
|
||||||
assert result["reason"] == "unknown"
|
assert result["reason"] == "unknown"
|
||||||
|
|
||||||
|
@ -245,7 +235,7 @@ async def test_no_servers_found(hass):
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
config_flow.DOMAIN, context={"source": "user"}
|
||||||
)
|
)
|
||||||
assert result["type"] == "form"
|
assert result["type"] == "form"
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "start_website_auth"
|
||||||
|
|
||||||
mm_plex_account = MagicMock()
|
mm_plex_account = MagicMock()
|
||||||
mm_plex_account.resources = Mock(return_value=[])
|
mm_plex_account.resources = Mock(return_value=[])
|
||||||
|
@ -256,9 +246,7 @@ async def test_no_servers_found(hass):
|
||||||
"plexauth.PlexAuth.token", return_value=MOCK_TOKEN
|
"plexauth.PlexAuth.token", return_value=MOCK_TOKEN
|
||||||
):
|
):
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
result["flow_id"], user_input={"manual_setup": False}
|
|
||||||
)
|
|
||||||
assert result["type"] == "external"
|
assert result["type"] == "external"
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
|
@ -266,7 +254,7 @@ async def test_no_servers_found(hass):
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
assert result["type"] == "form"
|
assert result["type"] == "form"
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "start_website_auth"
|
||||||
assert result["errors"]["base"] == "no_servers"
|
assert result["errors"]["base"] == "no_servers"
|
||||||
|
|
||||||
|
|
||||||
|
@ -279,7 +267,7 @@ async def test_single_available_server(hass):
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
config_flow.DOMAIN, context={"source": "user"}
|
||||||
)
|
)
|
||||||
assert result["type"] == "form"
|
assert result["type"] == "form"
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "start_website_auth"
|
||||||
|
|
||||||
mock_connections = MockConnections()
|
mock_connections = MockConnections()
|
||||||
|
|
||||||
|
@ -304,9 +292,7 @@ async def test_single_available_server(hass):
|
||||||
mock_plex_server.return_value
|
mock_plex_server.return_value
|
||||||
)._baseurl = PropertyMock(return_value=mock_connections.connections[0].httpuri)
|
)._baseurl = PropertyMock(return_value=mock_connections.connections[0].httpuri)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
result["flow_id"], user_input={"manual_setup": False}
|
|
||||||
)
|
|
||||||
assert result["type"] == "external"
|
assert result["type"] == "external"
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
|
@ -336,7 +322,7 @@ async def test_multiple_servers_with_selection(hass):
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
config_flow.DOMAIN, context={"source": "user"}
|
||||||
)
|
)
|
||||||
assert result["type"] == "form"
|
assert result["type"] == "form"
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "start_website_auth"
|
||||||
|
|
||||||
mock_connections = MockConnections()
|
mock_connections = MockConnections()
|
||||||
mm_plex_account = MagicMock()
|
mm_plex_account = MagicMock()
|
||||||
|
@ -360,9 +346,7 @@ async def test_multiple_servers_with_selection(hass):
|
||||||
mock_plex_server.return_value
|
mock_plex_server.return_value
|
||||||
)._baseurl = PropertyMock(return_value=mock_connections.connections[0].httpuri)
|
)._baseurl = PropertyMock(return_value=mock_connections.connections[0].httpuri)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
result["flow_id"], user_input={"manual_setup": False}
|
|
||||||
)
|
|
||||||
assert result["type"] == "external"
|
assert result["type"] == "external"
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
|
@ -406,7 +390,7 @@ async def test_adding_last_unconfigured_server(hass):
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
config_flow.DOMAIN, context={"source": "user"}
|
||||||
)
|
)
|
||||||
assert result["type"] == "form"
|
assert result["type"] == "form"
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "start_website_auth"
|
||||||
|
|
||||||
mock_connections = MockConnections()
|
mock_connections = MockConnections()
|
||||||
mm_plex_account = MagicMock()
|
mm_plex_account = MagicMock()
|
||||||
|
@ -430,9 +414,7 @@ async def test_adding_last_unconfigured_server(hass):
|
||||||
mock_plex_server.return_value
|
mock_plex_server.return_value
|
||||||
)._baseurl = PropertyMock(return_value=mock_connections.connections[0].httpuri)
|
)._baseurl = PropertyMock(return_value=mock_connections.connections[0].httpuri)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
result["flow_id"], user_input={"manual_setup": False}
|
|
||||||
)
|
|
||||||
assert result["type"] == "external"
|
assert result["type"] == "external"
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
|
@ -512,7 +494,7 @@ async def test_all_available_servers_configured(hass):
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
config_flow.DOMAIN, context={"source": "user"}
|
||||||
)
|
)
|
||||||
assert result["type"] == "form"
|
assert result["type"] == "form"
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "start_website_auth"
|
||||||
|
|
||||||
mock_connections = MockConnections()
|
mock_connections = MockConnections()
|
||||||
mm_plex_account = MagicMock()
|
mm_plex_account = MagicMock()
|
||||||
|
@ -525,9 +507,7 @@ async def test_all_available_servers_configured(hass):
|
||||||
"plexauth.PlexAuth.token", return_value=MOCK_TOKEN
|
"plexauth.PlexAuth.token", return_value=MOCK_TOKEN
|
||||||
):
|
):
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
result["flow_id"], user_input={"manual_setup": False}
|
|
||||||
)
|
|
||||||
assert result["type"] == "external"
|
assert result["type"] == "external"
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
|
@ -538,58 +518,6 @@ async def test_all_available_servers_configured(hass):
|
||||||
assert result["reason"] == "all_configured"
|
assert result["reason"] == "all_configured"
|
||||||
|
|
||||||
|
|
||||||
async def test_manual_config(hass):
|
|
||||||
"""Test creating via manual configuration."""
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
|
||||||
)
|
|
||||||
assert result["type"] == "form"
|
|
||||||
assert result["step_id"] == "user"
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
|
||||||
result["flow_id"], user_input={"manual_setup": True}
|
|
||||||
)
|
|
||||||
assert result["type"] == "form"
|
|
||||||
assert result["step_id"] == "manual_setup"
|
|
||||||
|
|
||||||
mock_connections = MockConnections(ssl=True)
|
|
||||||
|
|
||||||
with patch("plexapi.server.PlexServer") as mock_plex_server:
|
|
||||||
type(mock_plex_server.return_value).machineIdentifier = PropertyMock(
|
|
||||||
return_value=MOCK_SERVER_1.clientIdentifier
|
|
||||||
)
|
|
||||||
type(mock_plex_server.return_value).friendlyName = PropertyMock(
|
|
||||||
return_value=MOCK_SERVER_1.name
|
|
||||||
)
|
|
||||||
type( # pylint: disable=protected-access
|
|
||||||
mock_plex_server.return_value
|
|
||||||
)._baseurl = PropertyMock(return_value=mock_connections.connections[0].httpuri)
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
|
||||||
result["flow_id"],
|
|
||||||
user_input={
|
|
||||||
CONF_HOST: MOCK_HOST_1,
|
|
||||||
CONF_PORT: MOCK_PORT_1,
|
|
||||||
CONF_SSL: True,
|
|
||||||
CONF_VERIFY_SSL: True,
|
|
||||||
CONF_TOKEN: MOCK_TOKEN,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
assert result["type"] == "create_entry"
|
|
||||||
assert result["title"] == MOCK_SERVER_1.name
|
|
||||||
assert result["data"][config_flow.CONF_SERVER] == MOCK_SERVER_1.name
|
|
||||||
assert (
|
|
||||||
result["data"][config_flow.CONF_SERVER_IDENTIFIER]
|
|
||||||
== MOCK_SERVER_1.clientIdentifier
|
|
||||||
)
|
|
||||||
assert (
|
|
||||||
result["data"][config_flow.PLEX_SERVER_CONFIG][CONF_URL]
|
|
||||||
== mock_connections.connections[0].httpuri
|
|
||||||
)
|
|
||||||
assert result["data"][config_flow.PLEX_SERVER_CONFIG][CONF_TOKEN] == MOCK_TOKEN
|
|
||||||
|
|
||||||
|
|
||||||
async def test_option_flow(hass):
|
async def test_option_flow(hass):
|
||||||
"""Test config flow selection of one of two bridges."""
|
"""Test config flow selection of one of two bridges."""
|
||||||
|
|
||||||
|
@ -627,15 +555,13 @@ async def test_external_timed_out(hass):
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
config_flow.DOMAIN, context={"source": "user"}
|
||||||
)
|
)
|
||||||
assert result["type"] == "form"
|
assert result["type"] == "form"
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "start_website_auth"
|
||||||
|
|
||||||
with asynctest.patch("plexauth.PlexAuth.initiate_auth"), asynctest.patch(
|
with asynctest.patch("plexauth.PlexAuth.initiate_auth"), asynctest.patch(
|
||||||
"plexauth.PlexAuth.token", return_value=None
|
"plexauth.PlexAuth.token", return_value=None
|
||||||
):
|
):
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
result["flow_id"], user_input={"manual_setup": False}
|
|
||||||
)
|
|
||||||
assert result["type"] == "external"
|
assert result["type"] == "external"
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
|
@ -655,14 +581,12 @@ async def test_callback_view(hass, aiohttp_client):
|
||||||
config_flow.DOMAIN, context={"source": "user"}
|
config_flow.DOMAIN, context={"source": "user"}
|
||||||
)
|
)
|
||||||
assert result["type"] == "form"
|
assert result["type"] == "form"
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "start_website_auth"
|
||||||
|
|
||||||
with asynctest.patch("plexauth.PlexAuth.initiate_auth"), asynctest.patch(
|
with asynctest.patch("plexauth.PlexAuth.initiate_auth"), asynctest.patch(
|
||||||
"plexauth.PlexAuth.token", return_value=MOCK_TOKEN
|
"plexauth.PlexAuth.token", return_value=MOCK_TOKEN
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(result["flow_id"])
|
||||||
result["flow_id"], user_input={"manual_setup": False}
|
|
||||||
)
|
|
||||||
assert result["type"] == "external"
|
assert result["type"] == "external"
|
||||||
|
|
||||||
client = await aiohttp_client(hass.http.app)
|
client = await aiohttp_client(hass.http.app)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue