Update vlc.py

Added support for additional optional configuration

arguments:

to send to vlc.
It is useful for special configurations of VLC.
For example, I have two sound cards on my server, so I defined two vlc media players:

media_player:
- platform: vlc
  name: speaker_1
  arguments: '--alsa-audio-device=hw:1,0'
- platform: vlc
  name: speaker_2
  arguments: '--alsa-audio-device=hw:0,0'

This way, by specifying the corresponding entity_id, I can send the output to the desired speaker.
It is also useful for TTS.
This commit is contained in:
Gianluca Barbaro 2017-01-14 22:30:24 +01:00 committed by GitHub
parent 3b9fb6ccf5
commit 3d9b2b5ed0

View File

@ -20,28 +20,30 @@ REQUIREMENTS = ['python-vlc==1.1.2']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
ADDITIONAL_ARGS = 'arguments'
SUPPORT_VLC = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \ SUPPORT_VLC = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
SUPPORT_PLAY_MEDIA | SUPPORT_PLAY SUPPORT_PLAY_MEDIA | SUPPORT_PLAY
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_NAME): cv.string, vol.Optional(CONF_NAME): cv.string,
vol.Optional(ADDITIONAL_ARGS): cv.string,
}) })
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the vlc platform.""" """Setup the vlc platform."""
add_devices([VlcDevice(config.get(CONF_NAME))]) add_devices([VlcDevice(config.get(CONF_NAME), config.get(ADDITIONAL_ARGS))])
class VlcDevice(MediaPlayerDevice): class VlcDevice(MediaPlayerDevice):
"""Representation of a vlc player.""" """Representation of a vlc player."""
def __init__(self, name): def __init__(self, name, arguments):
"""Initialize the vlc device.""" """Initialize the vlc device."""
import vlc import vlc
self._instance = vlc.Instance() self._instance = vlc.Instance(arguments)
self._vlc = self._instance.media_player_new() self._vlc = self._instance.media_player_new()
self._name = name self._name = name
self._volume = None self._volume = None