diff --git a/homeassistant/components/soundtouch/const.py b/homeassistant/components/soundtouch/const.py index 37bf1d8cc2b9ad..8ae81d12a2e8c7 100644 --- a/homeassistant/components/soundtouch/const.py +++ b/homeassistant/components/soundtouch/const.py @@ -1,6 +1,14 @@ """Constants for the Bose Soundtouch component.""" +from enum import Enum + DOMAIN = "soundtouch" SERVICE_PLAY_EVERYWHERE = "play_everywhere" SERVICE_CREATE_ZONE = "create_zone" SERVICE_ADD_ZONE_SLAVE = "add_zone_slave" SERVICE_REMOVE_ZONE_SLAVE = "remove_zone_slave" + + +class ExtendSource(Enum): + """new sources supported by bose soundtouch.""" + + PRODUCT_SOURCE = "PRODUCT" diff --git a/homeassistant/components/soundtouch/manifest.json b/homeassistant/components/soundtouch/manifest.json index 25c4f7d1d1cf66..c8540b2d40f361 100644 --- a/homeassistant/components/soundtouch/manifest.json +++ b/homeassistant/components/soundtouch/manifest.json @@ -2,7 +2,7 @@ "domain": "soundtouch", "name": "Bose Soundtouch", "documentation": "https://www.home-assistant.io/integrations/soundtouch", - "requirements": ["libsoundtouch==0.7.2"], + "requirements": ["libsoundtouch==0.8.0"], "dependencies": [], "codeowners": [] } diff --git a/homeassistant/components/soundtouch/media_player.py b/homeassistant/components/soundtouch/media_player.py index 72677995a9d6b3..031bbae2d4575e 100644 --- a/homeassistant/components/soundtouch/media_player.py +++ b/homeassistant/components/soundtouch/media_player.py @@ -3,6 +3,7 @@ import re from libsoundtouch import soundtouch_device +from libsoundtouch.utils import Source import voluptuous as vol from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerDevice @@ -12,6 +13,7 @@ SUPPORT_PLAY, SUPPORT_PLAY_MEDIA, SUPPORT_PREVIOUS_TRACK, + SUPPORT_SELECT_SOURCE, SUPPORT_TURN_OFF, SUPPORT_TURN_ON, SUPPORT_VOLUME_MUTE, @@ -22,6 +24,9 @@ CONF_HOST, CONF_NAME, CONF_PORT, + CONF_RESOURCES, + CONF_SOURCE, + STATE_IDLE, STATE_OFF, STATE_PAUSED, STATE_PLAYING, @@ -35,6 +40,7 @@ SERVICE_CREATE_ZONE, SERVICE_PLAY_EVERYWHERE, SERVICE_REMOVE_ZONE_SLAVE, + ExtendSource, ) _LOGGER = logging.getLogger(__name__) @@ -44,6 +50,7 @@ "BUFFERING_STATE": STATE_PLAYING, "PAUSE_STATE": STATE_PAUSED, "STOP_STATE": STATE_OFF, + "INVALID_PLAY_STATUS": STATE_IDLE, } DATA_SOUNDTOUCH = "soundtouch" @@ -78,11 +85,16 @@ | SUPPORT_PLAY_MEDIA ) +SOURCE_SCHEMA = vol.Schema( + {vol.Required(CONF_SOURCE): cv.string, vol.Required(CONF_NAME): cv.string} +) + PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Required(CONF_HOST): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, + vol.Optional(CONF_RESOURCES): vol.All(cv.ensure_list, [SOURCE_SCHEMA]), } ) @@ -100,7 +112,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None): if host in [device.config["host"] for device in hass.data[DATA_SOUNDTOUCH]]: return - remote_config = {"id": "ha.component.soundtouch", "host": host, "port": port} + remote_config = { + "id": "ha.component.soundtouch", + "host": host, + "port": port, + "resources": None, + } bose_soundtouch_entity = SoundTouchDevice(None, remote_config) hass.data[DATA_SOUNDTOUCH].append(bose_soundtouch_entity) add_entities([bose_soundtouch_entity]) @@ -110,6 +127,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): "id": "ha.component.soundtouch", "port": config.get(CONF_PORT), "host": config.get(CONF_HOST), + "resources": config.get(CONF_RESOURCES), } bose_soundtouch_entity = SoundTouchDevice(name, remote_config) hass.data[DATA_SOUNDTOUCH].append(bose_soundtouch_entity) @@ -194,6 +212,19 @@ def __init__(self, name, config): self._status = self._device.status() self._volume = self._device.volume() self._config = config + self._supported_features = SUPPORT_SOUNDTOUCH + self._resources = config["resources"] + self._sources = [] + self._sourcename = {} + self._namesource = {} + if self._resources: + self._supported_features |= SUPPORT_SELECT_SOURCE + for pair in self._resources: + source = pair["source"].upper() + name = pair["name"] + self._sources.append(name) + self._sourcename[source] = name + self._namesource[name] = source @property def config(self): @@ -225,7 +256,7 @@ def state(self): """Return the state of the device.""" if self._status.source == "STANDBY": return STATE_OFF - + _LOGGER.debug("soundtouch state: %s", self._status) return MAP_STATUS.get(self._status.play_status, STATE_UNAVAILABLE) @property @@ -236,7 +267,7 @@ def is_volume_muted(self): @property def supported_features(self): """Flag media player features that are supported.""" - return SUPPORT_SOUNDTOUCH + return self._supported_features def turn_off(self): """Turn off media player.""" @@ -398,3 +429,26 @@ def add_zone_slave(self, slaves): "Adding slaves to zone with master %s", self._device.config.name ) self._device.add_zone_slave([slave.device for slave in slaves]) + + @property + def source_list(self): + """List of available input sources.""" + return self._sources + + @property + def source(self): + """Return the current input source.""" + return self._sourcename.get(self._status.source) + + def select_source(self, source): + """Set the input source.""" + source_account = ( + source if source in self._sourcename else self._namesource.get(source) + ) + if source_account == Source.BLUETOOTH.value: + self._device.select_source_bluetooth() + elif source_account: + self._device.select_content_item( + ExtendSource.PRODUCT_SOURCE, source_account + ) + self._status = self._device.status() diff --git a/requirements_all.txt b/requirements_all.txt index ef2c85373e6003..e81ad690945152 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -778,7 +778,7 @@ libpyvivotek==0.4.0 librouteros==3.0.0 # homeassistant.components.soundtouch -libsoundtouch==0.7.2 +libsoundtouch==0.8.0 # homeassistant.components.life360 life360==4.1.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 7ed5c31ca49bab..14c25025f2bc90 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -281,7 +281,7 @@ keyrings.alt==3.4.0 libpurecool==0.6.0 # homeassistant.components.soundtouch -libsoundtouch==0.7.2 +libsoundtouch==0.8.0 # homeassistant.components.logi_circle logi_circle==0.2.2