mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
media player Kodi: handle TransportError exceptions when calling JSONRPC API methods (#8047)
* handle TransportError exceptions when calling JSONRPC API * use double quotes for log messages; show TransportErrors as in async_ws_connect * fix spaces around keyword / parameter * fix logging message * review changes
This commit is contained in:
parent
0e08785373
commit
35132f9836
@ -540,7 +540,7 @@ class KodiDevice(MediaPlayerDevice):
|
|||||||
elif self._turn_off_action == 'shutdown':
|
elif self._turn_off_action == 'shutdown':
|
||||||
yield from self.server.System.Shutdown()
|
yield from self.server.System.Shutdown()
|
||||||
else:
|
else:
|
||||||
_LOGGER.warning('turn_off requested but turn_off_action is none')
|
_LOGGER.warning("turn_off requested but turn_off_action is none")
|
||||||
|
|
||||||
@cmd
|
@cmd
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -694,22 +694,26 @@ class KodiDevice(MediaPlayerDevice):
|
|||||||
def async_call_method(self, method, **kwargs):
|
def async_call_method(self, method, **kwargs):
|
||||||
"""Run Kodi JSONRPC API method with params."""
|
"""Run Kodi JSONRPC API method with params."""
|
||||||
import jsonrpc_base
|
import jsonrpc_base
|
||||||
_LOGGER.debug('Run API method "%s", kwargs=%s', method, kwargs)
|
_LOGGER.debug("Run API method %s, kwargs=%s", method, kwargs)
|
||||||
result_ok = False
|
result_ok = False
|
||||||
try:
|
try:
|
||||||
result = yield from getattr(self.server, method)(**kwargs)
|
result = yield from getattr(self.server, method)(**kwargs)
|
||||||
result_ok = True
|
result_ok = True
|
||||||
except jsonrpc_base.jsonrpc.ProtocolError as exc:
|
except jsonrpc_base.jsonrpc.ProtocolError as exc:
|
||||||
result = exc.args[2]['error']
|
result = exc.args[2]['error']
|
||||||
_LOGGER.error('Run API method %s.%s(%s) error: %s',
|
_LOGGER.error("Run API method %s.%s(%s) error: %s",
|
||||||
self.entity_id, method, kwargs, result)
|
self.entity_id, method, kwargs, result)
|
||||||
|
except jsonrpc_base.jsonrpc.TransportError:
|
||||||
|
result = None
|
||||||
|
_LOGGER.warning("TransportError trying to run API method "
|
||||||
|
"%s.%s(%s)", self.entity_id, method, kwargs)
|
||||||
|
|
||||||
if isinstance(result, dict):
|
if isinstance(result, dict):
|
||||||
event_data = {'entity_id': self.entity_id,
|
event_data = {'entity_id': self.entity_id,
|
||||||
'result': result,
|
'result': result,
|
||||||
'result_ok': result_ok,
|
'result_ok': result_ok,
|
||||||
'input': {'method': method, 'params': kwargs}}
|
'input': {'method': method, 'params': kwargs}}
|
||||||
_LOGGER.debug('EVENT kodi_call_method_result: %s', event_data)
|
_LOGGER.debug("EVENT kodi_call_method_result: %s", event_data)
|
||||||
self.hass.bus.async_fire(EVENT_KODI_CALL_METHOD_RESULT,
|
self.hass.bus.async_fire(EVENT_KODI_CALL_METHOD_RESULT,
|
||||||
event_data=event_data)
|
event_data=event_data)
|
||||||
return result
|
return result
|
||||||
@ -753,10 +757,13 @@ class KodiDevice(MediaPlayerDevice):
|
|||||||
yield from self.server.Playlist.Add(params)
|
yield from self.server.Playlist.Add(params)
|
||||||
except jsonrpc_base.jsonrpc.ProtocolError as exc:
|
except jsonrpc_base.jsonrpc.ProtocolError as exc:
|
||||||
result = exc.args[2]['error']
|
result = exc.args[2]['error']
|
||||||
_LOGGER.error('Run API method %s.Playlist.Add(%s) error: %s',
|
_LOGGER.error("Run API method %s.Playlist.Add(%s) error: %s",
|
||||||
self.entity_id, media_type, result)
|
self.entity_id, media_type, result)
|
||||||
|
except jsonrpc_base.jsonrpc.TransportError:
|
||||||
|
_LOGGER.warning("TransportError trying to add playlist to %s",
|
||||||
|
self.entity_id)
|
||||||
else:
|
else:
|
||||||
_LOGGER.warning('No media detected for Playlist.Add')
|
_LOGGER.warning("No media detected for Playlist.Add")
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_add_all_albums(self, artist_name):
|
def async_add_all_albums(self, artist_name):
|
||||||
@ -800,7 +807,7 @@ class KodiDevice(MediaPlayerDevice):
|
|||||||
artist_name, [a['artist'] for a in artists['artists']])
|
artist_name, [a['artist'] for a in artists['artists']])
|
||||||
return artists['artists'][out[0][0]]['artistid']
|
return artists['artists'][out[0][0]]['artistid']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
_LOGGER.warning('No artists were found: %s', artist_name)
|
_LOGGER.warning("No artists were found: %s", artist_name)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -839,7 +846,7 @@ class KodiDevice(MediaPlayerDevice):
|
|||||||
album_name, [a['label'] for a in albums['albums']])
|
album_name, [a['label'] for a in albums['albums']])
|
||||||
return albums['albums'][out[0][0]]['albumid']
|
return albums['albums'][out[0][0]]['albumid']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
_LOGGER.warning('No albums were found with artist: %s, album: %s',
|
_LOGGER.warning("No albums were found with artist: %s, album: %s",
|
||||||
artist_name, album_name)
|
artist_name, album_name)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user