Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 13 additions & 16 deletions homeassistant/components/webostv/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
"""Support for WebOS TV."""
"""Support for LG webOS Smart TV."""
import asyncio
import logging

from aiopylgtv import PyLGTVCmdException, PyLGTVPairException, WebOsClient
import voluptuous as vol
from websockets.exceptions import ConnectionClosed

from homeassistant.components.webostv.const import (
ATTR_BUTTON,
ATTR_COMMAND,
CONF_ON_ACTION,
CONF_SOURCES,
DEFAULT_NAME,
DOMAIN,
SERVICE_BUTTON,
SERVICE_COMMAND,
SERVICE_SELECT_SOUND_OUTPUT,
WEBOSTV_CONFIG_FILE,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
CONF_CUSTOMIZE,
Expand All @@ -19,21 +31,6 @@

from .const import ATTR_SOUND_OUTPUT

DOMAIN = "webostv"

CONF_SOURCES = "sources"
CONF_ON_ACTION = "turn_on_action"
DEFAULT_NAME = "LG webOS Smart TV"
WEBOSTV_CONFIG_FILE = "webostv.conf"

SERVICE_BUTTON = "button"
ATTR_BUTTON = "button"

SERVICE_COMMAND = "command"
ATTR_COMMAND = "command"

SERVICE_SELECT_SOUND_OUTPUT = "select_sound_output"

CUSTOMIZE_SCHEMA = vol.Schema(
{vol.Optional(CONF_SOURCES, default=[]): vol.All(cv.ensure_list, [cv.string])}
)
Expand Down
19 changes: 17 additions & 2 deletions homeassistant/components/webostv/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
"""Constants used for WebOS TV."""
LIVE_TV_APP_ID = "com.webos.app.livetv"
"""Constants used for LG webOS Smart TV."""
DOMAIN = "webostv"

DEFAULT_NAME = "LG webOS Smart TV"

ATTR_BUTTON = "button"
ATTR_COMMAND = "command"
ATTR_SOUND_OUTPUT = "sound_output"

CONF_ON_ACTION = "turn_on_action"
CONF_SOURCES = "sources"

SERVICE_BUTTON = "button"
SERVICE_COMMAND = "command"
SERVICE_SELECT_SOUND_OUTPUT = "select_sound_output"

LIVE_TV_APP_ID = "com.webos.app.livetv"

WEBOSTV_CONFIG_FILE = "webostv.conf"
49 changes: 35 additions & 14 deletions homeassistant/components/webostv/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from functools import wraps
import logging

from aiopylgtv import PyLGTVCmdException, PyLGTVPairException
from aiopylgtv import PyLGTVCmdException, PyLGTVPairException, WebOsClient
from websockets.exceptions import ConnectionClosed

from homeassistant import util
from homeassistant.components.media_player import MediaPlayerDevice
from homeassistant.components.media_player import DEVICE_CLASS_TV, MediaPlayerDevice
from homeassistant.components.media_player.const import (
MEDIA_TYPE_CHANNEL,
SUPPORT_NEXT_TRACK,
Expand All @@ -23,6 +23,13 @@
SUPPORT_VOLUME_SET,
SUPPORT_VOLUME_STEP,
)
from homeassistant.components.webostv.const import (
ATTR_SOUND_OUTPUT,
CONF_ON_ACTION,
CONF_SOURCES,
DOMAIN,
LIVE_TV_APP_ID,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
CONF_CUSTOMIZE,
Expand All @@ -36,31 +43,26 @@
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.script import Script

from . import CONF_ON_ACTION, CONF_SOURCES, DOMAIN
from .const import ATTR_SOUND_OUTPUT, LIVE_TV_APP_ID

_LOGGER = logging.getLogger(__name__)


SUPPORT_WEBOSTV = (
SUPPORT_TURN_OFF
| SUPPORT_NEXT_TRACK
| SUPPORT_PAUSE
| SUPPORT_PREVIOUS_TRACK
| SUPPORT_VOLUME_MUTE
| SUPPORT_VOLUME_SET
| SUPPORT_VOLUME_STEP
| SUPPORT_SELECT_SOURCE
| SUPPORT_PLAY_MEDIA
| SUPPORT_PLAY
)

SUPPORT_WEBOSTV_VOLUME = SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_STEP

MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=1)


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the LG WebOS TV platform."""
"""Set up the LG webOS Smart TV platform."""

if discovery_info is None:
return
Expand Down Expand Up @@ -108,12 +110,13 @@ async def wrapper(obj, *args, **kwargs):


class LgWebOSMediaPlayerEntity(MediaPlayerDevice):
"""Representation of a LG WebOS TV."""
"""Representation of a LG webOS Smart TV."""

def __init__(self, client, name, customize, on_script=None):
def __init__(self, client: WebOsClient, name: str, customize, on_script=None):
"""Initialize the webos device."""
self._client = client
self._name = name
self._unique_id = client.software_info["device_id"]
self._customize = customize
self._on_script = on_script

Expand Down Expand Up @@ -219,11 +222,21 @@ async def async_update(self):
):
pass

@property
def unique_id(self):
"""Return the unique id of the device."""
return self._unique_id

@property
def name(self):
"""Return the name of the device."""
return self._name

@property
def device_class(self):
"""Return the device class of the device."""
return DEVICE_CLASS_TV

@property
def state(self):
"""Return the state of the device."""
Expand Down Expand Up @@ -285,9 +298,17 @@ def media_image_url(self):
@property
def supported_features(self):
"""Flag media player features that are supported."""
supported = SUPPORT_WEBOSTV

if self._client.sound_output == "external_arc":
supported = supported | SUPPORT_WEBOSTV_VOLUME
elif self._client.sound_output != "lineout":
supported = supported | SUPPORT_WEBOSTV_VOLUME | SUPPORT_VOLUME_SET

if self._on_script:
return SUPPORT_WEBOSTV | SUPPORT_TURN_ON
return SUPPORT_WEBOSTV
supported = supported | SUPPORT_TURN_ON

return supported

@property
def device_state_attributes(self):
Expand Down
6 changes: 4 additions & 2 deletions tests/components/webostv/test_media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ATTR_MEDIA_VOLUME_MUTED,
SERVICE_SELECT_SOURCE,
)
from homeassistant.components.webostv import (
from homeassistant.components.webostv.const import (
ATTR_BUTTON,
ATTR_COMMAND,
DOMAIN,
Expand Down Expand Up @@ -40,7 +40,9 @@ def client_fixture():
with patch(
"homeassistant.components.webostv.WebOsClient", autospec=True
) as mock_client_class:
yield mock_client_class.return_value
client = mock_client_class.return_value
client.software_info = {"device_id": "a1:b1:c1:d1:e1:f1"}
yield client


async def setup_webostv(hass):
Expand Down