Add integration name to the deprecation warnings (#45901)
This commit is contained in:
parent
5615ab4c25
commit
90973f471f
1 changed files with 25 additions and 5 deletions
|
@ -4,6 +4,8 @@ import inspect
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Callable, Dict, Optional
|
from typing import Any, Callable, Dict, Optional
|
||||||
|
|
||||||
|
from ..helpers.frame import MissingIntegrationFrame, get_integration_frame
|
||||||
|
|
||||||
|
|
||||||
def deprecated_substitute(substitute_name: str) -> Callable[..., Callable]:
|
def deprecated_substitute(substitute_name: str) -> Callable[..., Callable]:
|
||||||
"""Help migrate properties to new names.
|
"""Help migrate properties to new names.
|
||||||
|
@ -86,11 +88,29 @@ def deprecated_function(replacement: str) -> Callable[..., Callable]:
|
||||||
def deprecated_func(*args: tuple, **kwargs: Dict[str, Any]) -> Any:
|
def deprecated_func(*args: tuple, **kwargs: Dict[str, Any]) -> Any:
|
||||||
"""Wrap for the original function."""
|
"""Wrap for the original function."""
|
||||||
logger = logging.getLogger(func.__module__)
|
logger = logging.getLogger(func.__module__)
|
||||||
logger.warning(
|
try:
|
||||||
"%s is a deprecated function. Use %s instead",
|
_, integration, path = get_integration_frame()
|
||||||
func.__name__,
|
if path == "custom_components/":
|
||||||
replacement,
|
logger.warning(
|
||||||
)
|
"%s was called from %s, this is a deprecated function. Use %s instead, please report this to the maintainer of %s",
|
||||||
|
func.__name__,
|
||||||
|
integration,
|
||||||
|
replacement,
|
||||||
|
integration,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
logger.warning(
|
||||||
|
"%s was called from %s, this is a deprecated function. Use %s instead",
|
||||||
|
func.__name__,
|
||||||
|
integration,
|
||||||
|
replacement,
|
||||||
|
)
|
||||||
|
except MissingIntegrationFrame:
|
||||||
|
logger.warning(
|
||||||
|
"%s is a deprecated function. Use %s instead",
|
||||||
|
func.__name__,
|
||||||
|
replacement,
|
||||||
|
)
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
return deprecated_func
|
return deprecated_func
|
||||||
|
|
Loading…
Add table
Reference in a new issue