Add play_media channel support to LG Netcast (#49527)

pull/49717/head^2
Artem Draft 2021-05-20 15:03:27 +03:00 committed by GitHub
parent e16a8063a5
commit f3db819548
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 0 deletions

View File

@ -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}")