Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions homeassistant/components/soundtouch/const.py
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"
2 changes: 1 addition & 1 deletion homeassistant/components/soundtouch/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
60 changes: 57 additions & 3 deletions homeassistant/components/soundtouch/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,6 +13,7 @@
SUPPORT_PLAY,
SUPPORT_PLAY_MEDIA,
SUPPORT_PREVIOUS_TRACK,
SUPPORT_SELECT_SOURCE,
SUPPORT_TURN_OFF,
SUPPORT_TURN_ON,
SUPPORT_VOLUME_MUTE,
Expand All @@ -22,6 +24,9 @@
CONF_HOST,
CONF_NAME,
CONF_PORT,
CONF_RESOURCES,
CONF_SOURCE,
STATE_IDLE,
STATE_OFF,
STATE_PAUSED,
STATE_PLAYING,
Expand All @@ -35,6 +40,7 @@
SERVICE_CREATE_ZONE,
SERVICE_PLAY_EVERYWHERE,
SERVICE_REMOVE_ZONE_SLAVE,
ExtendSource,
)

_LOGGER = logging.getLogger(__name__)
Expand All @@ -44,6 +50,7 @@
"BUFFERING_STATE": STATE_PLAYING,
"PAUSE_STATE": STATE_PAUSED,
"STOP_STATE": STATE_OFF,
"INVALID_PLAY_STATUS": STATE_IDLE,
}

DATA_SOUNDTOUCH = "soundtouch"
Expand Down Expand Up @@ -78,11 +85,16 @@
| SUPPORT_PLAY_MEDIA
)

SOURCE_SCHEMA = vol.Schema(
{vol.Required(CONF_SOURCE): cv.string, vol.Required(CONF_NAME): cv.string}
Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the enum Source available from the library. Can't we use that?

Copy link
Copy Markdown
Contributor Author

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:
image

)

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]),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor Author

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 get sources that device supported.
so config sources to configuration.yaml

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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?

in this pr, libsoundtouch lib already be updated to 0.8.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor

@da-anda da-anda Jan 23, 2020

Choose a reason for hiding this comment

The 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

The repo looks a bit dormant though.

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.
CharlesBlonde/libsoundtouch#38

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.

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare Jan 23, 2020

Choose a reason for hiding this comment

The 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.

}
)

Expand All @@ -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])
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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."""
Expand Down Expand Up @@ -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()
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down