From a314caf861f11bebea64a72dd47d4c2051c5ae20 Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Wed, 21 Dec 2022 13:57:23 -0800 Subject: [PATCH] Add `pin` parameter to `switchHomeUser` (#1076) --- plexapi/myplex.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plexapi/myplex.py b/plexapi/myplex.py index eb9499a2..ca3f026a 100644 --- a/plexapi/myplex.py +++ b/plexapi/myplex.py @@ -393,12 +393,13 @@ class MyPlexAccount(PlexObject): url = self.HOMEUSER.format(userId=user.id) return self.query(url, self._session.delete) - def switchHomeUser(self, user): + def switchHomeUser(self, user, pin=None): """ Returns a new :class:`~plexapi.myplex.MyPlexAccount` object switched to the given home user. Parameters: user (:class:`~plexapi.myplex.MyPlexUser` or str): :class:`~plexapi.myplex.MyPlexUser`, username, or email of the home user to switch to. + pin (str): PIN for the home user (required if the home user has a PIN set). Example: @@ -413,9 +414,12 @@ class MyPlexAccount(PlexObject): """ user = user if isinstance(user, MyPlexUser) else self.user(user) url = f'{self.HOMEUSERS}/{user.id}/switch' - data = self.query(url, self._session.post) + params = {} + if pin: + params['pin'] = pin + data = self.query(url, self._session.post, params=params) userToken = data.attrib.get('authenticationToken') - return MyPlexAccount(token=userToken) + return MyPlexAccount(token=userToken, session=self._session) def setPin(self, newPin, currentPin=None): """ Set a new Plex Home PIN for the account.