From 6d20be056bec6eba773bb7d6356c908e0745b851 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Thu, 23 Jan 2020 22:08:48 +0100 Subject: [PATCH 01/20] Webostv: add sound_output capability Add the ability to read and set the sound_output --- .../components/webostv/media_player.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/homeassistant/components/webostv/media_player.py b/homeassistant/components/webostv/media_player.py index c34fb376d316e..9856ba63cf762 100644 --- a/homeassistant/components/webostv/media_player.py +++ b/homeassistant/components/webostv/media_player.py @@ -61,6 +61,7 @@ LIVE_TV_APP_ID = "com.webos.app.livetv" +ATTR_SOUND_OUTPUT = "sound_output" async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the LG WebOS TV platform.""" @@ -290,6 +291,17 @@ 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 +333,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.""" From 12ea3349a940eba8c51fe2c8fbc1325e76c13ecf Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Thu, 23 Jan 2020 22:12:43 +0100 Subject: [PATCH 02/20] Webostv: add sound_output capability --- homeassistant/components/webostv/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/homeassistant/components/webostv/__init__.py b/homeassistant/components/webostv/__init__.py index 13f3d9e8f8d80..76f6e402ffa92 100644 --- a/homeassistant/components/webostv/__init__.py +++ b/homeassistant/components/webostv/__init__.py @@ -30,6 +30,9 @@ SERVICE_COMMAND = "command" ATTR_COMMAND = "command" +SERVICE_SELECT_SOUND_OUTPUT = "select_sound_output" +ATTR_SOUND_OUTPUT = "sound_output" + CUSTOMIZE_SCHEMA = vol.Schema( {vol.Optional(CONF_SOURCES, default=[]): vol.All(cv.ensure_list, [cv.string])} ) @@ -60,9 +63,12 @@ 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__) From dcd6ef4ca5818eb6c457298cefc3252581a5bfc3 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Thu, 23 Jan 2020 22:13:16 +0100 Subject: [PATCH 03/20] Webostv: add sound_output capability --- homeassistant/components/webostv/services.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/homeassistant/components/webostv/services.yaml b/homeassistant/components/webostv/services.yaml index 137a6026eda64..1dfb3a6f1d3f2 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' From 63e4c51b86cf360208ad1b7ec9d501462e372b8c Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Thu, 23 Jan 2020 22:27:44 +0100 Subject: [PATCH 04/20] fix blank spaces --- homeassistant/components/webostv/media_player.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/webostv/media_player.py b/homeassistant/components/webostv/media_player.py index 9856ba63cf762..cba4eac1d2ab7 100644 --- a/homeassistant/components/webostv/media_player.py +++ b/homeassistant/components/webostv/media_player.py @@ -63,6 +63,7 @@ ATTR_SOUND_OUTPUT = "sound_output" + async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the LG WebOS TV platform.""" @@ -295,10 +296,7 @@ def supported_features(self): def device_state_attributes(self): """Return device specific state attributes.""" attributes = {} - if ( - self._client.sound_output is not None - and self.state != STATE_OFF - ): + if self._client.sound_output is not None and self.state != STATE_OFF: attributes[ATTR_SOUND_OUTPUT] = self._client.sound_output return attributes From 78d89c7083a6b2d1f446f4ebae5b0e270467b03f Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Thu, 23 Jan 2020 22:29:37 +0100 Subject: [PATCH 05/20] fix to long line --- homeassistant/components/webostv/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/webostv/__init__.py b/homeassistant/components/webostv/__init__.py index 76f6e402ffa92..8ca9adde3580e 100644 --- a/homeassistant/components/webostv/__init__.py +++ b/homeassistant/components/webostv/__init__.py @@ -68,7 +68,10 @@ 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}, + SERVICE_SELECT_SOUND_OUTPUT: { + "method": "async_select_sound_output", + "schema": SOUND_OUTPUT_SCHEMA + }, } _LOGGER = logging.getLogger(__name__) From 7ab408d48e0776a64de7c9e0482a15d062c24fd9 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Thu, 23 Jan 2020 22:37:22 +0100 Subject: [PATCH 06/20] add , --- homeassistant/components/webostv/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/webostv/__init__.py b/homeassistant/components/webostv/__init__.py index 8ca9adde3580e..0426480bd3514 100644 --- a/homeassistant/components/webostv/__init__.py +++ b/homeassistant/components/webostv/__init__.py @@ -70,7 +70,7 @@ SERVICE_COMMAND: {"method": "async_command", "schema": COMMAND_SCHEMA}, SERVICE_SELECT_SOUND_OUTPUT: { "method": "async_select_sound_output", - "schema": SOUND_OUTPUT_SCHEMA + "schema": SOUND_OUTPUT_SCHEMA, }, } From ba1f615592e0aa717c66234eb1dba6ad3264a8b6 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 26 Jan 2020 15:50:27 +0100 Subject: [PATCH 07/20] Import ATTR_SOUND_OUTPUT Do not have the ability to test this change right now --- homeassistant/components/webostv/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/webostv/__init__.py b/homeassistant/components/webostv/__init__.py index 0426480bd3514..6dd0f88dab2c5 100644 --- a/homeassistant/components/webostv/__init__.py +++ b/homeassistant/components/webostv/__init__.py @@ -16,6 +16,7 @@ ) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_send +from .media_player import ATTR_SOUND_OUTPUT DOMAIN = "webostv" @@ -31,7 +32,6 @@ ATTR_COMMAND = "command" SERVICE_SELECT_SOUND_OUTPUT = "select_sound_output" -ATTR_SOUND_OUTPUT = "sound_output" CUSTOMIZE_SCHEMA = vol.Schema( {vol.Optional(CONF_SOURCES, default=[]): vol.All(cv.ensure_list, [cv.string])} From 96fc02e4cd129d1ad564ba34eac842f26af5bd48 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 26 Jan 2020 16:00:12 +0100 Subject: [PATCH 08/20] Add white space --- homeassistant/components/webostv/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/webostv/__init__.py b/homeassistant/components/webostv/__init__.py index 6dd0f88dab2c5..8f27ef64a1f18 100644 --- a/homeassistant/components/webostv/__init__.py +++ b/homeassistant/components/webostv/__init__.py @@ -16,6 +16,7 @@ ) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_send + from .media_player import ATTR_SOUND_OUTPUT DOMAIN = "webostv" From f77c4755c83511ffba12067ffff4032c78470480 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 26 Jan 2020 21:47:52 +0100 Subject: [PATCH 09/20] Create const.py --- homeassistant/components/webostv/const.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 homeassistant/components/webostv/const.py diff --git a/homeassistant/components/webostv/const.py b/homeassistant/components/webostv/const.py new file mode 100644 index 0000000000000..ad926abad870d --- /dev/null +++ b/homeassistant/components/webostv/const.py @@ -0,0 +1,3 @@ +LIVE_TV_APP_ID = "com.webos.app.livetv" + +ATTR_SOUND_OUTPUT = "sound_output" From 063112440c63efaa4de3a061fd0088d02e9d530c Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 26 Jan 2020 22:02:28 +0100 Subject: [PATCH 10/20] Use const import --- homeassistant/components/webostv/media_player.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/webostv/media_player.py b/homeassistant/components/webostv/media_player.py index cba4eac1d2ab7..05d70ddc29e50 100644 --- a/homeassistant/components/webostv/media_player.py +++ b/homeassistant/components/webostv/media_player.py @@ -37,10 +37,11 @@ from . import CONF_ON_ACTION, CONF_SOURCES, DOMAIN -_LOGGER = logging.getLogger(__name__) + +from const import LIVE_TV_APP_ID, ATTR_SOUND_OUTPUT -LIVETV_APP_ID = "com.webos.app.livetv" +_LOGGER = logging.getLogger(__name__) SUPPORT_WEBOSTV = ( @@ -59,10 +60,6 @@ MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10) MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=1) -LIVE_TV_APP_ID = "com.webos.app.livetv" - -ATTR_SOUND_OUTPUT = "sound_output" - async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the LG WebOS TV platform.""" @@ -412,7 +409,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() @@ -421,7 +418,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() From 4395d2420c45d98f99a0967c517cfc4241e68057 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 26 Jan 2020 22:04:46 +0100 Subject: [PATCH 11/20] Use import from const.py --- homeassistant/components/webostv/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/webostv/__init__.py b/homeassistant/components/webostv/__init__.py index 8f27ef64a1f18..8e32a355b7aab 100644 --- a/homeassistant/components/webostv/__init__.py +++ b/homeassistant/components/webostv/__init__.py @@ -17,7 +17,7 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_send -from .media_player import ATTR_SOUND_OUTPUT +from const import ATTR_SOUND_OUTPUT DOMAIN = "webostv" From e3210d6736ffcf45470a1ca289fdd47274264102 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 26 Jan 2020 22:23:02 +0100 Subject: [PATCH 12/20] Add docstring --- homeassistant/components/webostv/const.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/webostv/const.py b/homeassistant/components/webostv/const.py index ad926abad870d..a42ea0345783a 100644 --- a/homeassistant/components/webostv/const.py +++ b/homeassistant/components/webostv/const.py @@ -1,3 +1,4 @@ -LIVE_TV_APP_ID = "com.webos.app.livetv" +"""Constants used for WebOS TV.""" +IVE_TV_APP_ID = "com.webos.app.livetv" ATTR_SOUND_OUTPUT = "sound_output" From adc66adf5ed813684aa010edabdfe16cc6fa094a Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 26 Jan 2020 22:33:54 +0100 Subject: [PATCH 13/20] Change order --- homeassistant/components/webostv/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homeassistant/components/webostv/__init__.py b/homeassistant/components/webostv/__init__.py index 8e32a355b7aab..cf7e3a9b9c1d6 100644 --- a/homeassistant/components/webostv/__init__.py +++ b/homeassistant/components/webostv/__init__.py @@ -3,6 +3,7 @@ import logging from aiopylgtv import PyLGTVCmdException, PyLGTVPairException, WebOsClient +from const import ATTR_SOUND_OUTPUT import voluptuous as vol from websockets.exceptions import ConnectionClosed @@ -17,8 +18,6 @@ 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" From 7b480e349a100f43e113293a51930f5785931dab Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 26 Jan 2020 22:35:55 +0100 Subject: [PATCH 14/20] Change order --- homeassistant/components/webostv/media_player.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/homeassistant/components/webostv/media_player.py b/homeassistant/components/webostv/media_player.py index 05d70ddc29e50..925d011536be5 100644 --- a/homeassistant/components/webostv/media_player.py +++ b/homeassistant/components/webostv/media_player.py @@ -5,6 +5,7 @@ import logging from aiopylgtv import PyLGTVCmdException, PyLGTVPairException +from const import LIVE_TV_APP_ID, ATTR_SOUND_OUTPUT from websockets.exceptions import ConnectionClosed from homeassistant import util @@ -37,10 +38,6 @@ from . import CONF_ON_ACTION, CONF_SOURCES, DOMAIN - -from const import LIVE_TV_APP_ID, ATTR_SOUND_OUTPUT - - _LOGGER = logging.getLogger(__name__) From e9a222ad5f097b93529bea558d33d24c608a5326 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 26 Jan 2020 22:41:28 +0100 Subject: [PATCH 15/20] Fix import --- homeassistant/components/webostv/media_player.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/webostv/media_player.py b/homeassistant/components/webostv/media_player.py index 925d011536be5..35adb31583f01 100644 --- a/homeassistant/components/webostv/media_player.py +++ b/homeassistant/components/webostv/media_player.py @@ -5,7 +5,7 @@ import logging from aiopylgtv import PyLGTVCmdException, PyLGTVPairException -from const import LIVE_TV_APP_ID, ATTR_SOUND_OUTPUT +from .const import LIVE_TV_APP_ID, ATTR_SOUND_OUTPUT from websockets.exceptions import ConnectionClosed from homeassistant import util From f13f4faecaf05397fe78747647f649f30652a30a Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 26 Jan 2020 22:42:20 +0100 Subject: [PATCH 16/20] Fix import --- homeassistant/components/webostv/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/webostv/__init__.py b/homeassistant/components/webostv/__init__.py index cf7e3a9b9c1d6..352364c9b9951 100644 --- a/homeassistant/components/webostv/__init__.py +++ b/homeassistant/components/webostv/__init__.py @@ -3,7 +3,7 @@ import logging from aiopylgtv import PyLGTVCmdException, PyLGTVPairException, WebOsClient -from const import ATTR_SOUND_OUTPUT +from .const import ATTR_SOUND_OUTPUT import voluptuous as vol from websockets.exceptions import ConnectionClosed From b7db7bdb8ab0962b40b1d9d09b74266f2b7667c9 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 26 Jan 2020 22:43:11 +0100 Subject: [PATCH 17/20] Fix typo --- homeassistant/components/webostv/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/webostv/const.py b/homeassistant/components/webostv/const.py index a42ea0345783a..a81696f6c0bae 100644 --- a/homeassistant/components/webostv/const.py +++ b/homeassistant/components/webostv/const.py @@ -1,4 +1,4 @@ """Constants used for WebOS TV.""" -IVE_TV_APP_ID = "com.webos.app.livetv" +LIVE_TV_APP_ID = "com.webos.app.livetv" ATTR_SOUND_OUTPUT = "sound_output" From 2d9087f245616462a2fbe49fccdff25984adb6e6 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 26 Jan 2020 22:54:04 +0100 Subject: [PATCH 18/20] Change order again --- homeassistant/components/webostv/media_player.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/webostv/media_player.py b/homeassistant/components/webostv/media_player.py index 35adb31583f01..c32c18126ea71 100644 --- a/homeassistant/components/webostv/media_player.py +++ b/homeassistant/components/webostv/media_player.py @@ -5,7 +5,6 @@ import logging from aiopylgtv import PyLGTVCmdException, PyLGTVPairException -from .const import LIVE_TV_APP_ID, ATTR_SOUND_OUTPUT from websockets.exceptions import ConnectionClosed from homeassistant import util @@ -37,6 +36,7 @@ from homeassistant.helpers.script import Script from . import CONF_ON_ACTION, CONF_SOURCES, DOMAIN +from .const import LIVE_TV_APP_ID, ATTR_SOUND_OUTPUT _LOGGER = logging.getLogger(__name__) From 27a9950fe0ff5b577ecdc03415774bc29f646849 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 26 Jan 2020 22:56:31 +0100 Subject: [PATCH 19/20] Change order again --- homeassistant/components/webostv/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/webostv/__init__.py b/homeassistant/components/webostv/__init__.py index 352364c9b9951..9dec8fe0c71eb 100644 --- a/homeassistant/components/webostv/__init__.py +++ b/homeassistant/components/webostv/__init__.py @@ -3,7 +3,6 @@ import logging from aiopylgtv import PyLGTVCmdException, PyLGTVPairException, WebOsClient -from .const import ATTR_SOUND_OUTPUT import voluptuous as vol from websockets.exceptions import ConnectionClosed @@ -18,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" From a9b4bef6dc8d914549248e7a5607b8ed5f4b2a13 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Mon, 27 Jan 2020 07:34:13 +0100 Subject: [PATCH 20/20] Change order of attributes --- homeassistant/components/webostv/media_player.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/webostv/media_player.py b/homeassistant/components/webostv/media_player.py index c32c18126ea71..708db5ca679d2 100644 --- a/homeassistant/components/webostv/media_player.py +++ b/homeassistant/components/webostv/media_player.py @@ -36,7 +36,7 @@ from homeassistant.helpers.script import Script from . import CONF_ON_ACTION, CONF_SOURCES, DOMAIN -from .const import LIVE_TV_APP_ID, ATTR_SOUND_OUTPUT +from .const import ATTR_SOUND_OUTPUT, LIVE_TV_APP_ID _LOGGER = logging.getLogger(__name__)