Update volumio component (#12045)
This commit is contained in:
parent
13ec8b143d
commit
730e0a0094
1 changed files with 49 additions and 3 deletions
|
@ -4,6 +4,7 @@ Volumio Platform.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/media_player.volumio/
|
||||
"""
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
import asyncio
|
||||
import aiohttp
|
||||
|
@ -13,11 +14,13 @@ import voluptuous as vol
|
|||
from homeassistant.components.media_player import (
|
||||
SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PREVIOUS_TRACK, SUPPORT_SEEK,
|
||||
SUPPORT_PLAY_MEDIA, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET, SUPPORT_STOP,
|
||||
SUPPORT_PLAY, MediaPlayerDevice, PLATFORM_SCHEMA, MEDIA_TYPE_MUSIC)
|
||||
SUPPORT_PLAY, MediaPlayerDevice, PLATFORM_SCHEMA, MEDIA_TYPE_MUSIC,
|
||||
SUPPORT_VOLUME_STEP, SUPPORT_SELECT_SOURCE, SUPPORT_CLEAR_PLAYLIST)
|
||||
from homeassistant.const import (
|
||||
STATE_PLAYING, STATE_PAUSED, STATE_IDLE, CONF_HOST, CONF_PORT, CONF_NAME)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.util import Throttle
|
||||
|
||||
_CONFIGURING = {}
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -30,8 +33,10 @@ TIMEOUT = 10
|
|||
|
||||
SUPPORT_VOLUMIO = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
|
||||
SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK | SUPPORT_SEEK | \
|
||||
SUPPORT_PLAY_MEDIA | SUPPORT_STOP | SUPPORT_PLAY
|
||||
SUPPORT_PLAY_MEDIA | SUPPORT_STOP | SUPPORT_PLAY | \
|
||||
SUPPORT_VOLUME_STEP | SUPPORT_SELECT_SOURCE | SUPPORT_CLEAR_PLAYLIST
|
||||
|
||||
PLAYLIST_UPDATE_INTERVAL = timedelta(seconds=15)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string,
|
||||
|
@ -63,6 +68,8 @@ class Volumio(MediaPlayerDevice):
|
|||
self._state = {}
|
||||
self.async_update()
|
||||
self._lastvol = self._state.get('volume', 0)
|
||||
self._playlists = []
|
||||
self._currentplaylist = None
|
||||
|
||||
@asyncio.coroutine
|
||||
def send_volumio_msg(self, method, params=None):
|
||||
|
@ -96,6 +103,7 @@ class Volumio(MediaPlayerDevice):
|
|||
def async_update(self):
|
||||
"""Update state."""
|
||||
resp = yield from self.send_volumio_msg('getState')
|
||||
yield from self._async_update_playlists()
|
||||
if resp is False:
|
||||
return
|
||||
self._state = resp.copy()
|
||||
|
@ -157,7 +165,7 @@ class Volumio(MediaPlayerDevice):
|
|||
def volume_level(self):
|
||||
"""Volume level of the media player (0..1)."""
|
||||
volume = self._state.get('volume', None)
|
||||
if volume is not None:
|
||||
if volume is not None and volume != "":
|
||||
volume = volume / 100
|
||||
return volume
|
||||
|
||||
|
@ -171,6 +179,16 @@ class Volumio(MediaPlayerDevice):
|
|||
"""Return the name of the device."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def source_list(self):
|
||||
"""Return the list of available input sources."""
|
||||
return self._playlists
|
||||
|
||||
@property
|
||||
def source(self):
|
||||
"""Name of the current input source."""
|
||||
return self._currentplaylist
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Flag of media commands that are supported."""
|
||||
|
@ -199,6 +217,16 @@ class Volumio(MediaPlayerDevice):
|
|||
return self.send_volumio_msg(
|
||||
'commands', params={'cmd': 'volume', 'volume': int(volume * 100)})
|
||||
|
||||
def async_volume_up(self):
|
||||
"""Service to send the Volumio the command for volume up."""
|
||||
return self.send_volumio_msg(
|
||||
'commands', params={'cmd': 'volume', 'volume': 'plus'})
|
||||
|
||||
def async_volume_down(self):
|
||||
"""Service to send the Volumio the command for volume down."""
|
||||
return self.send_volumio_msg(
|
||||
'commands', params={'cmd': 'volume', 'volume': 'minus'})
|
||||
|
||||
def async_mute_volume(self, mute):
|
||||
"""Send mute command to media player."""
|
||||
mutecmd = 'mute' if mute else 'unmute'
|
||||
|
@ -210,3 +238,21 @@ class Volumio(MediaPlayerDevice):
|
|||
|
||||
return self.send_volumio_msg(
|
||||
'commands', params={'cmd': 'volume', 'volume': self._lastvol})
|
||||
|
||||
def async_select_source(self, source):
|
||||
"""Choose a different available playlist and play it."""
|
||||
self._currentplaylist = source
|
||||
return self.send_volumio_msg(
|
||||
'commands', params={'cmd': 'playplaylist', 'name': source})
|
||||
|
||||
def async_clear_playlist(self):
|
||||
"""Clear players playlist."""
|
||||
# FIXME
|
||||
self._currentplaylist = None
|
||||
return self.send_volumio_msg('clearQueue')
|
||||
|
||||
@asyncio.coroutine
|
||||
@Throttle(PLAYLIST_UPDATE_INTERVAL)
|
||||
def _async_update_playlists(self, **kwargs):
|
||||
"""Update available Volumio playlists."""
|
||||
self._playlists = yield from self.send_volumio_msg('listplaylists')
|
||||
|
|
Loading…
Add table
Reference in a new issue