Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add webostv sound_output capability #31121

Merged
merged 20 commits into from
Jan 27, 2020
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
10 changes: 10 additions & 0 deletions homeassistant/components/webostv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_send

from .const import ATTR_SOUND_OUTPUT

DOMAIN = "webostv"

CONF_SOURCES = "sources"
Expand All @@ -30,6 +32,8 @@
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 Expand Up @@ -60,9 +64,15 @@

COMMAND_SCHEMA = CALL_SCHEMA.extend({vol.Required(ATTR_COMMAND): cv.string})

SOUND_OUTPUT_SCHEMA = CALL_SCHEMA.extend({vol.Required(ATTR_SOUND_OUTPUT): cv.string})

SERVICE_TO_METHOD = {
SERVICE_BUTTON: {"method": "async_button", "schema": BUTTON_SCHEMA},
SERVICE_COMMAND: {"method": "async_command", "schema": COMMAND_SCHEMA},
SERVICE_SELECT_SOUND_OUTPUT: {
"method": "async_select_sound_output",
"schema": SOUND_OUTPUT_SCHEMA,
},
}

_LOGGER = logging.getLogger(__name__)
Expand Down
4 changes: 4 additions & 0 deletions homeassistant/components/webostv/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Constants used for WebOS TV."""
LIVE_TV_APP_ID = "com.webos.app.livetv"

ATTR_SOUND_OUTPUT = "sound_output"
23 changes: 16 additions & 7 deletions homeassistant/components/webostv/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@
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__)


LIVETV_APP_ID = "com.webos.app.livetv"


SUPPORT_WEBOSTV = (
SUPPORT_TURN_OFF
| SUPPORT_NEXT_TRACK
Expand All @@ -59,8 +57,6 @@
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=1)

LIVE_TV_APP_ID = "com.webos.app.livetv"


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the LG WebOS TV platform."""
Expand Down Expand Up @@ -290,6 +286,14 @@ def supported_features(self):
return SUPPORT_WEBOSTV | SUPPORT_TURN_ON
return SUPPORT_WEBOSTV

@property
def device_state_attributes(self):
"""Return device specific state attributes."""
attributes = {}
if self._client.sound_output is not None and self.state != STATE_OFF:
attributes[ATTR_SOUND_OUTPUT] = self._client.sound_output
return attributes

@cmd
async def async_turn_off(self):
"""Turn off media player."""
Expand Down Expand Up @@ -321,6 +325,11 @@ async def async_mute_volume(self, mute):
"""Send mute command."""
await self._client.set_mute(mute)

@cmd
async def async_select_sound_output(self, sound_output):
"""Select the sound output."""
await self._client.change_sound_output(sound_output)

@cmd
async def async_media_play_pause(self):
"""Simulate play pause media player."""
Expand Down Expand Up @@ -397,7 +406,7 @@ async def async_media_stop(self):
async def async_media_next_track(self):
"""Send next track command."""
current_input = self._client.get_input()
if current_input == LIVETV_APP_ID:
if current_input == LIVE_TV_APP_ID:
await self._client.channel_up()
else:
await self._client.fast_forward()
Expand All @@ -406,7 +415,7 @@ async def async_media_next_track(self):
async def async_media_previous_track(self):
"""Send the previous track command."""
current_input = self._client.get_input()
if current_input == LIVETV_APP_ID:
if current_input == LIVE_TV_APP_ID:
await self._client.channel_down()
else:
await self._client.rewind()
Expand Down
9 changes: 9 additions & 0 deletions homeassistant/components/webostv/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@ command:
https://github.com/TheRealLink/pylgtv/blob/master/pylgtv/endpoints.py
example: 'media.controls/rewind'

select_sound_output:
description: 'Send the TV the command to change sound output.'
fields:
entity_id:
description: Name(s) of the webostv entities to change sound output on.
example: 'media_player.living_room_tv'
sound_output:
description: Name of the sound output to switch to.
example: 'external_speaker'