Sonos Favourites problem preventing startup

I’ve just spent several days trying to find out why my Hassio (rPi) Sonos integration does not appear to discover any of my speakers. I was pretty convinced it was a networking problem (I have Ubquiti), but it’s not.

It turns out that there was something in my Sonos favourites list that was causing the integration to not start correctly. Clearing pretty much everything from my favourites list did the job. Everything is sweetness and light now.

I’ll add what appears to be the relevant section of the log below. If anyone else is having problems, check the log for similarities. I can provide the full config and log if required.

I hope this saves someone else a few hours of anguish.

Rgds

2022-11-21 13:50:36.603 DEBUG (MainThread) [homeassistant.components.sonos] Adding discovery job
2022-11-21 13:50:36.970 DEBUG (SyncWorker_7) [homeassistant.components.sonos] Adding new speaker: {'zone_name': 'Lounge', 'player_icon': '/img/icon-S6.png', 'uid': 'RINCON_5CAAFD09B3C001400', 'serial_number': '5C-AA-FD-09-B3-C0:4', 'software_version': '70.3-35070', 'hardware_version': '1.13.1.7-2.2', 'model_number': 'S6', 'model_name': 'Sonos Play:5', 'display_version': '14.19', 'mac_address': '5C-AA-FD-09-B3-C0'}
2022-11-21 13:50:37.094 DEBUG (SyncWorker_7) [homeassistant.components.sonos.alarms] Updating processed event 4 from <SoCo object at ip 192.168.1.27> (was None)
2022-11-21 13:50:37.316 DEBUG (SyncWorker_7) [homeassistant.components.sonos.favorites] Processing favorites update_id 17 for <SoCo object at ip 192.168.1.27> (was: None)
2022-11-21 13:50:37.515 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Sonos for sonos
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 365, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/usr/src/homeassistant/homeassistant/components/sonos/__init__.py", line 147, in async_setup_entry
    await manager.setup_platforms_and_discovery()
  File "/usr/src/homeassistant/homeassistant/components/sonos/__init__.py", line 407, in setup_platforms_and_discovery
    await self.hass.async_add_executor_job(self._poll_manual_hosts)
  File "/usr/local/lib/python3.10/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 290, in _poll_manual_hosts
    self._create_visible_speakers(ip_addr)
  File "/usr/src/homeassistant/homeassistant/components/sonos/__init__.py", line 198, in _create_visible_speakers
    self._add_speaker(zone)
  File "/usr/src/homeassistant/homeassistant/components/sonos/__init__.py", line 244, 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 67, 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.10/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.10/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.10/xml/etree/ElementTree.py", line 1343, in XML
    return parser.close()
xml.etree.ElementTree.ParseError: no element found: line 1, column 1023
type or paste code here

same problem here. so what’s the solution

It turns out that there was something in my Sonos favourites list that was causing the integration to not start correctly. Clearing pretty much everything from my favourites list did the job. Everything is sweetness and light now.