Add support to reauthorize expired Plex tokens (#40469)

This commit is contained in:
jjlawren authored and GitHub committed 2020-09-28 16:14:54 +02:00
1 parent eda68f127c
commit 3596eb39f2
5 files changed
+116 -18

No files matched your search

+10 -1
View File
@@ -62,9 +62,12 @@ plexapi.X_PLEX_VERSION = X_PLEX_VERSION
class PlexServer:
"""Manages a single Plex server connection."""
def __init__(self, hass, server_config, known_server_id=None, options=None):
def __init__(
self, hass, server_config, known_server_id=None, options=None, entry_id=None
):
"""Initialize a Plex server instance."""
self.hass = hass
self.entry_id = entry_id
self._plex_account = None
self._plex_server = None
self._created_clients = set()
@@ -270,6 +273,12 @@ class PlexServer:
devices, sessions, plextv_clients = await self.hass.async_add_executor_job(
self._fetch_platform_data
)
except plexapi.exceptions.Unauthorized:
_LOGGER.debug(
"Token has expired for '%s', reloading integration", self.friendly_name
)
await self.hass.config_entries.async_reload(self.entry_id)
return
except (
plexapi.exceptions.BadRequest,
requests.exceptions.RequestException,