snapcast update (#3012)
* snapcast update * snapcast update * validate config * use conf constants
This commit is contained in:
parent
b4df9b30d8
commit
451f0cb3f1
2 changed files with 20 additions and 13 deletions
|
@ -6,30 +6,35 @@ https://home-assistant.io/components/media_player.snapcast/
|
|||
"""
|
||||
import logging
|
||||
import socket
|
||||
import voluptuous as vol
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
from homeassistant.components.media_player import (
|
||||
SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET, SUPPORT_SELECT_SOURCE,
|
||||
MediaPlayerDevice)
|
||||
PLATFORM_SCHEMA, MediaPlayerDevice)
|
||||
from homeassistant.const import (
|
||||
STATE_OFF, STATE_IDLE, STATE_PLAYING, STATE_UNKNOWN)
|
||||
STATE_OFF, STATE_IDLE, STATE_PLAYING, STATE_UNKNOWN,
|
||||
CONF_HOST, CONF_PORT)
|
||||
|
||||
SUPPORT_SNAPCAST = SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
|
||||
SUPPORT_SELECT_SOURCE
|
||||
|
||||
DOMAIN = 'snapcast'
|
||||
REQUIREMENTS = ['snapcast==1.2.1']
|
||||
REQUIREMENTS = ['snapcast==1.2.2']
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Optional(CONF_PORT): cv.port
|
||||
})
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the Snapcast platform."""
|
||||
import snapcast.control
|
||||
host = config.get('host')
|
||||
port = config.get('port', snapcast.control.CONTROL_PORT)
|
||||
if not host:
|
||||
_LOGGER.error('No snapserver host specified')
|
||||
return
|
||||
host = config.get(CONF_HOST)
|
||||
port = config.get(CONF_PORT, snapcast.control.CONTROL_PORT)
|
||||
try:
|
||||
server = snapcast.control.Snapserver(host, port)
|
||||
except socket.gaierror:
|
||||
|
@ -75,18 +80,18 @@ class SnapcastDevice(MediaPlayerDevice):
|
|||
return {
|
||||
'idle': STATE_IDLE,
|
||||
'playing': STATE_PLAYING,
|
||||
'unkown': STATE_UNKNOWN,
|
||||
'unknown': STATE_UNKNOWN,
|
||||
}.get(self._client.stream.status, STATE_UNKNOWN)
|
||||
|
||||
@property
|
||||
def source(self):
|
||||
"""Return the current input source."""
|
||||
return self._client.stream.identifier
|
||||
return self._client.stream.name
|
||||
|
||||
@property
|
||||
def source_list(self):
|
||||
"""List of available input sources."""
|
||||
return self._client.available_streams()
|
||||
return list(self._client.streams_by_name().keys())
|
||||
|
||||
def mute_volume(self, mute):
|
||||
"""Send the mute command."""
|
||||
|
@ -98,4 +103,6 @@ class SnapcastDevice(MediaPlayerDevice):
|
|||
|
||||
def select_source(self, source):
|
||||
"""Set input source."""
|
||||
self._client.stream = source
|
||||
streams = self._client.streams_by_name()
|
||||
if source in streams:
|
||||
self._client.stream = streams[source].identifier
|
||||
|
|
|
@ -431,7 +431,7 @@ slacker==0.9.24
|
|||
sleekxmpp==1.3.1
|
||||
|
||||
# homeassistant.components.media_player.snapcast
|
||||
snapcast==1.2.1
|
||||
snapcast==1.2.2
|
||||
|
||||
# homeassistant.components.climate.honeywell
|
||||
# homeassistant.components.thermostat.honeywell
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue