Expose callbackError parameter in PlexServer.startAlertListener() (#985)

* Expose callbackError

This makes it easier to catch errors without separately instantiating an AlertListener

* Update docstring.

* Fix docstring

Removed post-argument note, incorporated suggestion.
This commit is contained in:
Rui Carmo 2022-08-06 03:52:09 +01:00 committed by GitHub
parent 3a56c69078
commit a7e87a583f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -753,21 +753,27 @@ class PlexServer(PlexObject):
""" Returns a list of all active :class:`~plexapi.media.TranscodeSession` objects. """
return self.fetchItems('/transcode/sessions')
def startAlertListener(self, callback=None):
def startAlertListener(self, callback=None, callbackError=None):
""" Creates a websocket connection to the Plex Server to optionally receive
notifications. These often include messages from Plex about media scans
as well as updates to currently running Transcode Sessions.
NOTE: You need websocket-client installed in order to use this feature.
>> pip install websocket-client
Returns a new :class:`~plexapi.alert.AlertListener` object.
Note: ``websocket-client`` must be installed in order to use this feature.
.. code-block:: python
>> pip install websocket-client
Parameters:
callback (func): Callback function to call on received messages.
callbackError (func): Callback function to call on errors.
Raises:
:exc:`~plexapi.exception.Unsupported`: Websocket-client not installed.
"""
notifier = AlertListener(self, callback)
notifier = AlertListener(self, callback, callbackError)
notifier.start()
return notifier