From df355fb9541359e081c72de0d80a67b2458762f0 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 16 Jun 2019 21:54:03 +0200 Subject: [PATCH] Fixed typos and warnings in snapcast backend --- platypush/backend/music/snapcast.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/platypush/backend/music/snapcast.py b/platypush/backend/music/snapcast.py index dab792a92..c660deefd 100644 --- a/platypush/backend/music/snapcast.py +++ b/platypush/backend/music/snapcast.py @@ -34,7 +34,7 @@ class MusicSnapcastBackend(Backend): _DEFAULT_POLL_SECONDS = 10 # Poll servers each 10 seconds _SOCKET_EOL = '\r\n'.encode() - def __init__(self, hosts=['localhost'], ports=[_DEFAULT_SNAPCAST_PORT], + def __init__(self, hosts=None, ports=None, poll_seconds=_DEFAULT_POLL_SECONDS, *args, **kwargs): """ :param hosts: List of Snapcast server names or IPs to monitor (default: @@ -52,6 +52,11 @@ class MusicSnapcastBackend(Backend): super().__init__(*args, **kwargs) + if hosts is None: + hosts = ['localhost'] + if ports is None: + ports = [self._DEFAULT_SNAPCAST_PORT] + self.hosts = hosts[:] self.ports = ports[:] self.poll_seconds = poll_seconds @@ -123,7 +128,7 @@ class MusicSnapcastBackend(Backend): elif msg.get('method') == 'Group.OnStreamChanged': group_id = msg.get('params', {}).get('id') stream_id = msg.get('params', {}).get('stream_id') - evt = GroupStreamChangeEvent(host=host, group=group, stream=stream) + evt = GroupStreamChangeEvent(host=host, group=group_id, stream=stream_id) elif msg.get('method') == 'Stream.OnUpdate': stream_id = msg.get('params', {}).get('stream_id') stream = msg.get('params', {}).get('stream') @@ -137,10 +142,9 @@ class MusicSnapcastBackend(Backend): def _client(self, host, port): def _thread(): set_thread_name('Snapcast-' + host) - status = None try: - status = self._status(host, port) + self._status(host, port) except Exception as e: self.logger.warning(('Exception while getting the status ' + 'of the Snapcast server {}:{}: {}'). @@ -200,7 +204,7 @@ class MusicSnapcastBackend(Backend): except Exception as e: self.logger.warning('Unable to connect to {}:{}: {}'.format( host, port, str(e))) - self._socks[hosts] = None + self._socks[host] = None def run(self): super().run()