Better handling for when user hasn't properly configured Pandora client (#2317)

pull/2326/head
Nick Touran 2016-06-18 08:23:35 -07:00 committed by Paulus Schoutsen
parent 29343ad651
commit e7ea6ecf5a
1 changed files with 14 additions and 2 deletions

View File

@ -102,11 +102,22 @@ class PandoraMediaPlayer(MediaPlayerDevice):
self._pianobar = pexpect.spawn('pianobar')
_LOGGER.info('Started pianobar subprocess')
mode = self._pianobar.expect(['Receiving new playlist',
'Select station:'])
'Select station:',
'Email:'])
if mode == 1:
# station list was presented. dismiss it.
self._pianobar.sendcontrol('m')
elif mode == 2:
_LOGGER.warning('The pianobar client is not configured to log in. '
'Please create a config file for it as described '
'at https://home-assistant.io'
'/components/media_player.pandora/')
# pass through the email/password prompts to quit cleanly
self._pianobar.sendcontrol('m')
self._pianobar.sendcontrol('m')
self._pianobar.terminate()
self._pianobar = None
return
self._update_stations()
self.update_playing_status()
@ -122,6 +133,7 @@ class PandoraMediaPlayer(MediaPlayerDevice):
self._pianobar.send('q')
try:
_LOGGER.info('Stopped Pianobar subprocess')
self._pianobar.terminate()
except pexpect.exceptions.TIMEOUT:
# kill the process group
os.killpg(os.getpgid(self._pianobar.pid), signal.SIGTERM)