From 9d36688a61474f4a201dc13ed7cfb48115fc898a Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 7 Mar 2019 21:19:40 +0100 Subject: [PATCH] Don't fail hard if it's not possible yet to retrieve the mopidy status in the backend constructor --- platypush/backend/music/mopidy.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/platypush/backend/music/mopidy.py b/platypush/backend/music/mopidy.py index cd8e124e..5ac5b68d 100644 --- a/platypush/backend/music/mopidy.py +++ b/platypush/backend/music/mopidy.py @@ -44,8 +44,13 @@ class MusicMopidyBackend(Backend): self.port = int(port) self.url = 'ws://{}:{}/mopidy/ws'.format(host, port) self._msg_id = 0 - self._latest_status = self._get_tracklist_status() self._ws = None + self._latest_status = {} + + try: + self._latest_status = self._get_tracklist_status() + except Exception as e: + self.logger.warning('Unable to get mopidy status: {}'.format(str(e))) def _parse_track(self, track, pos=None): if not track: @@ -178,13 +183,13 @@ class MusicMopidyBackend(Backend): self.bus.post(PlaylistChangeEvent(changes=tracklist)) elif event == 'options_changed': new_status = self._get_tracklist_status() - if new_status['random'] != self._latest_status['random']: + if new_status['random'] != self._latest_status.get('random'): self.bus.post(PlaybackRandomModeChangeEvent(state=new_status['random'])) - if new_status['repeat'] != self._latest_status['repeat']: + if new_status['repeat'] != self._latest_status('repeat'): self.bus.post(PlaybackRepeatModeChangeEvent(state=new_status['repeat'])) - if new_status['single'] != self._latest_status['single']: + if new_status['single'] != self._latest_status('single'): self.bus.post(PlaybackSingleModeChangeEvent(state=new_status['single'])) - if new_status['consume'] != self._latest_status['consume']: + if new_status['consume'] != self._latest_status('consume'): self.bus.post(PlaybackConsumeModeChangeEvent(state=new_status['consume'])) self._latest_status = new_status