When notifications fail to send the client list is automatically reloaded in case the client address has changed.
This commit is contained in:
@@ -29,31 +29,40 @@ class Plex(Notification):
|
|||||||
|
|
||||||
return self.server.refresh()
|
return self.server.refresh()
|
||||||
|
|
||||||
def notifyClients(self, message, clients):
|
def getClientNames(self):
|
||||||
|
return [
|
||||||
|
x.strip().lower()
|
||||||
|
for x in self.conf('clients').split(',')
|
||||||
|
]
|
||||||
|
|
||||||
|
def notifyClients(self, message, client_names):
|
||||||
success = True
|
success = True
|
||||||
|
|
||||||
while len(clients):
|
while len(client_names):
|
||||||
client = clients[0]
|
client_name = client_names[0]
|
||||||
|
client_success = False
|
||||||
|
client = self.server.clients.get(client_name)
|
||||||
|
|
||||||
success = fireEvent('notify.plex.notifyClient', client, message, single=True)
|
if client:
|
||||||
|
client_success = fireEvent('notify.plex.notifyClient', client, message, single=True)
|
||||||
|
|
||||||
if success:
|
if client_success:
|
||||||
clients.pop(0)
|
client_names.pop(0)
|
||||||
else:
|
|
||||||
|
if not client_success:
|
||||||
if self.server.staleClients():
|
if self.server.staleClients():
|
||||||
log.info('Failed to send notification to client "%s". '
|
log.info('Failed to send notification to client "%s". '
|
||||||
'Client list is stale, updating the client list and retrying.', client['name'])
|
'Client list is stale, updating the client list and retrying.', client_name)
|
||||||
self.server.updateClients()
|
self.server.updateClients(self.getClientNames())
|
||||||
else:
|
else:
|
||||||
log.warning('Failed to send notification to client %s, skipping this time', client['name'])
|
log.warning('Failed to send notification to client %s, skipping this time', client_name)
|
||||||
clients.pop(0)
|
client_names.pop(0)
|
||||||
success = False
|
success = False
|
||||||
break
|
|
||||||
|
|
||||||
return success
|
return success
|
||||||
|
|
||||||
def notify(self, message = '', data = {}, listener = None):
|
def notify(self, message = '', data = {}, listener = None):
|
||||||
return self.notifyClients(message, self.server.clients.values())
|
return self.notifyClients(message, self.getClientNames())
|
||||||
|
|
||||||
def test(self, **kwargs):
|
def test(self, **kwargs):
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class PlexServer(object):
|
|||||||
else:
|
else:
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def updateClients(self):
|
def updateClients(self, client_names):
|
||||||
log.info('Searching for clients on Plex Media Server')
|
log.info('Searching for clients on Plex Media Server')
|
||||||
|
|
||||||
self.clients = {}
|
self.clients = {}
|
||||||
@@ -53,14 +53,9 @@ class PlexServer(object):
|
|||||||
if not result:
|
if not result:
|
||||||
return
|
return
|
||||||
|
|
||||||
notify_clients = [
|
|
||||||
x.strip().lower()
|
|
||||||
for x in self.plex.conf('clients').split(',')
|
|
||||||
]
|
|
||||||
|
|
||||||
found_clients = [
|
found_clients = [
|
||||||
c for c in result.findall('Server')
|
c for c in result.findall('Server')
|
||||||
if c.get('name') and c.get('name').lower() in notify_clients
|
if c.get('name') and c.get('name').lower() in client_names
|
||||||
]
|
]
|
||||||
|
|
||||||
for client in found_clients:
|
for client in found_clients:
|
||||||
@@ -73,10 +68,10 @@ class PlexServer(object):
|
|||||||
'protocol': client.get('protocol', 'xbmchttp')
|
'protocol': client.get('protocol', 'xbmchttp')
|
||||||
}
|
}
|
||||||
|
|
||||||
notify_clients.remove(name)
|
client_names.remove(name)
|
||||||
|
|
||||||
if len(notify_clients) > 0:
|
if len(client_names) > 0:
|
||||||
log.debug('Unable to find clients: %s', ', '.join(notify_clients))
|
log.debug('Unable to find clients: %s', ', '.join(client_names))
|
||||||
|
|
||||||
self.last_clients_update = datetime.now()
|
self.last_clients_update = datetime.now()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user