From f3db819548b801940e1fe32a552d4566267a5833 Mon Sep 17 00:00:00 2001 From: Artem Draft Date: Thu, 20 May 2021 15:03:27 +0300 Subject: [PATCH] Add play_media channel support to LG Netcast (#49527) --- .../components/lg_netcast/media_player.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/homeassistant/components/lg_netcast/media_player.py b/homeassistant/components/lg_netcast/media_player.py index f3e7e44fe5a..31316ca975b 100644 --- a/homeassistant/components/lg_netcast/media_player.py +++ b/homeassistant/components/lg_netcast/media_player.py @@ -12,6 +12,7 @@ from homeassistant.components.media_player.const import ( SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PLAY, + SUPPORT_PLAY_MEDIA, SUPPORT_PREVIOUS_TRACK, SUPPORT_SELECT_SOURCE, SUPPORT_TURN_OFF, @@ -46,6 +47,7 @@ SUPPORT_LGTV = ( | SUPPORT_TURN_OFF | SUPPORT_SELECT_SOURCE | SUPPORT_PLAY + | SUPPORT_PLAY_MEDIA ) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( @@ -85,6 +87,7 @@ class LgTVDevice(MediaPlayerEntity): # Assume that the TV is in Play mode self._playing = True self._volume = 0 + self._channel_id = None self._channel_name = "" self._program_name = "" self._state = None @@ -116,8 +119,11 @@ class LgTVDevice(MediaPlayerEntity): channel_info = client.query_data("cur_channel") if channel_info: channel_info = channel_info[0] + channel_id = channel_info.find("major") self._channel_name = channel_info.find("chname").text self._program_name = channel_info.find("progName").text + if channel_id is not None: + self._channel_id = int(channel_id.text) if self._channel_name is None: self._channel_name = channel_info.find("inputSourceName").text if self._program_name is None: @@ -172,6 +178,11 @@ class LgTVDevice(MediaPlayerEntity): """List of available input sources.""" return self._source_names + @property + def media_content_id(self): + """Content id of current playing media.""" + return self._channel_id + @property def media_content_type(self): """Content type of current playing media.""" @@ -252,3 +263,16 @@ class LgTVDevice(MediaPlayerEntity): def media_previous_track(self): """Send the previous track command.""" self.send_command(37) + + def play_media(self, media_type, media_id, **kwargs): + """Tune to channel.""" + if media_type != MEDIA_TYPE_CHANNEL: + raise ValueError(f"Invalid media type: {media_type}") + + for name, channel in self._sources.items(): + channel_id = channel.find("major") + if channel_id is not None and int(channel_id.text) == int(media_id): + self.select_source(name) + return + + raise ValueError(f"Invalid media id: {media_id}")