From bbc3a9e82a2b0423cb6735e79d9ae08f2843e4b5 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 6 Jan 2019 23:46:52 +0100 Subject: [PATCH] Fixed Snapcast status method --- platypush/plugins/music/snapcast.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/platypush/plugins/music/snapcast.py b/platypush/plugins/music/snapcast.py index 6ccdf77578..eb9272e579 100644 --- a/platypush/plugins/music/snapcast.py +++ b/platypush/plugins/music/snapcast.py @@ -2,6 +2,7 @@ import json import socket import threading +from platypush.context import get_backend from platypush.plugins import Plugin, action @@ -34,6 +35,9 @@ class MusicSnapcastPlugin(Plugin): self._latest_req_id = 0 self._latest_req_id_lock = threading.RLock() + backend = get_backend('music.snapcast') + self.backend_hosts = backend.hosts if backend else [] + def _get_req_id(self): with self._latest_req_id_lock: self._latest_req_id += 1 @@ -63,8 +67,12 @@ class MusicSnapcastPlugin(Plugin): buf += sock.recv(1) return json.loads(buf.decode().strip()).get('result') + def _get_group(self, sock, group): + for g in self._status(sock).get('groups', []): + if group == g.get('id') or group == g.get('name'): + return g - def _get_group_by_client(self, sock, client): + def _get_client(self, sock, client): for g in self._status(sock).get('groups', []): clients = g.get('clients', []) @@ -73,19 +81,8 @@ class MusicSnapcastPlugin(Plugin): client == c.get('name') or \ client == c.get('host', {}).get('name') or \ client == c.get('host', {}).get('ip'): - return g - - def _get_group(self, sock, group): - for g in self._status(sock).get('groups', []): - if group == g.get('id') or group == g.get('name'): - return g - - def _get_client(self, sock, client): - group = self._get_group_by_client(sock, client) - if not group: - return None - clients = group.get('clients', []) - return None if len(clients) == 0 else clients[0] + c['group_id'] = g.get('id') + return c def _status(self, sock): request = {