mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add webostv sound_output capability (#31121)
* Webostv: add sound_output capability Add the ability to read and set the sound_output * Webostv: add sound_output capability * Webostv: add sound_output capability * fix blank spaces * fix to long line * add , * Import ATTR_SOUND_OUTPUT Do not have the ability to test this change right now * Add white space * Create const.py * Use const import * Use import from const.py * Add docstring * Change order * Change order * Fix import * Fix import * Fix typo * Change order again * Change order again * Change order of attributes
This commit is contained in:
parent
1f0f62de7f
commit
1278f32306
@ -17,6 +17,8 @@ from homeassistant.const import (
|
||||
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 @@ 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])}
|
||||
)
|
||||
@ -60,9 +64,15 @@ BUTTON_SCHEMA = CALL_SCHEMA.extend({vol.Required(ATTR_BUTTON): cv.string})
|
||||
|
||||
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__)
|
||||
|
4
homeassistant/components/webostv/const.py
Normal file
4
homeassistant/components/webostv/const.py
Normal file
@ -0,0 +1,4 @@
|
||||
"""Constants used for WebOS TV."""
|
||||
LIVE_TV_APP_ID = "com.webos.app.livetv"
|
||||
|
||||
ATTR_SOUND_OUTPUT = "sound_output"
|
@ -36,13 +36,11 @@ 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__)
|
||||
|
||||
|
||||
LIVETV_APP_ID = "com.webos.app.livetv"
|
||||
|
||||
|
||||
SUPPORT_WEBOSTV = (
|
||||
SUPPORT_TURN_OFF
|
||||
| SUPPORT_NEXT_TRACK
|
||||
@ -59,8 +57,6 @@ SUPPORT_WEBOSTV = (
|
||||
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."""
|
||||
@ -289,6 +285,14 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice):
|
||||
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."""
|
||||
@ -320,6 +324,11 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice):
|
||||
"""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."""
|
||||
@ -396,7 +405,7 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice):
|
||||
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()
|
||||
@ -405,7 +414,7 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice):
|
||||
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()
|
||||
|
@ -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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user