thlucas1 / homeassistantcomponent_soundtouchplus

Home Assistant integration for Bose SoundTouch speakers
MIT License
14 stars 1 forks source link

Trying to get soundtocuhplus devices work with Music Assistant or as a DLNA Media Renderer #24

Open override80 opened 1 day ago

override80 commented 1 day ago

System Health details

System Information

version core-2024.11.3
installation_type Home Assistant Supervised
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.12.4
os_name Linux
os_version 6.1.0-25-amd64
arch x86_64
timezone Europe/Rome
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok HACS Data | ok GitHub API Calls Remaining | 5000 Installed Version | 2.0.1 Stage | running Available Repositories | 1488 Downloaded Repositories | 113
AccuWeather can_reach_server | ok -- | -- remaining_requests | 11
Home Assistant Supervisor host_os | Debian GNU/Linux 12 (bookworm) -- | -- update_channel | stable supervisor_version | supervisor-2024.11.4 agent_version | 1.6.0 docker_version | 27.2.1 disk_total | 453.2 GB disk_used | 135.6 GB healthy | true supported | true host_connectivity | true supervisor_connectivity | true ntp_synchronized | true virtualization | supervisor_api | ok version_api | ok installed_addons | AppDaemon (0.16.7), Home Assistant Google Drive Backup (0.112.1), Let's Encrypt (5.2.5), MariaDB (2.7.1), NGINX Home Assistant SSL proxy (3.11.1), TasmoAdmin (0.31.0), Rhasspy Assistant (2.5.11), Hikvision Doorbell (3.0.19), ESPHome Device Compiler (2024.11.1), Prowlarr NAS (nightly-1.27.0.4846-ls104), FlareSolverr (3.3.21), Radarr (5.15.1.9463), Sonarr (4.0.10.2656), Network UPS Tools (0.13.2), Jellyseerr (2.1.0), Exadel CompreFace (1.1.0), Portainer (2.24.0), Piper (1.5.2), Whisper (2.2.0), openWakeWord (1.10.0), Cloudflared (5.2.2), Jellyfin NAS (10.10.3), Music Assistant Server (2.3.3), qBittorrent (5.0.2), Frigate (Full Access) (0.14.1), Double Take (1.13.11.8), Rclone Backup (3.3.2), OpenVPN Client (0.0.2), UniFi Network Application (3.5.0), EMQX (0.7.2), phpMyAdmin (0.10.0)
Dashboards dashboards | 8 -- | -- resources | 62 views | 36 mode | storage
Recorder oldest_recorder_run | November 18, 2024 at 7:16 AM -- | -- current_recorder_run | November 26, 2024 at 4:13 PM estimated_db_size | 5379.84 MiB database_engine | mysql database_version | 10.11.6
Solcast PV Forecast can_reach_server | ok -- | --
Bose SoundTouch Plus integration_version | v1.0.72 -- | -- devices_configured | 4: SoundTouch 20 LivingRoom (SoundTouch 20), SoundTouch 10 Bedroom (SoundTouch 10), SoundTouch 10 Giulio (SoundTouch 10), SoundTouch 10 Gym (SoundTouch 10)
Spotify api_endpoint_reachable | ok -- | --
SpotifyPlus integration_version | v1.0.66 -- | -- clients_configured | 1: override (premium) api_endpoint_reachable | ok

Checklist

Describe the issue

Hi @thlucas1 , I'm wondering if you ever tried to use soundtouchplus devices with Music Assistant.

Until a few weeks ago, my soundtouch speakers were working correclty as DLNA Media Renderer and i used this DLNA devices to play music from Music Assistant.

Well, adding my soundtouchplus devices (ST10 and ST20) to Music Assistant directly as Home Assistant players (because for some reason DLNA Media renderer are "Unavailable") will not work until i change the source to "Notification" in the SoundTouchPlus home assistant media players. I have to manually do this every time on speakers that i want to use from Music Assistant. Problems are somehow expected (https://music-assistant.io/player-support/ha/).

If i switch the source to Upnp (which should be the one used by DLNA, afaiu) the device becomes unavailable and I have to go with the Bose SoundTouch App to play a song from spotify or wherever to have the device back in a proper state in Home Assistant.

I have opened an issue about the DLNA problem (https://github.com/home-assistant/core/issues/131537), It should not be related to SoundTouchPlus though.

Do you have any experience here? What's the best way to use Music Assistant with SoundTouchPlus devices (via Home Assistant Player Provider or via DLNA Player Provider? Consider that I also use SoundTouch devices to TTS notifications)?

Thanks!

PS I also have no idea why it goes to unknown when I play via Music Assistant as an Home Assistant Player: image

On the ST-20 i get clear errors in logs:

2024-11-26 19:11:19.070 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139872469585776] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2802, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2845, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 989, in entity_service_call
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Entity media_player.soundtouch_10_bedroom_dlna does not support this service.
2024-11-26 19:14:34.983 ERROR (SyncWorker_53) [bosesoundtouchapi.soundtouchclient] SoundTouchError: "BST1002E - 'SoundTouch 20 LivingRoom': SoundTouch Web-services API returned an error status: 'unsupported device'", code="403", name="HTTP_STATUS_FORBIDDEN", severity="Unknown"
2024-11-26 19:14:34.984 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139872469585776] Unexpected exception
Traceback (most recent call last):
  File "/config/custom_components/soundtouchplus/media_player.py", line 916, in play_media
    self._client.PlayUrl(media_id, artist=announceValue, album=announceValue, getMetaDataFromUrlFile=True, volumeLevel=0)
  File "/usr/local/lib/python3.12/site-packages/bosesoundtouchapi/soundtouchclient.py", line 3048, in PlayUrl
    self.MakeRequest('POST', message)
  File "/usr/local/lib/python3.12/site-packages/bosesoundtouchapi/soundtouchclient.py", line 2445, in MakeRequest
    self._CheckResponseForErrors(msg.Response)
  File "/usr/local/lib/python3.12/site-packages/bosesoundtouchapi/soundtouchclient.py", line 307, in _CheckResponseForErrors
    raise SoundTouchError(errMessage, errName, errSeverity, errValue, _logsi)
bosesoundtouchapi.soundtoucherror.SoundTouchError: SoundTouchError: "BST1002E - 'SoundTouch 20 LivingRoom': SoundTouch Web-services API returned an error status: 'unsupported device'", code="403", name="HTTP_STATUS_FORBIDDEN", severity="Unknown"

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/soundtouchplus/media_player.py", line 846, in async_play_media
    await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/soundtouchplus/media_player.py", line 949, in play_media
    raise HomeAssistantError(str(ex)) from ex
homeassistant.exceptions.HomeAssistantError: SoundTouchError: "BST1002E - 'SoundTouch 20 LivingRoom': SoundTouch Web-services API returned an error status: 'unsupported device'", code="403", name="HTTP_STATUS_FORBIDDEN", severity="Unknown"

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2802, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2845, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1007, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1079, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/soundtouchplus/media_player.py", line 854, in async_play_media
    raise HomeAssistantError(str(ex)) from ex
homeassistant.exceptions.HomeAssistantError: SoundTouchError: "BST1002E - 'SoundTouch 20 LivingRoom': SoundTouch Web-services API returned an error status: 'unsupported device'", code="403", name="HTTP_STATUS_FORBIDDEN", severity="Unknown"
2024-11-26 19:14:45.516 ERROR (SyncWorker_51) [bosesoundtouchapi.soundtouchclient] SoundTouchError: "BST1002E - 'SoundTouch 20 LivingRoom': SoundTouch Web-services API returned an error status: 'unsupported device'", code="403", name="HTTP_STATUS_FORBIDDEN", severity="Unknown"
2024-11-26 19:14:45.517 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139872469585776] Unexpected exception
Traceback (most recent call last):
  File "/config/custom_components/soundtouchplus/media_player.py", line 916, in play_media
    self._client.PlayUrl(media_id, artist=announceValue, album=announceValue, getMetaDataFromUrlFile=True, volumeLevel=0)
  File "/usr/local/lib/python3.12/site-packages/bosesoundtouchapi/soundtouchclient.py", line 3048, in PlayUrl
    self.MakeRequest('POST', message)
  File "/usr/local/lib/python3.12/site-packages/bosesoundtouchapi/soundtouchclient.py", line 2445, in MakeRequest
    self._CheckResponseForErrors(msg.Response)
  File "/usr/local/lib/python3.12/site-packages/bosesoundtouchapi/soundtouchclient.py", line 307, in _CheckResponseForErrors
    raise SoundTouchError(errMessage, errName, errSeverity, errValue, _logsi)
bosesoundtouchapi.soundtoucherror.SoundTouchError: SoundTouchError: "BST1002E - 'SoundTouch 20 LivingRoom': SoundTouch Web-services API returned an error status: 'unsupported device'", code="403", name="HTTP_STATUS_FORBIDDEN", severity="Unknown"

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/soundtouchplus/media_player.py", line 846, in async_play_media
    await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/soundtouchplus/media_player.py", line 949, in play_media
    raise HomeAssistantError(str(ex)) from ex
homeassistant.exceptions.HomeAssistantError: SoundTouchError: "BST1002E - 'SoundTouch 20 LivingRoom': SoundTouch Web-services API returned an error status: 'unsupported device'", code="403", name="HTTP_STATUS_FORBIDDEN", severity="Unknown"

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2802, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2845, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1007, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1079, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/soundtouchplus/media_player.py", line 854, in async_play_media
    raise HomeAssistantError(str(ex)) from ex
homeassistant.exceptions.HomeAssistantError: SoundTouchError: "BST1002E - 'SoundTouch 20 LivingRoom': SoundTouch Web-services API returned an error status: 'unsupported device'", code="403", name="HTTP_STATUS_FORBIDDEN", severity="Unknown"
2024-11-26 19:14:50.429 ERROR (SyncWorker_45) [bosesoundtouchapi.soundtouchclient] SoundTouchError: "BST1002E - 'SoundTouch 20 LivingRoom': SoundTouch Web-services API returned an error status: 'unsupported device'", code="403", name="HTTP_STATUS_FORBIDDEN", severity="Unknown"
2024-11-26 19:14:50.430 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139872469585776] Unexpected exception
Traceback (most recent call last):
  File "/config/custom_components/soundtouchplus/media_player.py", line 916, in play_media
    self._client.PlayUrl(media_id, artist=announceValue, album=announceValue, getMetaDataFromUrlFile=True, volumeLevel=0)
  File "/usr/local/lib/python3.12/site-packages/bosesoundtouchapi/soundtouchclient.py", line 3048, in PlayUrl
    self.MakeRequest('POST', message)
  File "/usr/local/lib/python3.12/site-packages/bosesoundtouchapi/soundtouchclient.py", line 2445, in MakeRequest
    self._CheckResponseForErrors(msg.Response)
  File "/usr/local/lib/python3.12/site-packages/bosesoundtouchapi/soundtouchclient.py", line 307, in _CheckResponseForErrors
    raise SoundTouchError(errMessage, errName, errSeverity, errValue, _logsi)
bosesoundtouchapi.soundtoucherror.SoundTouchError: SoundTouchError: "BST1002E - 'SoundTouch 20 LivingRoom': SoundTouch Web-services API returned an error status: 'unsupported device'", code="403", name="HTTP_STATUS_FORBIDDEN", severity="Unknown"

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/soundtouchplus/media_player.py", line 846, in async_play_media
    await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/soundtouchplus/media_player.py", line 949, in play_media
    raise HomeAssistantError(str(ex)) from ex
homeassistant.exceptions.HomeAssistantError: SoundTouchError: "BST1002E - 'SoundTouch 20 LivingRoom': SoundTouch Web-services API returned an error status: 'unsupported device'", code="403", name="HTTP_STATUS_FORBIDDEN", severity="Unknown"

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2802, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2845, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1007, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1079, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/soundtouchplus/media_player.py", line 854, in async_play_media
    raise HomeAssistantError(str(ex)) from ex
homeassistant.exceptions.HomeAssistantError: SoundTouchError: "BST1002E - 'SoundTouch 20 LivingRoom': SoundTouch Web-services API returned an error status: 'unsupported device'", code="403", name="HTTP_STATUS_FORBIDDEN", severity="Unknown"

but also on the ST-10 when trying to play via DLNA:

2024-11-26 19:17:29.032 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/xml/etree/ElementTree.py", line 1706, in feed
    self.parser.Parse(data, False)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 477, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/async_upnp_client/aiohttp.py", line 348, in _handle_request
    status = await self.event_handler.handle_notify(http_request)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/async_upnp_client/event_handler.py", line 167, in handle_notify
    service.notify_changed_state_variables(changes)
  File "/usr/local/lib/python3.12/site-packages/async_upnp_client/client.py", line 542, in notify_changed_state_variables
    self.on_event(self, changed_state_variables)
  File "/usr/local/lib/python3.12/site-packages/async_upnp_client/profiles/dlna.py", line 389, in _on_event
    dlna_handle_notify_last_change(state_variable)
  File "/usr/local/lib/python3.12/site-packages/async_upnp_client/profiles/dlna.py", line 215, in dlna_handle_notify_last_change
    service.notify_changed_state_variables(changes_0)
  File "/usr/local/lib/python3.12/site-packages/async_upnp_client/client.py", line 542, in notify_changed_state_variables
    self.on_event(self, changed_state_variables)
  File "/usr/local/lib/python3.12/site-packages/async_upnp_client/profiles/dlna.py", line 400, in _on_event
    self.on_event(service, state_variables)
  File "/usr/src/homeassistant/homeassistant/components/dlna_dmr/media_player.py", line 533, in _on_event
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/components/dlna_dmr/media_player.py", line 358, in async_write_ha_state
    super().async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1007, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1132, in _async_write_ha_state
    self.__async_calculate_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1091, in __async_calculate_state
    if (entity_picture := self.entity_picture) is not None:
                          ^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 1081, in entity_picture
    return self.media_image_local
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 1086, in media_image_local
    if (image_hash := self.media_image_hash) is None:
                      ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 652, in media_image_hash
    if (url := self.media_image_url) is not None:
               ^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/dlna_dmr/media_player.py", line 894, in media_image_url
    return self._device.media_image_url
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/async_upnp_client/profiles/dlna.py", line 1198, in media_image_url
    items = _cached_from_xml_string(xml)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/async_upnp_client/profiles/dlna.py", line 239, in _cached_from_xml_string
    return didl_lite.from_xml_string(xml, strict=False)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/didl_lite/didl_lite.py", line 1077, in from_xml_string
    xml_el = defusedxml.ElementTree.fromstring(xml_string)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/defusedxml/common.py", line 126, in fromstring
    parser.feed(text)
  File "/usr/local/lib/python3.12/xml/etree/ElementTree.py", line 1708, in feed
    self._raiseerror(v)
  File "/usr/local/lib/python3.12/xml/etree/ElementTree.py", line 1615, in _raiseerror
    raise err
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 0
2024-11-26 19:17:30.764 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.soundtouch_10_gym_dlna fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/xml/etree/ElementTree.py", line 1706, in feed
    self.parser.Parse(data, False)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 944, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1302, in async_device_update
    await self.async_update()
  File "/usr/src/homeassistant/homeassistant/components/dlna_dmr/media_player.py", line 498, in async_update
    await self._device.async_update(do_ping=do_ping)
  File "/usr/local/lib/python3.12/site-packages/async_upnp_client/profiles/dlna.py", line 360, in async_update
    await self._async_poll_state_variables(
  File "/usr/local/lib/python3.12/site-packages/async_upnp_client/profiles/profile.py", line 468, in _async_poll_state_variables
    self._on_event(service, changed_state_variables)
  File "/usr/local/lib/python3.12/site-packages/async_upnp_client/profiles/dlna.py", line 394, in _on_event
    self._update_current_track_meta_data(state_variable)
  File "/usr/local/lib/python3.12/site-packages/async_upnp_client/profiles/dlna.py", line 1086, in _update_current_track_meta_data
    items = _cached_from_xml_string(xml)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/async_upnp_client/profiles/dlna.py", line 239, in _cached_from_xml_string
    return didl_lite.from_xml_string(xml, strict=False)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/didl_lite/didl_lite.py", line 1077, in from_xml_string
    xml_el = defusedxml.ElementTree.fromstring(xml_string)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/defusedxml/common.py", line 126, in fromstring
    parser.feed(text)
  File "/usr/local/lib/python3.12/xml/etree/ElementTree.py", line 1708, in feed
    self._raiseerror(v)
  File "/usr/local/lib/python3.12/xml/etree/ElementTree.py", line 1615, in _raiseerror
    raise err
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 0
2024-11-26 19:17:30.943 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/xml/etree/ElementTree.py", line 1706, in feed
    self.parser.Parse(data, False)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 1046, in _async_update_entity_states
    await entity.async_update_ha_state(True)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 962, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1132, in _async_write_ha_state
    self.__async_calculate_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1091, in __async_calculate_state
    if (entity_picture := self.entity_picture) is not None:
                          ^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 1081, in entity_picture
    return self.media_image_local
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 1086, in media_image_local
    if (image_hash := self.media_image_hash) is None:
                      ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 652, in media_image_hash
    if (url := self.media_image_url) is not None:
               ^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/dlna_dmr/media_player.py", line 894, in media_image_url
    return self._device.media_image_url
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/async_upnp_client/profiles/dlna.py", line 1198, in media_image_url
    items = _cached_from_xml_string(xml)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/async_upnp_client/profiles/dlna.py", line 239, in _cached_from_xml_string
    return didl_lite.from_xml_string(xml, strict=False)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/didl_lite/didl_lite.py", line 1077, in from_xml_string
    xml_el = defusedxml.ElementTree.fromstring(xml_string)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/defusedxml/common.py", line 126, in fromstring
    parser.feed(text)
  File "/usr/local/lib/python3.12/xml/etree/ElementTree.py", line 1708, in feed
    self._raiseerror(v)
  File "/usr/local/lib/python3.12/xml/etree/ElementTree.py", line 1615, in _raiseerror
    raise err
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 0

Reproduction steps

  1. Buy a ST10
  2. Install home Assistant and Music Assistant
  3. Install SoundTouchPlus Integration
  4. Install DLNA Digital Media Renderer Integration
  5. Wodner what's the best way to glue all of these togheter :)

Debug logs

no relevant logs

Diagnostics dump

No response

thlucas1 commented 23 hours ago

I am not familiar with the details of Music Assistant, so not sure how to direct you there.

As for SoundTouch device DLNA support, I believe all you have to do is add a "Music Library on Computer" music service entry via the SoundTouch App, as well as have the "SoundTouch Music Server" running in the background (on Windows OS anyway): image

This will appear as a source in the SoundTouchPlus device list: image

The SoundTouch Music Server then exposes the defined music service as a DLNA endpoint which should be recognized (I would think anyway) by Music Assistant.

Also note that the SoundTouch App music service "Music Library on NAS" is different than the "Music Library on Computer" music service. I'm not sure if the "Music Service on NAS" uses DLNA for streaming or not; I think it does, but the DLNA server would be the NAS device instead of the "SoundTouch Music Server". I'm fuzzy on that though, as it's been awhile since I played with DLNA support on my SoundTouch devices.

I believe the Upnp source is reserved for Bose internal use; I have never tried to select that source directly. I have always used the play_contentitem SoundTouchPlus service to play content from the "SoundTouch Music Server" DLNA server (notice the source: LOCAL_MUSIC setting):

# play dlna local music content.
service: soundtouchplus.play_contentitem
data:
  entity_id: media_player.soundtouch_10
  name: Welcome to the New
  source: LOCAL_MUSIC
  source_account: 3f205110-4a57-4e91-810a-ad949d25abb2
  item_type: album
  location: 'album:983'
  container_art: http://192.168.1.1:8085/v1/albums/983/image?_=1&w=62
  is_presetable: true

I have always used the play_contentitem SoundTouchPlus service to play content from the "NAS" DLNA server (notice the source: STORED_MUSIC setting):

# play music library on NAS content.
service: soundtouchplus.play_contentitem
data:
  entity_id: media_player.soundtouch_10
  name: Welcome to the New
  source: STORED_MUSIC
  source_account: 'd09708a1-5953-44bc-a413-123456789012/0'
  location: '7_11412345'
  container_art: http://192.168.1.1:10243/WMPNSSv4/2050238549/0_N18xMTRlOGRlOS00MDE5.jpg?albumArt=true
  is_presetable: true

As for Music Assistant being able to play on the SoundTouch devices, I would think it would not be possible unless MA implements some sort of interface to the SoundTouch Web API. Or maybe you have to configure the MA to call the soundtouchplus.play_contentitem service? Not sure how MA works for that.

Hope it helps!

override80 commented 14 hours ago

Hi @thlucas1 , thanks for the precious feedback. I gave it a try adding the "My music library" service to the SoundTouch app, unfortunately

The weirdest thing is that in one ST-10 the DLNA is somehow working (despire reporting the device as paused instead of off): image

The other ST-10s are just in "unknown" state:

image

It makes no sense. I'm guessing that it has something to do with some bug in the DLNA Digital Media Renderer integration in home assistant.

thlucas1 commented 10 hours ago

@override80 Keep in mind that the media_player.soundtouch_10_bedroom and soundtouch_10_bedroom_dlna are two separate media players, with the soundtouch_10_bedroom_dlna player being the one that controls the device if controlled through DLNA Digital Media Renderer integration. I can only speak for what the media_player.soundtouch_10_bedroom is doing, as that's the SoundTouchPlus integration media player.

Do you remember if you enabled the SoundTouchPlus integration Websocket Port option on the media_player.soundtouch_10_bedroom device when you set it up? If enabled, this should cause the SoundTouchPlus media player to receive updates of when statuses change on the device from external sources. To check if it's currently enabled, display the device state and look for the soundtouchplus_websockets_enabled: xxxx value; it will be true if enabled, false if disabled.

The Websocket Port functionality causes the SoundTouchPlus media player to update as events happen on the device, from whatever is controlling it (e.g. a button press on the device, pressing pause on the HA media player UI, issuing an HA service call to resume playback, starting a track via a DLNA client, etc).

For example, here is what my Bose ST-10 device status looks like (going from off state) after starting a track via the Bose SoundTouch App for the THLUCASI9 Music source (e.g. DLNA / "Music Library on Computer" music service):

image

I would agree with your statement that the DLNA Digital Media Renderer integration is not handling something correctly.

Hope that helps.

override80 commented 8 hours ago

I just readded all soundtouch devices enabling websocket as suggested.

It's much better!

Now i can play a song from the soundtouch app from spotify, then when music assistant steps in, it works! this is valid for the ST-10s. On the ST-20 i get the following error when trying to play a song from Music Asistant:

2024-11-27 18:35:59.741 ERROR (SyncWorker_3) [bosesoundtouchapi.soundtouchclient] SoundTouchError: "BST1002E - 'SoundTouch 20 LivingRoom': SoundTouch Web-services API returned an error status: 'unsupported device'", code="403", name="HTTP_STATUS_FORBIDDEN", severity="Unknown"
2024-11-27 18:35:59.742 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140306373793040] Unexpected exception
Traceback (most recent call last):
  File "/config/custom_components/soundtouchplus/media_player.py", line 916, in play_media
    self._client.PlayUrl(media_id, artist=announceValue, album=announceValue, getMetaDataFromUrlFile=True, volumeLevel=0)
  File "/usr/local/lib/python3.12/site-packages/bosesoundtouchapi/soundtouchclient.py", line 3048, in PlayUrl
    self.MakeRequest('POST', message)
  File "/usr/local/lib/python3.12/site-packages/bosesoundtouchapi/soundtouchclient.py", line 2445, in MakeRequest
    self._CheckResponseForErrors(msg.Response)
  File "/usr/local/lib/python3.12/site-packages/bosesoundtouchapi/soundtouchclient.py", line 307, in _CheckResponseForErrors
    raise SoundTouchError(errMessage, errName, errSeverity, errValue, _logsi)
bosesoundtouchapi.soundtoucherror.SoundTouchError: SoundTouchError: "BST1002E - 'SoundTouch 20 LivingRoom': SoundTouch Web-services API returned an error status: 'unsupported device'", code="403", name="HTTP_STATUS_FORBIDDEN", severity="Unknown"

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/soundtouchplus/media_player.py", line 846, in async_play_media
    await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/soundtouchplus/media_player.py", line 949, in play_media
    raise HomeAssistantError(str(ex)) from ex
homeassistant.exceptions.HomeAssistantError: SoundTouchError: "BST1002E - 'SoundTouch 20 LivingRoom': SoundTouch Web-services API returned an error status: 'unsupported device'", code="403", name="HTTP_STATUS_FORBIDDEN", severity="Unknown"

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
    response = await hass.services.async_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2802, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2845, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1007, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1079, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/soundtouchplus/media_player.py", line 854, in async_play_media
    raise HomeAssistantError(str(ex)) from ex
homeassistant.exceptions.HomeAssistantError: SoundTouchError: "BST1002E - 'SoundTouch 20 LivingRoom': SoundTouch Web-services API returned an error status: 'unsupported device'", code="403", name="HTTP_STATUS_FORBIDDEN", severity="Unknown"

Seems similar to the issues connected to TTS notifications on ST-20, isn't it? Probably because Music Assistant switches the player to the following source:

image

thlucas1 commented 3 hours ago

I forgot that the ST-20 does not support websockets. See the Bose SoundTouch ST-20 limitations wiki for more details.

The ST-20 supports TTS notifications, per the TTS notify service notes.