Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions homeassistant/components/media_player/liveboxplaytv.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
CONF_HOST, CONF_PORT, STATE_ON, STATE_OFF, STATE_PLAYING,
STATE_PAUSED, CONF_NAME)
import homeassistant.helpers.config_validation as cv
import homeassistant.util.dt as dt_util

REQUIREMENTS = ['liveboxplaytv==2.0.0']
REQUIREMENTS = ['liveboxplaytv==2.0.2', 'pyteleloisirs==3.3']

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -76,19 +77,32 @@ def __init__(self, host, port, name):
self._channel_list = {}
self._current_channel = None
self._current_program = None
self._media_duration = None
self._media_remaining_time = None
self._media_image_url = None
self._media_last_updated = None

@asyncio.coroutine
def async_update(self):
"""Retrieve the latest data."""
import pyteleloisirs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should either expose get_program_duration and get_remaining_time off of liveboxplaytv, or specifically call out pyteleloisirs in the requirements list since we're using it directly. We shouldn't implicitly depend on liveboxplaytv to pull in the requirement if we're calling it directly.

try:
self._state = self.refresh_state()
# Update current channel
channel = self._client.channel
if channel is not None:
self._current_program = yield from \
self._client.async_get_current_program_name()
self._current_channel = channel
program = yield from \
self._client.async_get_current_program()
if program and self._current_program != program.get('name'):
self._current_program = program.get('name')
# Media progress info
self._media_duration = \
pyteleloisirs.get_program_duration(program)
rtime = pyteleloisirs.get_remaining_time(program)
if rtime != self._media_remaining_time:
self._media_remaining_time = rtime
self._media_last_updated = dt_util.utcnow()
# Set media image to current program if a thumbnail is
# available. Otherwise we'll use the channel's image.
img_size = 800
Expand All @@ -100,7 +114,6 @@ def async_update(self):
chan_img_url = \
self._client.get_current_channel_image(img_size)
self._media_image_url = chan_img_url
self.refresh_channel_list()
except requests.ConnectionError:
self._state = None

Expand Down Expand Up @@ -149,8 +162,25 @@ def media_title(self):
if self._current_program:
return '{}: {}'.format(self._current_channel,
self._current_program)
else:
return self._current_channel
return self._current_channel

@property
def media_duration(self):
"""Duration of current playing media in seconds."""
return self._media_duration

@property
def media_position(self):
"""Position of current playing media in seconds."""
return self._media_remaining_time

@property
def media_position_updated_at(self):
"""When was the position of the current playing media valid.

Returns value from homeassistant.util.dt.utcnow().
"""
return self._media_last_updated

@property
def supported_features(self):
Expand Down
5 changes: 4 additions & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ lightify==1.0.6
limitlessled==1.0.8

# homeassistant.components.media_player.liveboxplaytv
liveboxplaytv==2.0.0
liveboxplaytv==2.0.2

# homeassistant.components.lametric
# homeassistant.components.notify.lametric
Expand Down Expand Up @@ -753,6 +753,9 @@ pysma==0.1.3
# homeassistant.components.sensor.snmp
pysnmp==4.3.10

# homeassistant.components.media_player.liveboxplaytv
pyteleloisirs==3.3

# homeassistant.components.sensor.thinkingcleaner
# homeassistant.components.switch.thinkingcleaner
pythinkingcleaner==0.0.3
Expand Down