@@ -234,8 +234,10 @@ def createToken(self, type='delegation', scope='all'):
234234 q = self .query (f'/security/token?type={ type } &scope={ scope } ' )
235235 return q .attrib .get ('token' )
236236
237+ @utils .deprecated ('switchUser is deprecated, use switchHomeUser instead' )
237238 def switchUser (self , user , session = None , timeout = None ):
238- """ Returns a new :class:`~plexapi.server.PlexServer` object logged in as the given username.
239+ """ Deprecated. Use :meth:`~plexapi.server.PlexServer.switchHomeUser` instead.
240+ Returns a new :class:`~plexapi.server.PlexServer` object logged in as the given username.
239241 Note: Only the admin account can switch to other users.
240242
241243 Parameters:
@@ -258,14 +260,38 @@ def switchUser(self, user, session=None, timeout=None):
258260 # Login to the same Plex server using a different account
259261 userPlex = plex.switchUser("Username")
260262
263+ """
264+ return self .switchHomeUser (user , session = session , timeout = timeout )
265+
266+ def switchHomeUser (self , user , pin = None , session = None , timeout = None ):
267+ """ Returns a new :class:`~plexapi.server.PlexServer` object logged in as the given Plex Home user.
268+ Note: Only the admin account can switch to other users.
269+
270+ Parameters:
271+ user (:class:`~plexapi.myplex.MyPlexUser` or str): :class:`~plexapi.myplex.MyPlexUser`,
272+ username, or email of the Plex Home user to switch to.
273+ pin (str): PIN for the Plex Home user (required if the Plex Home user has a PIN set).
274+ session (requests.Session, optional): Use your own session object if you want to
275+ cache the http responses from the server. This will default to the same
276+ session as the current account if no new session is provided.
277+ timeout (int, optional): Timeout in seconds on initial connection to the server.
278+ This will default to the same timeout as the current account if no new timeout is provided.
279+
280+ Example:
281+
282+ .. code-block:: python
283+
284+ from plexapi.server import PlexServer
285+ # Login to the Plex server using the admin token
286+ plex = PlexServer('http://plexserver:32400', token='2ffLuB84dqLswk9skLos')
287+ # Login to the same Plex server using a different Plex Home user account
288+ userPlex = plex.switchHomeUser("Username")
289+
261290 """
262291 from plexapi .myplex import MyPlexUser
263292 user = user if isinstance (user , MyPlexUser ) else self .myPlexAccount ().user (user )
264- userToken = user .get_token (self .machineIdentifier )
265- if session is None :
266- session = self ._session
267- if timeout is None :
268- timeout = self ._timeout
293+ userAccount = self .myPlexAccount ().switchHomeUser (user , pin = pin , session = session , timeout = timeout )
294+ userToken = userAccount .resource (self .machineIdentifier ).accessToken
269295 return PlexServer (self ._baseurl , token = userToken , session = session , timeout = timeout )
270296
271297 @cached_data_property
0 commit comments