Add method to retrieve Plex server identity (#1204)

* Add server identity

* Add test for server identity
This commit is contained in:
JonnyWong16 2023-08-27 12:06:40 -07:00 committed by GitHub
parent 35008908fc
commit 6471582c92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View file

@ -189,6 +189,11 @@ class PlexServer(PlexObject):
data = self.query(Settings.key) data = self.query(Settings.key)
return Settings(self, data) return Settings(self, data)
def identity(self):
""" Returns the Plex server identity. """
data = self.query('/identity')
return Identity(self, data)
def account(self): def account(self):
""" Returns the :class:`~plexapi.server.Account` object this server belongs to. """ """ Returns the :class:`~plexapi.server.Account` object this server belongs to. """
data = self.query(Account.key) data = self.query(Account.key)
@ -1273,3 +1278,22 @@ class ButlerTask(PlexObject):
self.name = data.attrib.get('name') self.name = data.attrib.get('name')
self.scheduleRandomized = utils.cast(bool, data.attrib.get('scheduleRandomized')) self.scheduleRandomized = utils.cast(bool, data.attrib.get('scheduleRandomized'))
self.title = data.attrib.get('title') self.title = data.attrib.get('title')
class Identity(PlexObject):
""" Represents a server identity.
Attributes:
claimed (bool): True or False if the server is claimed.
machineIdentifier (str): The Plex server machine identifier.
version (str): The Plex server version.
"""
def __repr__(self):
return f"<{self.__class__.__name__}:{self.machineIdentifier}>"
def _loadData(self, data):
self._data = data
self.claimed = utils.cast(bool, data.attrib.get('claimed'))
self.machineIdentifier = data.attrib.get('machineIdentifier')
self.version = data.attrib.get('version')

View file

@ -566,3 +566,8 @@ def test_server_agents(plex):
setting = next((s for s in settings if s.id == 'country'), None) setting = next((s for s in settings if s.id == 'country'), None)
assert setting assert setting
assert setting.enumValues is not None assert setting.enumValues is not None
def test_server_identity(plex):
identity = plex.identity()
assert identity.machineIdentifier == plex.machineIdentifier