Fixed typos and warnings in snapcast backend

This commit is contained in:
Fabio Manganiello 2019-06-16 21:54:03 +02:00
parent 3bbbd5edaa
commit df355fb954

View file

@ -34,7 +34,7 @@ class MusicSnapcastBackend(Backend):
_DEFAULT_POLL_SECONDS = 10 # Poll servers each 10 seconds _DEFAULT_POLL_SECONDS = 10 # Poll servers each 10 seconds
_SOCKET_EOL = '\r\n'.encode() _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): poll_seconds=_DEFAULT_POLL_SECONDS, *args, **kwargs):
""" """
:param hosts: List of Snapcast server names or IPs to monitor (default: :param hosts: List of Snapcast server names or IPs to monitor (default:
@ -52,6 +52,11 @@ class MusicSnapcastBackend(Backend):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
if hosts is None:
hosts = ['localhost']
if ports is None:
ports = [self._DEFAULT_SNAPCAST_PORT]
self.hosts = hosts[:] self.hosts = hosts[:]
self.ports = ports[:] self.ports = ports[:]
self.poll_seconds = poll_seconds self.poll_seconds = poll_seconds
@ -123,7 +128,7 @@ class MusicSnapcastBackend(Backend):
elif msg.get('method') == 'Group.OnStreamChanged': elif msg.get('method') == 'Group.OnStreamChanged':
group_id = msg.get('params', {}).get('id') group_id = msg.get('params', {}).get('id')
stream_id = msg.get('params', {}).get('stream_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': elif msg.get('method') == 'Stream.OnUpdate':
stream_id = msg.get('params', {}).get('stream_id') stream_id = msg.get('params', {}).get('stream_id')
stream = msg.get('params', {}).get('stream') stream = msg.get('params', {}).get('stream')
@ -137,10 +142,9 @@ class MusicSnapcastBackend(Backend):
def _client(self, host, port): def _client(self, host, port):
def _thread(): def _thread():
set_thread_name('Snapcast-' + host) set_thread_name('Snapcast-' + host)
status = None
try: try:
status = self._status(host, port) self._status(host, port)
except Exception as e: except Exception as e:
self.logger.warning(('Exception while getting the status ' + self.logger.warning(('Exception while getting the status ' +
'of the Snapcast server {}:{}: {}'). 'of the Snapcast server {}:{}: {}').
@ -200,7 +204,7 @@ class MusicSnapcastBackend(Backend):
except Exception as e: except Exception as e:
self.logger.warning('Unable to connect to {}:{}: {}'.format( self.logger.warning('Unable to connect to {}:{}: {}'.format(
host, port, str(e))) host, port, str(e)))
self._socks[hosts] = None self._socks[host] = None
def run(self): def run(self):
super().run() super().run()