Reset the connection to a Snapcast server if it starts failing

This commit is contained in:
Fabio Manganiello 2019-02-10 11:08:04 +01:00
parent cd49f22d5c
commit 630850ee9a

View file

@ -59,7 +59,7 @@ class MusicSnapcastBackend(Backend):
def _connect(self, host, port): def _connect(self, host, port):
if host in self._socks: if self._socks.get(host):
return self._socks[host] return self._socks[host]
self.logger.debug('Connecting to {}:{}'.format(host, port)) self.logger.debug('Connecting to {}:{}'.format(host, port))
@ -188,7 +188,12 @@ class MusicSnapcastBackend(Backend):
} }
get_plugin('music.snapcast')._send(sock, request) get_plugin('music.snapcast')._send(sock, request)
try:
return self._recv(sock).get('result', {}).get('server', {}) return self._recv(sock).get('result', {}).get('server', {})
except Exception as e:
self.logger.warning('Unable to connect to {}:{}: {}'.format(
host, port, str(e)))
self._socks[hosts] = None
def run(self): def run(self):
super().run() super().run()