mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-10 06:04:15 +00:00
Add clientIdentifier attribute to SystemDevice (#703)
* Add clientIdentifier attribute to SystemDevice * Add test for SystemDevice clientIdentifier * Add methods to return a specific SystemAccount or SystemDevice by ID * Update tests for SystemAccounts and SystemDevices
This commit is contained in:
parent
ef18e2c256
commit
1d4e911ef5
2 changed files with 31 additions and 12 deletions
|
@ -217,19 +217,41 @@ class PlexServer(PlexObject):
|
|||
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
|
||||
|
@ -845,6 +867,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>)
|
||||
|
@ -855,6 +878,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
|
||||
|
@ -897,19 +921,11 @@ class StatisticsBandwidth(PlexObject):
|
|||
|
||||
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):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue