mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Kodi cleanup and config update (#5098)
This commit is contained in:
parent
254eb4e88a
commit
018d786f36
@ -43,27 +43,24 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Setup the Kodi platform."""
|
"""Setup the Kodi platform."""
|
||||||
url = '{}:{}'.format(config.get(CONF_HOST), config.get(CONF_PORT))
|
host = config.get(CONF_HOST)
|
||||||
|
port = config.get(CONF_PORT)
|
||||||
|
|
||||||
jsonrpc_url = config.get('url') # deprecated
|
if host.startswith('http://') or host.startswith('https://'):
|
||||||
if jsonrpc_url:
|
host = host.lstrip('http://').lstrip('https://')
|
||||||
url = jsonrpc_url.rstrip('/jsonrpc')
|
_LOGGER.warning(
|
||||||
|
"Kodi host name should no longer conatin http:// See updated "
|
||||||
|
"definitions here: "
|
||||||
|
"https://home-assistant.io/components/media_player.kodi/")
|
||||||
|
|
||||||
username = config.get(CONF_USERNAME)
|
add_entities([
|
||||||
password = config.get(CONF_PASSWORD)
|
|
||||||
|
|
||||||
if username is not None:
|
|
||||||
auth = (username, password)
|
|
||||||
else:
|
|
||||||
auth = None
|
|
||||||
|
|
||||||
add_devices([
|
|
||||||
KodiDevice(
|
KodiDevice(
|
||||||
config.get(CONF_NAME),
|
config.get(CONF_NAME),
|
||||||
url,
|
host=host, port=port,
|
||||||
auth=auth,
|
username=config.get(CONF_USERNAME),
|
||||||
|
password=config.get(CONF_PASSWORD),
|
||||||
turn_off_action=config.get(CONF_TURN_OFF_ACTION)),
|
turn_off_action=config.get(CONF_TURN_OFF_ACTION)),
|
||||||
])
|
])
|
||||||
|
|
||||||
@ -71,25 +68,25 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
class KodiDevice(MediaPlayerDevice):
|
class KodiDevice(MediaPlayerDevice):
|
||||||
"""Representation of a XBMC/Kodi device."""
|
"""Representation of a XBMC/Kodi device."""
|
||||||
|
|
||||||
def __init__(self, name, url, auth=None, turn_off_action=None):
|
def __init__(self, name, host, port, username=None, password=None,
|
||||||
|
turn_off_action=None):
|
||||||
"""Initialize the Kodi device."""
|
"""Initialize the Kodi device."""
|
||||||
import jsonrpc_requests
|
import jsonrpc_requests
|
||||||
self._name = name
|
self._name = name
|
||||||
self._url = url
|
|
||||||
self._basic_auth_url = None
|
|
||||||
|
|
||||||
kwargs = {'timeout': 5}
|
kwargs = {'timeout': 5}
|
||||||
|
|
||||||
if auth is not None:
|
if username is not None:
|
||||||
kwargs['auth'] = auth
|
kwargs['auth'] = (username, password)
|
||||||
scheme, netloc, path, query, fragment = urllib.parse.urlsplit(url)
|
image_auth_string = "{}:{}@".format(username, password)
|
||||||
self._basic_auth_url = \
|
else:
|
||||||
urllib.parse.urlunsplit((scheme, '{}:{}@{}'.format
|
image_auth_string = ""
|
||||||
(auth[0], auth[1], netloc),
|
|
||||||
path, query, fragment))
|
|
||||||
|
|
||||||
self._server = jsonrpc_requests.Server(
|
self._http_url = 'http://{}:{}/jsonrpc'.format(host, port)
|
||||||
'{}/jsonrpc'.format(self._url), **kwargs)
|
self._image_url = 'http://{}{}:{}/image'.format(
|
||||||
|
image_auth_string, host, port)
|
||||||
|
|
||||||
|
self._server = jsonrpc_requests.Server(self._http_url, **kwargs)
|
||||||
|
|
||||||
self._turn_off_action = turn_off_action
|
self._turn_off_action = turn_off_action
|
||||||
self._players = list()
|
self._players = list()
|
||||||
@ -110,7 +107,7 @@ class KodiDevice(MediaPlayerDevice):
|
|||||||
return self._server.Player.GetActivePlayers()
|
return self._server.Player.GetActivePlayers()
|
||||||
except jsonrpc_requests.jsonrpc.TransportError:
|
except jsonrpc_requests.jsonrpc.TransportError:
|
||||||
if self._players is not None:
|
if self._players is not None:
|
||||||
_LOGGER.warning('Unable to fetch kodi data')
|
_LOGGER.info('Unable to fetch kodi data')
|
||||||
_LOGGER.debug('Unable to fetch kodi data', exc_info=True)
|
_LOGGER.debug('Unable to fetch kodi data', exc_info=True)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -193,21 +190,13 @@ class KodiDevice(MediaPlayerDevice):
|
|||||||
@property
|
@property
|
||||||
def media_image_url(self):
|
def media_image_url(self):
|
||||||
"""Image url of current playing media."""
|
"""Image url of current playing media."""
|
||||||
if self._item is not None:
|
if self._item is None:
|
||||||
return self._get_image_url()
|
return None
|
||||||
|
|
||||||
def _get_image_url(self):
|
|
||||||
"""Helper function that parses the thumbnail URLs used by Kodi."""
|
|
||||||
url_components = urllib.parse.urlparse(self._item['thumbnail'])
|
url_components = urllib.parse.urlparse(self._item['thumbnail'])
|
||||||
|
|
||||||
if url_components.scheme == 'image':
|
if url_components.scheme == 'image':
|
||||||
if self._basic_auth_url is not None:
|
return '{}/{}'.format(
|
||||||
return '{}/image/{}'.format(
|
self._image_url,
|
||||||
self._basic_auth_url,
|
|
||||||
urllib.parse.quote_plus(self._item['thumbnail']))
|
|
||||||
|
|
||||||
return '{}/image/{}'.format(
|
|
||||||
self._url,
|
|
||||||
urllib.parse.quote_plus(self._item['thumbnail']))
|
urllib.parse.quote_plus(self._item['thumbnail']))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
x
Reference in New Issue
Block a user