Skip to content

Commit

Permalink
webostv: Ensure source exists before use (home-assistant#10959)
Browse files Browse the repository at this point in the history
In a case where either (a) an incorrect source name is used, or (b) the
TV isn't currently queryable (e.g. it's off), we get tracebacks because
we assume the source that we are being asked to select exists in
self._source_list.

This makes the lookup code a little more rugged, and adds in a warning
message (in place of the current exception).
  • Loading branch information
OddBloke authored and pvizeli committed Dec 6, 2017
1 parent 9cff6c7 commit 0fc7f37
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions homeassistant/components/media_player/webostv.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,15 @@ def media_play_pause(self):

def select_source(self, source):
"""Select input source."""
if self._source_list.get(source).get('title'):
self._current_source_id = self._source_list[source]['id']
source = self._source_list.get(source)
if source is None:
_LOGGER.warning("Source %s not found for %s", source, self.name)
return
self._current_source_id = self._source_list[source]['id']
if source.get('title'):
self._current_source = self._source_list[source]['title']
self._client.launch_app(self._source_list[source]['id'])
elif self._source_list.get(source).get('label'):
self._current_source_id = self._source_list[source]['id']
elif source.get('label'):
self._current_source = self._source_list[source]['label']
self._client.set_input(self._source_list[source]['id'])

Expand Down

0 comments on commit 0fc7f37

Please sign in to comment.