mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
snapcast update (#3012)
* snapcast update * snapcast update * validate config * use conf constants
This commit is contained in:
parent
b4df9b30d8
commit
451f0cb3f1
@ -6,30 +6,35 @@ https://home-assistant.io/components/media_player.snapcast/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
|
import voluptuous as vol
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
from homeassistant.components.media_player import (
|
from homeassistant.components.media_player import (
|
||||||
SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET, SUPPORT_SELECT_SOURCE,
|
SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET, SUPPORT_SELECT_SOURCE,
|
||||||
MediaPlayerDevice)
|
PLATFORM_SCHEMA, MediaPlayerDevice)
|
||||||
from homeassistant.const import (
|
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_SNAPCAST = SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
|
||||||
SUPPORT_SELECT_SOURCE
|
SUPPORT_SELECT_SOURCE
|
||||||
|
|
||||||
DOMAIN = 'snapcast'
|
DOMAIN = 'snapcast'
|
||||||
REQUIREMENTS = ['snapcast==1.2.1']
|
REQUIREMENTS = ['snapcast==1.2.2']
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_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
|
# 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 Snapcast platform."""
|
"""Setup the Snapcast platform."""
|
||||||
import snapcast.control
|
import snapcast.control
|
||||||
host = config.get('host')
|
host = config.get(CONF_HOST)
|
||||||
port = config.get('port', snapcast.control.CONTROL_PORT)
|
port = config.get(CONF_PORT, snapcast.control.CONTROL_PORT)
|
||||||
if not host:
|
|
||||||
_LOGGER.error('No snapserver host specified')
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
server = snapcast.control.Snapserver(host, port)
|
server = snapcast.control.Snapserver(host, port)
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
@ -75,18 +80,18 @@ class SnapcastDevice(MediaPlayerDevice):
|
|||||||
return {
|
return {
|
||||||
'idle': STATE_IDLE,
|
'idle': STATE_IDLE,
|
||||||
'playing': STATE_PLAYING,
|
'playing': STATE_PLAYING,
|
||||||
'unkown': STATE_UNKNOWN,
|
'unknown': STATE_UNKNOWN,
|
||||||
}.get(self._client.stream.status, STATE_UNKNOWN)
|
}.get(self._client.stream.status, STATE_UNKNOWN)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source(self):
|
def source(self):
|
||||||
"""Return the current input source."""
|
"""Return the current input source."""
|
||||||
return self._client.stream.identifier
|
return self._client.stream.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source_list(self):
|
def source_list(self):
|
||||||
"""List of available input sources."""
|
"""List of available input sources."""
|
||||||
return self._client.available_streams()
|
return list(self._client.streams_by_name().keys())
|
||||||
|
|
||||||
def mute_volume(self, mute):
|
def mute_volume(self, mute):
|
||||||
"""Send the mute command."""
|
"""Send the mute command."""
|
||||||
@ -98,4 +103,6 @@ class SnapcastDevice(MediaPlayerDevice):
|
|||||||
|
|
||||||
def select_source(self, source):
|
def select_source(self, source):
|
||||||
"""Set input 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
|
sleekxmpp==1.3.1
|
||||||
|
|
||||||
# homeassistant.components.media_player.snapcast
|
# homeassistant.components.media_player.snapcast
|
||||||
snapcast==1.2.1
|
snapcast==1.2.2
|
||||||
|
|
||||||
# homeassistant.components.climate.honeywell
|
# homeassistant.components.climate.honeywell
|
||||||
# homeassistant.components.thermostat.honeywell
|
# homeassistant.components.thermostat.honeywell
|
||||||
|
Loading…
x
Reference in New Issue
Block a user