diff --git a/homeassistant/components/webostv/__init__.py b/homeassistant/components/webostv/__init__.py index 13f3d9e8f8d80d..9dec8fe0c71eb1 100644 --- a/homeassistant/components/webostv/__init__.py +++ b/homeassistant/components/webostv/__init__.py @@ -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" @@ -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])} ) @@ -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__) diff --git a/homeassistant/components/webostv/const.py b/homeassistant/components/webostv/const.py new file mode 100644 index 00000000000000..a81696f6c0baed --- /dev/null +++ b/homeassistant/components/webostv/const.py @@ -0,0 +1,4 @@ +"""Constants used for WebOS TV.""" +LIVE_TV_APP_ID = "com.webos.app.livetv" + +ATTR_SOUND_OUTPUT = "sound_output" diff --git a/homeassistant/components/webostv/media_player.py b/homeassistant/components/webostv/media_player.py index c34fb376d316ec..708db5ca679d2a 100644 --- a/homeassistant/components/webostv/media_player.py +++ b/homeassistant/components/webostv/media_player.py @@ -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 @@ -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.""" @@ -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.""" @@ -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.""" @@ -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() @@ -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() diff --git a/homeassistant/components/webostv/services.yaml b/homeassistant/components/webostv/services.yaml index 137a6026eda648..1dfb3a6f1d3f22 100644 --- a/homeassistant/components/webostv/services.yaml +++ b/homeassistant/components/webostv/services.yaml @@ -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'