Few more fixes on mopidy backend

This commit is contained in:
Fabio Manganiello 2019-02-12 22:57:09 +01:00
parent 9a4963a48a
commit c18515bd3c

View file

@ -87,7 +87,9 @@ class MusicMopidyBackend(Backend):
ws = websocket.create_connection(self.url)
ws.send(msg)
return json.loads(ws.recv()).get('result')
response = json.loads(ws.recv()).get('result')
ws.close()
return response
def _get_tracklist_status(self):
@ -102,21 +104,6 @@ class MusicMopidyBackend(Backend):
'method': 'core.tracklist.get_consume'}),
}
async def _poll_events(self):
import websocket
try:
while not self.should_stop():
async with websockets.connect(self.url) as ws:
msg = await ws.recv()
if isinstance(msg, bytes):
msg = msg.decode()
self._handle_msg(msg)
except Exception as e:
self.logger.warning('The Mopidy backend raised an exception')
self.logger.exception(e)
time.sleep(2) # Wait a bit before retrying
def _on_msg(self):
def hndl(msg):
msg = json.loads(msg)
@ -210,6 +197,8 @@ class MusicMopidyBackend(Backend):
return hndl
def _connect(self):
import websocket
if not self._ws:
self._ws = websocket.WebSocketApp(self.url,
on_message=self._on_msg(),