mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Handle timeouts in Sonos, reduce logging noise (#85461)
This commit is contained in:
parent
318871f8a9
commit
9d7e99eeb7
@ -11,6 +11,7 @@ import socket
|
|||||||
from typing import TYPE_CHECKING, Any, Optional, cast
|
from typing import TYPE_CHECKING, Any, Optional, cast
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
from requests.exceptions import Timeout
|
||||||
from soco import events_asyncio, zonegroupstate
|
from soco import events_asyncio, zonegroupstate
|
||||||
import soco.config as soco_config
|
import soco.config as soco_config
|
||||||
from soco.core import SoCo
|
from soco.core import SoCo
|
||||||
@ -223,13 +224,13 @@ class SonosDiscoveryManager:
|
|||||||
|
|
||||||
async def async_subscription_failed(now: datetime.datetime) -> None:
|
async def async_subscription_failed(now: datetime.datetime) -> None:
|
||||||
"""Fallback logic if the subscription callback never arrives."""
|
"""Fallback logic if the subscription callback never arrives."""
|
||||||
await sub.unsubscribe()
|
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Subscription to %s failed, attempting to poll directly", ip_address
|
"Subscription to %s failed, attempting to poll directly", ip_address
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
|
await sub.unsubscribe()
|
||||||
await self.hass.async_add_executor_job(soco.zone_group_state.poll, soco)
|
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(
|
_LOGGER.warning(
|
||||||
"Fallback pollling to %s failed, setup cannot continue: %s",
|
"Fallback pollling to %s failed, setup cannot continue: %s",
|
||||||
ip_address,
|
ip_address,
|
||||||
@ -322,8 +323,8 @@ class SonosDiscoveryManager:
|
|||||||
new_coordinator.setup(soco)
|
new_coordinator.setup(soco)
|
||||||
coord_dict[soco.household_id] = new_coordinator
|
coord_dict[soco.household_id] = new_coordinator
|
||||||
speaker.setup(self.entry)
|
speaker.setup(self.entry)
|
||||||
except (OSError, SoCoException):
|
except (OSError, SoCoException, Timeout) as ex:
|
||||||
_LOGGER.warning("Failed to add SonosSpeaker using %s", soco, exc_info=True)
|
_LOGGER.warning("Failed to add SonosSpeaker using %s: %s", soco, ex)
|
||||||
|
|
||||||
async def async_poll_manual_hosts(
|
async def async_poll_manual_hosts(
|
||||||
self, now: datetime.datetime | None = None
|
self, now: datetime.datetime | None = None
|
||||||
@ -344,8 +345,10 @@ class SonosDiscoveryManager:
|
|||||||
get_sync_attributes,
|
get_sync_attributes,
|
||||||
soco,
|
soco,
|
||||||
)
|
)
|
||||||
except OSError:
|
except (OSError, SoCoException, Timeout) as ex:
|
||||||
_LOGGER.warning("Could not get visible Sonos devices from %s", ip_addr)
|
_LOGGER.warning(
|
||||||
|
"Could not get visible Sonos devices from %s: %s", ip_addr, ex
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
if new_hosts := {
|
if new_hosts := {
|
||||||
x.ip_address
|
x.ip_address
|
||||||
|
@ -5,6 +5,7 @@ from collections.abc import Callable
|
|||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING, Any, TypeVar, overload
|
from typing import TYPE_CHECKING, Any, TypeVar, overload
|
||||||
|
|
||||||
|
from requests.exceptions import Timeout
|
||||||
from soco import SoCo
|
from soco import SoCo
|
||||||
from soco.exceptions import SoCoException, SoCoUPnPException
|
from soco.exceptions import SoCoException, SoCoUPnPException
|
||||||
from typing_extensions import Concatenate, ParamSpec
|
from typing_extensions import Concatenate, ParamSpec
|
||||||
@ -65,7 +66,7 @@ def soco_error(
|
|||||||
args_soco = next((arg for arg in args if isinstance(arg, SoCo)), None)
|
args_soco = next((arg for arg in args if isinstance(arg, SoCo)), None)
|
||||||
try:
|
try:
|
||||||
result = funct(self, *args, **kwargs)
|
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)
|
error_code = getattr(err, "error_code", None)
|
||||||
function = funct.__qualname__
|
function = funct.__qualname__
|
||||||
if errorcodes and error_code in errorcodes:
|
if errorcodes and error_code in errorcodes:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user