From 90973f471f991de9c270c39c540abd4d6770e2d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Wed, 3 Feb 2021 14:40:11 +0100 Subject: [PATCH] Add integration name to the deprecation warnings (#45901) --- homeassistant/helpers/deprecation.py | 30 +++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/homeassistant/helpers/deprecation.py b/homeassistant/helpers/deprecation.py index 0022f888829..7478a7fede9 100644 --- a/homeassistant/helpers/deprecation.py +++ b/homeassistant/helpers/deprecation.py @@ -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