Add integration name to the deprecation warnings (#45901)

This commit is contained in:
Joakim Sørensen 2021-02-03 14:40:11 +01:00 committed by GitHub
parent 5615ab4c25
commit 90973f471f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,8 @@ import inspect
import logging
from typing import Any, Callable, Dict, Optional
from ..helpers.frame import MissingIntegrationFrame, get_integration_frame
def deprecated_substitute(substitute_name: str) -> Callable[..., Callable]:
"""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:
"""Wrap for the original function."""
logger = logging.getLogger(func.__module__)
logger.warning(
"%s is a deprecated function. Use %s instead",
func.__name__,
replacement,
)
try:
_, integration, path = get_integration_frame()
if path == "custom_components/":
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 deprecated_func