Remove manual config flow step (#27291)
This commit is contained in:
1 parent
73aa341ed8
commit
463c2e8d45
3 files changed
+66
-199
No files matched your search
@@ -12,14 +12,7 @@ from homeassistant.components.http.view import HomeAssistantView
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_PORT,
|
||||
CONF_URL,
|
||||
CONF_TOKEN,
|
||||
CONF_SSL,
|
||||
CONF_VERIFY_SSL,
|
||||
)
|
||||
from homeassistant.const import CONF_URL, CONF_TOKEN, CONF_SSL, CONF_VERIFY_SSL
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.util.json import load_json
|
||||
|
||||
@@ -30,8 +23,6 @@ from .const import ( # pylint: disable=unused-import
|
||||
CONF_SERVER_IDENTIFIER,
|
||||
CONF_USE_EPISODE_ART,
|
||||
CONF_SHOW_ALL_CONTROLS,
|
||||
DEFAULT_PORT,
|
||||
DEFAULT_SSL,
|
||||
DEFAULT_VERIFY_SSL,
|
||||
DOMAIN,
|
||||
PLEX_CONFIG_FILE,
|
||||
@@ -44,8 +35,6 @@ from .const import ( # pylint: disable=unused-import
|
||||
from .errors import NoServersFound, ServerNotSpecified
|
||||
from .server import PlexServer
|
||||
|
||||
USER_SCHEMA = vol.Schema({vol.Optional("manual_setup"): bool})
|
||||
|
||||
_LOGGER = logging.getLogger(__package__)
|
||||
|
||||
|
||||
@@ -73,23 +62,17 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
def __init__(self):
|
||||
"""Initialize the Plex flow."""
|
||||
self.current_login = {}
|
||||
self.discovery_info = {}
|
||||
self.available_servers = None
|
||||
self.plexauth = None
|
||||
self.token = None
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Handle a flow initialized by the user."""
|
||||
errors = {}
|
||||
if user_input is not None:
|
||||
if user_input.pop("manual_setup", False):
|
||||
return await self.async_step_manual_setup(user_input)
|
||||
return self.async_show_form(step_id="start_website_auth")
|
||||
|
||||
return await self.async_step_plex_website_auth()
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="user", data_schema=USER_SCHEMA, errors=errors
|
||||
)
|
||||
async def async_step_start_website_auth(self, user_input=None):
|
||||
"""Show a form before starting external authentication."""
|
||||
return await self.async_step_plex_website_auth()
|
||||
|
||||
async def async_step_server_validate(self, server_config):
|
||||
"""Validate a provided configuration."""
|
||||
@@ -120,9 +103,7 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
return self.async_abort(reason="unknown")
|
||||
|
||||
if errors:
|
||||
return self.async_show_form(
|
||||
step_id="user", data_schema=USER_SCHEMA, errors=errors
|
||||
)
|
||||
return self.async_show_form(step_id="start_website_auth", errors=errors)
|
||||
|
||||
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):
|
||||
"""Use selected Plex server."""
|
||||
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.
|
||||
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)
|
||||
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)
|
||||
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):
|
||||
"""Import from Plex configuration."""
|
||||
|
||||
@@ -2,16 +2,6 @@
|
||||
"config": {
|
||||
"title": "Plex",
|
||||
"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": {
|
||||
"title": "Select Plex server",
|
||||
"description": "Multiple servers available, select one:",
|
||||
@@ -19,12 +9,9 @@
|
||||
"server": "Server"
|
||||
}
|
||||
},
|
||||
"user": {
|
||||
"start_website_auth": {
|
||||
"title": "Connect Plex server",
|
||||
"description": "Continue to authorize at plex.tv or manually configure a server.",
|
||||
"data": {
|
||||
"manual_setup": "Manual setup"
|
||||
}
|
||||
"description": "Continue to authorize at plex.tv."
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
@@ -36,6 +23,7 @@
|
||||
"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 config file found",
|
||||
"invalid_import": "Imported configuration is invalid",
|
||||
"token_request_timeout": "Timed out obtaining token",
|
||||
"unknown": "Failed for unknown reason"
|
||||
|
||||
Reference in new issue
Block a user