Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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']

_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_ = None

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.

Looks like a copy-paste artifact got left in here.

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:
self._current_program = program.get('name')
# Media progress info
self._media_duration = \
pyteleloisirs.get_program_duration(program)
self._media_remaining_time = \

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.

Media position and media remaining time need to only change when the player actually changes state. See vlc for an example https://github.com/home-assistant/home-assistant/blob/08b0629eca6417a2bb1b6f3c805ff19208484e4d/homeassistant/components/media_player/vlc.py#L70-L72

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, but the media duration only depends on the current time. So this is pretty much guaranteed to be updated every time.

pyteleloisirs.get_remaining_time(program)
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
2 changes: 1 addition & 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