-
-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Support SELECT_SOURCE for Bose soundtouch #31071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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]), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this option? If we know what the device supports, we can just return that list of sources in the media player entity source list.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/CharlesBlonde/libsoundtouch , this library is not updated 2 years. no api to get sources that device supported.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it make sense to bump libsoundtouch to 0.8.0 since HA is currently using an even older version?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw - this might be an alternative in future? Just found it https://github.com/trunet/aiobosest
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We like asyncio! If that works it might be a very nice replacement! The repo looks a bit dormant though.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
in this pr, libsoundtouch lib already be updated to 0.8.0
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the sources could be fetched from the api if the library would support it, I don't think adding this config option is a good step forward. We want to avoid config options as much as possible. Please update or change library first, in a separate PR, and then we see if this PR is still needed.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is a pending PR over at libsoundtouch which would add a source list, but the maintainer didn't respond to PRs in over a year. CharlesBlonde/libsoundtouch#34
Yes, the author of it commented that he wrote it for HA back then but the guys implementing the HA component went with libsoundtouch instead, which is why he stopped working on it. But he seems to be interested in working on it and implement the missing features if we (HA) considers to switch to it. I'm not saying we have to or should, especially since libsoundtouch is well documented and it's always a pitty if well used projects either have to be forked or abandoned.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the maintainer of https://github.com/trunet/aiobosest is active and the maintainer of https://github.com/CharlesBlonde/libsoundtouch is not, I suggest we change to the active library. |
||
| } | ||
| ) | ||
|
|
||
|
|
@@ -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() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check that the source is one of the supported sources of the library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/CharlesBlonde/libsoundtouch , this library is not updated 2 years. no api to check source
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have the enum
Sourceavailable from the library. Can't we use that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HDMI_1 ~ HDMI_6, and something else, not belong to source, but sourceAccount.
sourceAccount not enum in the library.
sources from device:
