From 500e8617ee96e157fc2df7bb7c4b688f2e19bebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9deric=20Kinnaer?= Date: Wed, 23 Jan 2019 12:42:50 +0100 Subject: [PATCH 1/3] SongPal: error handling if active_source can't be detected --- homeassistant/components/media_player/songpal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/media_player/songpal.py b/homeassistant/components/media_player/songpal.py index 59293fd3e8cb1d..a09e232ad17f9a 100644 --- a/homeassistant/components/media_player/songpal.py +++ b/homeassistant/components/media_player/songpal.py @@ -288,7 +288,7 @@ def state(self): @property def source(self): """Return currently active source.""" - return self._active_source.title + return getattr(self._active_source, 'title', None) @property def volume_level(self): From 27208a27ce2c377f9c5c0f7a6fc9f9a4e5d99e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9deric=20Kinnaer?= Date: Thu, 24 Jan 2019 11:16:40 +0100 Subject: [PATCH 2/3] sonpal: Add comment to the use of getattr() for property source --- homeassistant/components/media_player/songpal.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/homeassistant/components/media_player/songpal.py b/homeassistant/components/media_player/songpal.py index a09e232ad17f9a..7a17559a943b97 100644 --- a/homeassistant/components/media_player/songpal.py +++ b/homeassistant/components/media_player/songpal.py @@ -288,6 +288,8 @@ def state(self): @property def source(self): """Return currently active source.""" + # Use getattr() to avoid a KeyError when _active_source is + # not (yet) populated. return getattr(self._active_source, 'title', None) @property From 15fb3ac9e86ea5963d1e8761d640cea71073a012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9deric=20Kinnaer?= Date: Thu, 24 Jan 2019 11:18:28 +0100 Subject: [PATCH 3/3] songpal: make comment single-line --- homeassistant/components/media_player/songpal.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homeassistant/components/media_player/songpal.py b/homeassistant/components/media_player/songpal.py index 7a17559a943b97..e67578539adc2c 100644 --- a/homeassistant/components/media_player/songpal.py +++ b/homeassistant/components/media_player/songpal.py @@ -288,8 +288,7 @@ def state(self): @property def source(self): """Return currently active source.""" - # Use getattr() to avoid a KeyError when _active_source is - # not (yet) populated. + # Avoid a KeyError when _active_source is not (yet) populated return getattr(self._active_source, 'title', None) @property