Skip to content
Merged
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
15 changes: 9 additions & 6 deletions homeassistant/components/sonos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from typing import TYPE_CHECKING, Any, Optional, cast
from urllib.parse import urlparse

from requests.exceptions import Timeout
from soco import events_asyncio, zonegroupstate
import soco.config as soco_config
from soco.core import SoCo
Expand Down Expand Up @@ -222,13 +223,13 @@ def _async_add_visible_zones(subscription_succeeded: bool = False) -> None:

async def async_subscription_failed(now: datetime.datetime) -> None:
"""Fallback logic if the subscription callback never arrives."""
await sub.unsubscribe()
_LOGGER.warning(
"Subscription to %s failed, attempting to poll directly", ip_address
)
try:
await sub.unsubscribe()
await self.hass.async_add_executor_job(soco.zone_group_state.poll, soco)
except (OSError, SoCoException) as ex:
except (OSError, SoCoException, Timeout) as ex:
_LOGGER.warning(
"Fallback pollling to %s failed, setup cannot continue: %s",
ip_address,
Expand Down Expand Up @@ -321,8 +322,8 @@ def _add_speaker(
new_coordinator.setup(soco)
coord_dict[soco.household_id] = new_coordinator
speaker.setup(self.entry)
except (OSError, SoCoException):
_LOGGER.warning("Failed to add SonosSpeaker using %s", soco, exc_info=True)
except (OSError, SoCoException, Timeout) as ex:
_LOGGER.warning("Failed to add SonosSpeaker using %s: %s", soco, ex)

async def async_poll_manual_hosts(
self, now: datetime.datetime | None = None
Expand All @@ -343,8 +344,10 @@ def get_sync_attributes(soco: SoCo) -> set[SoCo]:
get_sync_attributes,
soco,
)
except OSError:
_LOGGER.warning("Could not get visible Sonos devices from %s", ip_addr)
except (OSError, SoCoException, Timeout) as ex:
_LOGGER.warning(
"Could not get visible Sonos devices from %s: %s", ip_addr, ex
)
else:
if new_hosts := {
x.ip_address
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/sonos/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
from typing import TYPE_CHECKING, Any, TypeVar, overload

from requests.exceptions import Timeout
from soco import SoCo
from soco.exceptions import SoCoException, SoCoUPnPException
from typing_extensions import Concatenate, ParamSpec
Expand Down Expand Up @@ -65,7 +66,7 @@ def wrapper(self: _T, *args: _P.args, **kwargs: _P.kwargs) -> _R | None:
args_soco = next((arg for arg in args if isinstance(arg, SoCo)), None)
try:
result = funct(self, *args, **kwargs)
except (OSError, SoCoException, SoCoUPnPException) as err:
except (OSError, SoCoException, SoCoUPnPException, Timeout) as err:
error_code = getattr(err, "error_code", None)
function = funct.__qualname__
if errorcodes and error_code in errorcodes:
Expand Down