Move core Sonos functionality out of entities (#50277)
This commit is contained in:
parent
0fdc50408a
commit
d6a202bd74
9 changed files with 733 additions and 839 deletions
32
homeassistant/components/sonos/helpers.py
Normal file
32
homeassistant/components/sonos/helpers.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
"""Helper methods for common tasks."""
|
||||
from __future__ import annotations
|
||||
|
||||
import functools as ft
|
||||
import logging
|
||||
from typing import Any, Callable
|
||||
|
||||
from pysonos.exceptions import SoCoException, SoCoUPnPException
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def soco_error(errorcodes: list[str] | None = None) -> Callable:
|
||||
"""Filter out specified UPnP errors from logs and avoid exceptions."""
|
||||
|
||||
def decorator(funct: Callable) -> Callable:
|
||||
"""Decorate functions."""
|
||||
|
||||
@ft.wraps(funct)
|
||||
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
||||
"""Wrap for all soco UPnP exception."""
|
||||
try:
|
||||
return funct(*args, **kwargs)
|
||||
except SoCoUPnPException as err:
|
||||
if not errorcodes or err.error_code not in errorcodes:
|
||||
_LOGGER.error("Error on %s with %s", funct.__name__, err)
|
||||
except SoCoException as err:
|
||||
_LOGGER.error("Error on %s with %s", funct.__name__, err)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
Loading…
Add table
Add a link
Reference in a new issue