Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions plexapi/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,41 @@ def createToken(self, type='delegation', scope='all'):
return q.attrib.get('token')

def systemAccounts(self):
""" Returns a list of :class:`~plexapi.server.SystemAccounts` objects this server contains. """
""" Returns a list of :class:`~plexapi.server.SystemAccount` objects this server contains. """
if self._systemAccounts is None:
key = '/accounts'
self._systemAccounts = self.fetchItems(key, SystemAccount)
return self._systemAccounts

def systemAccount(self, accountID):
""" Returns the :class:`~plexapi.server.SystemAccount` object for the specified account ID.

Parameters:
accountID (int): The :class:`~plexapi.server.SystemAccount` ID.
"""
try:
return next(account for account in self.systemAccounts() if account.id == accountID)
except StopIteration:
raise NotFound('Unknown account with accountID=%s' % accountID) from None

def systemDevices(self):
""" Returns a list of :class:`~plexapi.server.SystemDevices` objects this server contains. """
""" Returns a list of :class:`~plexapi.server.SystemDevice` objects this server contains. """
if self._systemDevices is None:
key = '/devices'
self._systemDevices = self.fetchItems(key, SystemDevice)
return self._systemDevices

def systemDevice(self, deviceID):
""" Returns the :class:`~plexapi.server.SystemDevice` object for the specified device ID.

Parameters:
deviceID (int): The :class:`~plexapi.server.SystemDevice` ID.
"""
try:
return next(device for device in self.systemDevices() if device.id == deviceID)
except StopIteration:
raise NotFound('Unknown device with deviceID=%s' % deviceID) from None

def myPlexAccount(self):
""" Returns a :class:`~plexapi.myplex.MyPlexAccount` object using the same
token to access this server. If you are not the owner of this PlexServer
Expand Down Expand Up @@ -842,6 +864,7 @@ class SystemDevice(PlexObject):

Attributes:
TAG (str): 'Device'
clientIdentifier (str): The unique identifier for the device.
createdAt (datatime): Datetime the device was created.
id (int): The ID of the device (not the same as :class:`~plexapi.myplex.MyPlexDevice` ID).
key (str): API URL (/devices/<id>)
Expand All @@ -852,6 +875,7 @@ class SystemDevice(PlexObject):

def _loadData(self, data):
self._data = data
self.clientIdentifier = data.attrib.get('clientIdentifier')
self.createdAt = utils.toDatetime(data.attrib.get('createdAt'))
self.id = cast(int, data.attrib.get('id'))
self.key = '/devices/%s' % self.id
Expand Down Expand Up @@ -894,19 +918,11 @@ def __repr__(self):

def account(self):
""" Returns the :class:`~plexapi.server.SystemAccount` associated with the bandwidth data. """
accounts = self._server.systemAccounts()
try:
return next(account for account in accounts if account.id == self.accountID)
except StopIteration:
raise NotFound('Unknown account for this bandwidth data: accountID=%s' % self.accountID)
return self._server.systemAccount(self.accountID)

def device(self):
""" Returns the :class:`~plexapi.server.SystemDevice` associated with the bandwidth data. """
devices = self._server.systemDevices()
try:
return next(device for device in devices if device.id == self.deviceID)
except StopIteration:
raise NotFound('Unknown device for this bandwidth data: deviceID=%s' % self.deviceID)
return self._server.systemDevice(self.deviceID)


class StatisticsResources(PlexObject):
Expand Down
3 changes: 3 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,17 +388,20 @@ def test_server_system_accounts(plex):
assert account.thumb == ""
assert account.accountID == account.id
assert account.accountKey == account.key
assert plex.systemAccount(account.id) == account


def test_server_system_devices(plex):
devices = plex.systemDevices()
assert len(devices)
device = devices[-1]
assert device.clientIdentifier or device.clientIdentifier is None
assert utils.is_datetime(device.createdAt)
assert utils.is_int(device.id)
assert len(device.key)
assert len(device.name) or device.name == ""
assert len(device.platform) or device.platform == ""
assert plex.systemDevice(device.id) == device


@pytest.mark.authenticated
Expand Down