Skip to content

Commit

Permalink
Add pin parameter to switchHomeUser (#1076)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyWong16 authored Dec 21, 2022
1 parent 9b8c7d5 commit a314caf
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions plexapi/myplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,13 @@ def removeHomeUser(self, user):
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:
Expand All @@ -413,9 +414,12 @@ def switchHomeUser(self, user):
"""
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.
Expand Down

0 comments on commit a314caf

Please sign in to comment.