-
-
Notifications
You must be signed in to change notification settings - Fork 38.3k
Add media position properties #10076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
2579129
9606212
4906419
e5ff3a6
99ced74
8b01324
093dce8
6a5bcf6
951ce74
01ca064
bde6604
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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__) | ||
|
|
||
|
|
@@ -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 | ||
| self._media_image_url = None | ||
| self._media_last_updated = None | ||
|
|
||
| @asyncio.coroutine | ||
| def async_update(self): | ||
| """Retrieve the latest data.""" | ||
| import pyteleloisirs | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should either expose |
||
| 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 = \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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 | ||
|
|
||
|
|
@@ -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): | ||
|
|
||
There was a problem hiding this comment.
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.