home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.55k stars 30.73k forks source link

Sonos cannot add new devices - unclosed token #96071

Closed miniminne closed 1 year ago

miniminne commented 1 year ago

The problem

I’m having a beast of a time getting Sonos to work again in my HA system. It was working for awhile, but recently (last 6 months) failed to find/add my devices again. I turned on debug logging, and one common theme was this error here:

2023-07-07 02:57:50.828 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sonos/__init__.py", line 340, in async_add_speakers
    await self.hass.async_add_executor_job(_add_speakers)
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sonos/__init__.py", line 337, in _add_speakers
    self._add_speaker(soco, sub)
  File "/usr/src/homeassistant/homeassistant/components/sonos/__init__.py", line 361, in _add_speaker
    new_coordinator.setup(soco)
  File "/usr/src/homeassistant/homeassistant/components/sonos/favorites.py", line 42, in setup
    super().setup(soco)
  File "/usr/src/homeassistant/homeassistant/components/sonos/household_coordinator.py", line 34, in setup
    self.update_cache(soco)
  File "/usr/src/homeassistant/homeassistant/components/sonos/helpers.py", line 64, in wrapper
    result = funct(self, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sonos/favorites.py", line 128, in update_cache
    if fav.reference.resources:
       ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/soco/data_structures.py", line 983, in reference
    ref = _FROM_DIDL_STRING_FUNCTION(getattr(self, "resource_meta_data"))[0]
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/soco/data_structures_entry.py", line 31, in from_didl_string
    root = XML.fromstring(string.encode("utf-8"))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/xml/etree/ElementTree.py", line 1339, in XML
    return parser.close()
           ^^^^^^^^^^^^^^
xml.etree.ElementTree.ParseError: unclosed token: line 1, column 946

I am running this on a Unifi network, no VLANs, and my switches are configured for STP vs RSTP. I’m at a loss how to get this working again as HASS can clearly see the devices, but is struggling to set them up again.

This is running through a Proxmox 8 VM, but considering SoCo in the terminal AddOn can see the devices, I don’t think that’s the issue here.

I’ve attempted to do some nerdier troubleshooting by running python in the Terminal AddOn then importing SoCo and trying to find devices that way. This does succeed, so I think something wilder is going on right now.

What version of Home Assistant Core has the issue?

core-2023.7.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Sonos

Link to integration documentation on our website

https://www.home-assistant.io/integrations/sonos/

Diagnostics information

home-assistant_sonos_2023-07-07T07-58-19.341Z.log

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @cgtobi, @jjlawren, mind taking a look at this issue as it has been labeled with an integration (sonos) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `sonos` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign sonos` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


sonos documentation sonos source (message by IssueLinks)

jjlawren commented 1 year ago

This appears to be a problem with one of your saved Sonos favorites which SoCo is choking while parsing. Perhaps you have an idea which one might be causing an issue and try to either remove or recreate it?

miniminne commented 1 year ago

This appears to be a problem with one of your saved Sonos favorites which SoCo is choking while parsing. Perhaps you have an idea which one might be causing an issue and try to either remove or recreate it?

Hey! This seemed to have fixed it. Between a combination of Apple Music favorites being broken (due to cancelling my sub) and missing files I think that caused the breakdown.