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()
|
||||
|
||||
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
|
||||
|
||||
while len(clients):
|
||||
client = clients[0]
|
||||
while len(client_names):
|
||||
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:
|
||||
clients.pop(0)
|
||||
else:
|
||||
if client_success:
|
||||
client_names.pop(0)
|
||||
|
||||
if not client_success:
|
||||
if self.server.staleClients():
|
||||
log.info('Failed to send notification to client "%s". '
|
||||
'Client list is stale, updating the client list and retrying.', client['name'])
|
||||
self.server.updateClients()
|
||||
'Client list is stale, updating the client list and retrying.', client_name)
|
||||
self.server.updateClients(self.getClientNames())
|
||||
else:
|
||||
log.warning('Failed to send notification to client %s, skipping this time', client['name'])
|
||||
clients.pop(0)
|
||||
log.warning('Failed to send notification to client %s, skipping this time', client_name)
|
||||
client_names.pop(0)
|
||||
success = False
|
||||
break
|
||||
|
||||
return success
|
||||
|
||||
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):
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class PlexServer(object):
|
||||
else:
|
||||
return data
|
||||
|
||||
def updateClients(self):
|
||||
def updateClients(self, client_names):
|
||||
log.info('Searching for clients on Plex Media Server')
|
||||
|
||||
self.clients = {}
|
||||
@@ -53,14 +53,9 @@ class PlexServer(object):
|
||||
if not result:
|
||||
return
|
||||
|
||||
notify_clients = [
|
||||
x.strip().lower()
|
||||
for x in self.plex.conf('clients').split(',')
|
||||
]
|
||||
|
||||
found_clients = [
|
||||
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:
|
||||
@@ -73,10 +68,10 @@ class PlexServer(object):
|
||||
'protocol': client.get('protocol', 'xbmchttp')
|
||||
}
|
||||
|
||||
notify_clients.remove(name)
|
||||
client_names.remove(name)
|
||||
|
||||
if len(notify_clients) > 0:
|
||||
log.debug('Unable to find clients: %s', ', '.join(notify_clients))
|
||||
if len(client_names) > 0:
|
||||
log.debug('Unable to find clients: %s', ', '.join(client_names))
|
||||
|
||||
self.last_clients_update = datetime.now()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user