Stop Plex config flow imports where more user input needed (#29241)

* Abort imports that require user interaction, update logs and tests

* Disable lint
This commit is contained in:
jjlawren authored and Paulus Schoutsen committed 2019-11-30 22:07:12 -08:00
1 parent c4c8a1ba2d
commit 6a02c6540e
3 files changed
+38 -4

No files matched your search

@@ -80,12 +80,17 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Validate a provided configuration."""
errors = {}
self.current_login = server_config
is_importing = (
self.context["source"] # pylint: disable=no-member
== config_entries.SOURCE_IMPORT
)
plex_server = PlexServer(self.hass, server_config)
try:
await self.hass.async_add_executor_job(plex_server.connect)
except NoServersFound:
_LOGGER.error("No servers linked to Plex account")
errors["base"] = "no_servers"
except (plexapi.exceptions.BadRequest, plexapi.exceptions.Unauthorized):
_LOGGER.error("Invalid credentials provided, config not created")
@@ -98,6 +103,11 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
errors["base"] = "not_found"
except ServerNotSpecified as available_servers:
if is_importing:
_LOGGER.warning(
"Imported configuration has multiple available Plex servers. Specify server in configuration or add a new Integration."
)
return self.async_abort(reason="non-interactive")
self.available_servers = available_servers.args[0]
return await self.async_step_select_server()
@@ -106,12 +116,17 @@ class PlexFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
return self.async_abort(reason="unknown")
if errors:
if is_importing:
return self.async_abort(reason="non-interactive")
return self.async_show_form(step_id="start_website_auth", errors=errors)
server_id = plex_server.machine_identifier
for entry in self._async_current_entries():
if entry.data[CONF_SERVER_IDENTIFIER] == server_id:
_LOGGER.debug(
"Plex server already configured: %s", entry.data[CONF_SERVER]
)
return self.async_abort(reason="already_configured")
url = plex_server.url_in_use
@@ -25,6 +25,7 @@
"already_in_progress": "Plex is being configured",
"discovery_no_file": "No legacy config file found",
"invalid_import": "Imported configuration is invalid",
"non-interactive": "Non-interactive import",
"token_request_timeout": "Timed out obtaining token",
"unknown": "Failed for unknown reason"
}