core: Sonos integration fails upon HA restart, if any device is powered off

The problem

While I only have to restart my Home Assistant occasionally, every time I do, I need to make sure all my Sonos devices are turned on / have power, to avoid the integration from failing to setup and all Sonos devices being unavailable.

My Sonos Roam is not always on. Both my Sonos Beam and Play5 are behind a smart plug that switches off e.g. during the night.

Environment:

  • HA core in docker container @ host: 192.168.1.104
  • Docker container NOT on host network
  • configuration.yaml adjusted according to: Sonos ‘advanced-use’ (see below yaml snippet)

What version of Home Assistant Core has the issue?

core-2023.3.4

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

config_entry-sonos-2a2fb28b09fe9fbc04d5d8322c2ac283.json.txt

Example YAML snippet

sonos:
  media_player:
    advertise_addr: 192.168.1.104
    hosts:
      - 192.168.1.28 #Play5
      - 192.168.1.30 #Beam
      - 192.168.1.42 #Roam

Anything in the logs that might be useful for us?

2023-03-24 11:23:35.637 DEBUG (SyncWorker_3) [soco.zonegroupstate] Cache still active (GetZoneGroupState) during poll for 192.168.1.42
2023-03-24 11:23:35.637 DEBUG (MainThread) [homeassistant.components.sonos.speaker] Activity on Sonos Roam from manual zone scan while in cooldown, ignoring
2023-03-24 11:23:35.638 DEBUG (SyncWorker_16) [soco.services] Request timeout set to 1
2023-03-24 11:23:35.638 DEBUG (SyncWorker_16) [soco.services] Sending GetVolume [('InstanceID', 0), ('Channel', 'Master')] to 192.168.1.42
2023-03-24 11:23:35.638 DEBUG (SyncWorker_16) [soco.services] Sending {'Content-Type': 'text/xml; charset="utf-8"', 'SOAPACTION': 'urn:schemas-upnp-org:service:RenderingControl:1#GetVolume'}, <?xml version="1.0" ?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <s:Body>
    <u:GetVolume xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1">
      <InstanceID>0</InstanceID>
      <Channel>Master</Channel>
    </u:GetVolume>
  </s:Body>
</s:Envelope>

2023-03-24 11:23:36.642 DEBUG (MainThread) [homeassistant.components.sonos] Manual poll to 192.168.1.42 failed, keeping unavailable
2023-03-24 11:23:40.778 WARNING (MainThread) [soco.events_asyncio] Could not bind to 172.20.0.5:1400: [Errno 98] Address in use
2023-03-24 11:23:51.471 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 383, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/usr/src/homeassistant/homeassistant/components/sonos/__init__.py", line 156, in async_setup_entry
    await manager.setup_platforms_and_discovery()
  File "/usr/src/homeassistant/homeassistant/components/sonos/__init__.py", line 514, in setup_platforms_and_discovery
    await self.async_poll_manual_hosts()
  File "/usr/src/homeassistant/homeassistant/components/sonos/__init__.py", line 390, in async_poll_manual_hosts
    await self._async_handle_discovery_message(
  File "/usr/src/homeassistant/homeassistant/components/sonos/__init__.py", line 416, in _async_handle_discovery_message
    await self.async_subscribe_to_zone_updates(discovered_ip)
  File "/usr/src/homeassistant/homeassistant/components/sonos/__init__.py", line 203, in async_subscribe_to_zone_updates
    sub = await soco.zoneGroupTopology.subscribe()
  File "/usr/local/lib/python3.10/site-packages/soco/events_asyncio.py", line 374, in _async_wrap_subscribe
    await subscribe(requested_timeout, auto_renew)
  File "/usr/local/lib/python3.10/site-packages/soco/events_asyncio.py", line 507, in _async_make_request
    response = await self.event_listener.session.request(
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 467, in _request
    with timer:
  File "/usr/local/lib/python3.10/site-packages/aiohttp/helpers.py", line 721, in __exit__
    raise asyncio.TimeoutError from None
asyncio.exceptions.TimeoutError

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

Sounds good, Ive looked at the code and know what to fix and will get something together next few days.

The change has been approved! Got some really good help getting the unit tests improved.

I don’t know if it will make the cutoff for 2023.6.0; or if will be in 2023.7.0