From 25791295508f3e24f7ddc1e8d9671805aa5ab4de Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Mon, 23 Oct 2017 15:19:49 +0200 Subject: [PATCH 01/11] Add media progress information --- .../components/media_player/liveboxplaytv.py | 43 +++++++++++++++++-- requirements_all.txt | 6 +++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/media_player/liveboxplaytv.py b/homeassistant/components/media_player/liveboxplaytv.py index 15698ec50223bd..f74e6ce17138bf 100644 --- a/homeassistant/components/media_player/liveboxplaytv.py +++ b/homeassistant/components/media_player/liveboxplaytv.py @@ -5,6 +5,7 @@ https://home-assistant.io/components/media_player.liveboxplaytv/ """ import asyncio +import datetime import logging from datetime import timedelta @@ -21,7 +22,7 @@ STATE_PAUSED, CONF_NAME) import homeassistant.helpers.config_validation as cv -REQUIREMENTS = ['liveboxplaytv==2.0.0'] +REQUIREMENTS = ['liveboxplaytv==2.0.0', 'pyteleloisirs==3.1'] _LOGGER = logging.getLogger(__name__) @@ -76,18 +77,24 @@ 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 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() + program = yield from \ + self._client.async_get_current_program() + self._current_program = program.get('name') self._current_channel = channel # Set media image to current program if a thumbnail is # available. Otherwise we'll use the channel's image. @@ -100,7 +107,13 @@ 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() + # Media progress info + now = datetime.datetime.now() + self._media_duration = \ + pyteleloisirs.get_program_duration(program) + self._media_remaining_time = \ + pyteleloisirs.get_remaining_time(program) + self._media_last_updated = now except requests.ConnectionError: self._state = None @@ -152,6 +165,28 @@ def media_title(self): else: 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.""" + # if self.media_status is None or \ + # not (self.media_status.player_is_playing or + # self.media_status.player_is_paused or + # self.media_status.player_is_idle): + # return None + 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): """Flag media player features that are supported.""" diff --git a/requirements_all.txt b/requirements_all.txt index 814f0442292fa9..f73fae24734f16 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -753,6 +753,12 @@ pysma==0.1.3 # homeassistant.components.sensor.snmp pysnmp==4.3.10 +# homeassistant.components.media_player.sonyavr +pysonyavr==1.4 + +# homeassistant.components.media_player.liveboxplaytv +pyteleloisirs==3.1 + # homeassistant.components.sensor.thinkingcleaner # homeassistant.components.switch.thinkingcleaner pythinkingcleaner==0.0.3 From 960621234ae39d8d566ddb38481c1e2ff2005cde Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Mon, 23 Oct 2017 15:33:53 +0200 Subject: [PATCH 02/11] Remove unnecessary comments --- .../components/media_player/liveboxplaytv.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/media_player/liveboxplaytv.py b/homeassistant/components/media_player/liveboxplaytv.py index f74e6ce17138bf..0e813485ff58d0 100644 --- a/homeassistant/components/media_player/liveboxplaytv.py +++ b/homeassistant/components/media_player/liveboxplaytv.py @@ -21,6 +21,7 @@ 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', 'pyteleloisirs==3.1'] @@ -108,7 +109,7 @@ def async_update(self): self._client.get_current_channel_image(img_size) self._media_image_url = chan_img_url # Media progress info - now = datetime.datetime.now() + now = dt_util.utcnow() self._media_duration = \ pyteleloisirs.get_program_duration(program) self._media_remaining_time = \ @@ -173,16 +174,12 @@ def media_duration(self): @property def media_position(self): """Position of current playing media in seconds.""" - # if self.media_status is None or \ - # not (self.media_status.player_is_playing or - # self.media_status.player_is_paused or - # self.media_status.player_is_idle): - # return None return self._media_remaining_time @property def media_position_updated_at(self): - """When was the position of the current playing media valid. + """ + When was the position of the current playing media valid. Returns value from homeassistant.util.dt.utcnow(). """ return self._media_last_updated From 4906419ed14864819e5a039bcff4e6a9c94f6572 Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Mon, 23 Oct 2017 15:34:40 +0200 Subject: [PATCH 03/11] Remove datetime import --- homeassistant/components/media_player/liveboxplaytv.py | 1 - 1 file changed, 1 deletion(-) diff --git a/homeassistant/components/media_player/liveboxplaytv.py b/homeassistant/components/media_player/liveboxplaytv.py index 0e813485ff58d0..3b37fe93350672 100644 --- a/homeassistant/components/media_player/liveboxplaytv.py +++ b/homeassistant/components/media_player/liveboxplaytv.py @@ -5,7 +5,6 @@ https://home-assistant.io/components/media_player.liveboxplaytv/ """ import asyncio -import datetime import logging from datetime import timedelta From e5ff3a60b4fce37d6333eec61771c635c2cc9c8a Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Mon, 23 Oct 2017 15:59:15 +0200 Subject: [PATCH 04/11] Remove pysonyavr dependency --- requirements_all.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/requirements_all.txt b/requirements_all.txt index f73fae24734f16..d6022ff5162686 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -753,9 +753,6 @@ pysma==0.1.3 # homeassistant.components.sensor.snmp pysnmp==4.3.10 -# homeassistant.components.media_player.sonyavr -pysonyavr==1.4 - # homeassistant.components.media_player.liveboxplaytv pyteleloisirs==3.1 From 99ced7473e2849f9fd2e9e2fcc495dd47a6acdb0 Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Mon, 23 Oct 2017 18:13:12 +0200 Subject: [PATCH 05/11] Fix doc syntax (D205) --- homeassistant/components/media_player/liveboxplaytv.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/media_player/liveboxplaytv.py b/homeassistant/components/media_player/liveboxplaytv.py index 3b37fe93350672..b5da819b16f7bd 100644 --- a/homeassistant/components/media_player/liveboxplaytv.py +++ b/homeassistant/components/media_player/liveboxplaytv.py @@ -177,8 +177,8 @@ def media_position(self): @property def media_position_updated_at(self): - """ - When was the position of the current playing media valid. + """When was the position of the current playing media valid. + Returns value from homeassistant.util.dt.utcnow(). """ return self._media_last_updated From 8b01324025b8fb9c1024c4db08947cb8a31ebed7 Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Mon, 23 Oct 2017 18:24:08 +0200 Subject: [PATCH 06/11] Lint fix: no-else-return --- homeassistant/components/media_player/liveboxplaytv.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homeassistant/components/media_player/liveboxplaytv.py b/homeassistant/components/media_player/liveboxplaytv.py index b5da819b16f7bd..0d2df8d7aadcd2 100644 --- a/homeassistant/components/media_player/liveboxplaytv.py +++ b/homeassistant/components/media_player/liveboxplaytv.py @@ -162,8 +162,7 @@ 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): From 093dce81be7e1f288d9f574d71d7336a9128b44e Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Tue, 24 Oct 2017 07:48:49 +0200 Subject: [PATCH 07/11] Don't attempt to set media progress info if program is None --- .../components/media_player/liveboxplaytv.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/media_player/liveboxplaytv.py b/homeassistant/components/media_player/liveboxplaytv.py index 0d2df8d7aadcd2..2c408bc3360851 100644 --- a/homeassistant/components/media_player/liveboxplaytv.py +++ b/homeassistant/components/media_player/liveboxplaytv.py @@ -92,10 +92,17 @@ def async_update(self): # Update current channel channel = self._client.channel if channel is not None: + self._current_channel = channel program = yield from \ self._client.async_get_current_program() - self._current_program = program.get('name') - self._current_channel = channel + if program: + self._current_program = program.get('name') + # Media progress info + self._media_duration = \ + pyteleloisirs.get_program_duration(program) + self._media_remaining_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 @@ -107,13 +114,6 @@ def async_update(self): chan_img_url = \ self._client.get_current_channel_image(img_size) self._media_image_url = chan_img_url - # Media progress info - now = dt_util.utcnow() - self._media_duration = \ - pyteleloisirs.get_program_duration(program) - self._media_remaining_time = \ - pyteleloisirs.get_remaining_time(program) - self._media_last_updated = now except requests.ConnectionError: self._state = None From 6a5bcf608586ab925f035b3236450b065d4014c6 Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Wed, 25 Oct 2017 21:03:13 +0200 Subject: [PATCH 08/11] Fix Python 3.4 compatibility --- homeassistant/components/media_player/liveboxplaytv.py | 2 +- requirements_all.txt | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/media_player/liveboxplaytv.py b/homeassistant/components/media_player/liveboxplaytv.py index 2c408bc3360851..d6884e43aff066 100644 --- a/homeassistant/components/media_player/liveboxplaytv.py +++ b/homeassistant/components/media_player/liveboxplaytv.py @@ -22,7 +22,7 @@ import homeassistant.helpers.config_validation as cv import homeassistant.util.dt as dt_util -REQUIREMENTS = ['liveboxplaytv==2.0.0', 'pyteleloisirs==3.1'] +REQUIREMENTS = ['liveboxplaytv==2.0.2'] _LOGGER = logging.getLogger(__name__) diff --git a/requirements_all.txt b/requirements_all.txt index d6022ff5162686..b155db2f1f151c 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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 @@ -753,9 +753,6 @@ pysma==0.1.3 # homeassistant.components.sensor.snmp pysnmp==4.3.10 -# homeassistant.components.media_player.liveboxplaytv -pyteleloisirs==3.1 - # homeassistant.components.sensor.thinkingcleaner # homeassistant.components.switch.thinkingcleaner pythinkingcleaner==0.0.3 From 951ce749387e5caa4f9a406b432395b2ce8701db Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Thu, 26 Oct 2017 08:22:25 +0200 Subject: [PATCH 09/11] Explicitely depend on pyteleloisirs --- homeassistant/components/media_player/liveboxplaytv.py | 3 +-- requirements_all.txt | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/media_player/liveboxplaytv.py b/homeassistant/components/media_player/liveboxplaytv.py index d6884e43aff066..26cbbe760665ae 100644 --- a/homeassistant/components/media_player/liveboxplaytv.py +++ b/homeassistant/components/media_player/liveboxplaytv.py @@ -22,7 +22,7 @@ import homeassistant.helpers.config_validation as cv import homeassistant.util.dt as dt_util -REQUIREMENTS = ['liveboxplaytv==2.0.2'] +REQUIREMENTS = ['liveboxplaytv==2.0.2', 'pyteleloisirs==3.3'] _LOGGER = logging.getLogger(__name__) @@ -79,7 +79,6 @@ def __init__(self, host, port, name): 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 diff --git a/requirements_all.txt b/requirements_all.txt index b155db2f1f151c..dc691ff9430144 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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 From 01ca064d14073eedad39b16bf6291d611d56c398 Mon Sep 17 00:00:00 2001 From: Philipp Schmitt Date: Thu, 26 Oct 2017 08:28:11 +0200 Subject: [PATCH 10/11] Only update remaining play time when it changed --- homeassistant/components/media_player/liveboxplaytv.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/media_player/liveboxplaytv.py b/homeassistant/components/media_player/liveboxplaytv.py index 26cbbe760665ae..d0754c5806f304 100644 --- a/homeassistant/components/media_player/liveboxplaytv.py +++ b/homeassistant/components/media_player/liveboxplaytv.py @@ -99,9 +99,10 @@ def async_update(self): # Media progress info self._media_duration = \ pyteleloisirs.get_program_duration(program) - self._media_remaining_time = \ - pyteleloisirs.get_remaining_time(program) - self._media_last_updated = dt_util.utcnow() + 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 From bde66046058c4571f9b695ad054106d42db33fe7 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 6 Dec 2017 15:09:01 +0100 Subject: [PATCH 11/11] Fix floot state table --- homeassistant/components/media_player/liveboxplaytv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/media_player/liveboxplaytv.py b/homeassistant/components/media_player/liveboxplaytv.py index d0754c5806f304..8093f0d3dbe15b 100644 --- a/homeassistant/components/media_player/liveboxplaytv.py +++ b/homeassistant/components/media_player/liveboxplaytv.py @@ -94,7 +94,7 @@ def async_update(self): self._current_channel = channel program = yield from \ self._client.async_get_current_program() - if program: + if program and self._current_program != program.get('name'): self._current_program = program.get('name') # Media progress info self._media_duration = \