Show current program thumbnail as media_image (#10033)

* Do not include program data in media_title if program data is undefined (None)

* Show thumbnail of currently playing program

* async setup

* Update requirements
This commit is contained in:
Philipp Schmitt 2017-10-23 12:04:23 +02:00 committed by Pascal Vizeli
parent 5182f76aea
commit e201bcad14
2 changed files with 28 additions and 15 deletions

View File

@ -4,13 +4,13 @@ Support for interface with an Orange Livebox Play TV appliance.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/media_player.liveboxplaytv/ https://home-assistant.io/components/media_player.liveboxplaytv/
""" """
import asyncio
import logging import logging
from datetime import timedelta from datetime import timedelta
import requests import requests
import voluptuous as vol import voluptuous as vol
import homeassistant.util as util
from homeassistant.components.media_player import ( from homeassistant.components.media_player import (
SUPPORT_TURN_ON, SUPPORT_TURN_OFF, SUPPORT_PLAY, SUPPORT_TURN_ON, SUPPORT_TURN_OFF, SUPPORT_PLAY,
SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PREVIOUS_TRACK, SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PREVIOUS_TRACK,
@ -21,7 +21,7 @@ from homeassistant.const import (
STATE_PAUSED, CONF_NAME) STATE_PAUSED, CONF_NAME)
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
REQUIREMENTS = ['liveboxplaytv==1.5.0'] REQUIREMENTS = ['liveboxplaytv==2.0.0']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -43,8 +43,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
}) })
# pylint: disable=unused-argument @asyncio.coroutine
def setup_platform(hass, config, add_devices, discovery_info=None): def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
"""Set up the Orange Livebox Play TV platform.""" """Set up the Orange Livebox Play TV platform."""
host = config.get(CONF_HOST) host = config.get(CONF_HOST)
port = config.get(CONF_PORT) port = config.get(CONF_PORT)
@ -58,7 +58,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
except IOError: except IOError:
_LOGGER.error("Failed to connect to Livebox Play TV at %s:%s. " _LOGGER.error("Failed to connect to Livebox Play TV at %s:%s. "
"Please check your configuration", host, port) "Please check your configuration", host, port)
add_devices(livebox_devices, True) async_add_devices(livebox_devices, True)
class LiveboxPlayTvDevice(MediaPlayerDevice): class LiveboxPlayTvDevice(MediaPlayerDevice):
@ -78,18 +78,28 @@ class LiveboxPlayTvDevice(MediaPlayerDevice):
self._current_program = None self._current_program = None
self._media_image_url = None self._media_image_url = None
@util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS) @asyncio.coroutine
def update(self): def async_update(self):
"""Retrieve the latest data.""" """Retrieve the latest data."""
try: try:
self._state = self.refresh_state() self._state = self.refresh_state()
# Update current channel # Update current channel
channel = self._client.get_current_channel() channel = self._client.channel
if channel is not None: if channel is not None:
self._current_program = self._client.program self._current_program = yield from \
self._current_channel = channel.get('name', None) self._client.async_get_current_program_name()
self._media_image_url = \ self._current_channel = channel
self._client.get_current_channel_image(img_size=300) # Set media image to current program if a thumbnail is
# available. Otherwise we'll use the channel's image.
img_size = 800
prg_img_url = yield from \
self._client.async_get_current_program_image(img_size)
if prg_img_url:
self._media_image_url = prg_img_url
else:
chan_img_url = \
self._client.get_current_channel_image(img_size)
self._media_image_url = chan_img_url
self.refresh_channel_list() self.refresh_channel_list()
except requests.ConnectionError: except requests.ConnectionError:
self._state = None self._state = None
@ -136,8 +146,11 @@ class LiveboxPlayTvDevice(MediaPlayerDevice):
def media_title(self): def media_title(self):
"""Title of current playing media.""" """Title of current playing media."""
if self._current_channel: if self._current_channel:
return '{}: {}'.format(self._current_channel, if self._current_program:
self._current_program) return '{}: {}'.format(self._current_channel,
self._current_program)
else:
return self._current_channel
@property @property
def supported_features(self): def supported_features(self):

View File

@ -411,7 +411,7 @@ lightify==1.0.6
limitlessled==1.0.8 limitlessled==1.0.8
# homeassistant.components.media_player.liveboxplaytv # homeassistant.components.media_player.liveboxplaytv
liveboxplaytv==1.5.0 liveboxplaytv==2.0.0
# homeassistant.components.lametric # homeassistant.components.lametric
# homeassistant.components.notify.lametric # homeassistant.components.notify.lametric