From 630850ee9aac7d85c1bc107567eb89bfddefd5ff Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 10 Feb 2019 11:08:04 +0100 Subject: [PATCH] Reset the connection to a Snapcast server if it starts failing --- platypush/backend/music/snapcast.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/platypush/backend/music/snapcast.py b/platypush/backend/music/snapcast.py index 2c3a25fc3..e42853931 100644 --- a/platypush/backend/music/snapcast.py +++ b/platypush/backend/music/snapcast.py @@ -59,7 +59,7 @@ class MusicSnapcastBackend(Backend): def _connect(self, host, port): - if host in self._socks: + if self._socks.get(host): return self._socks[host] self.logger.debug('Connecting to {}:{}'.format(host, port)) @@ -188,7 +188,12 @@ class MusicSnapcastBackend(Backend): } get_plugin('music.snapcast')._send(sock, request) - return self._recv(sock).get('result', {}).get('server', {}) + try: + 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): super().run()