mirror of
https://github.com/home-assistant/core.git
synced 2025-12-27 06:28:31 +00:00
Black
This commit is contained in:
@@ -12,34 +12,42 @@ def deprecated_substitute(substitute_name: str) -> Callable[..., Callable]:
|
||||
If the old property is defined, its value will be used instead, and a log
|
||||
warning will be issued alerting the user of the impending change.
|
||||
"""
|
||||
|
||||
def decorator(func: Callable) -> Callable:
|
||||
"""Decorate function as deprecated."""
|
||||
|
||||
def func_wrapper(self: Callable) -> Any:
|
||||
"""Wrap for the original function."""
|
||||
if hasattr(self, substitute_name):
|
||||
# If this platform is still using the old property, issue
|
||||
# a logger warning once with instructions on how to fix it.
|
||||
warnings = getattr(func, '_deprecated_substitute_warnings', {})
|
||||
warnings = getattr(func, "_deprecated_substitute_warnings", {})
|
||||
module_name = self.__module__
|
||||
if not warnings.get(module_name):
|
||||
logger = logging.getLogger(module_name)
|
||||
logger.warning(
|
||||
"'%s' is deprecated. Please rename '%s' to "
|
||||
"'%s' in '%s' to ensure future support.",
|
||||
substitute_name, substitute_name, func.__name__,
|
||||
inspect.getfile(self.__class__))
|
||||
substitute_name,
|
||||
substitute_name,
|
||||
func.__name__,
|
||||
inspect.getfile(self.__class__),
|
||||
)
|
||||
warnings[module_name] = True
|
||||
setattr(func, '_deprecated_substitute_warnings', warnings)
|
||||
setattr(func, "_deprecated_substitute_warnings", warnings)
|
||||
|
||||
# Return the old property
|
||||
return getattr(self, substitute_name)
|
||||
return func(self)
|
||||
|
||||
return func_wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
def get_deprecated(config: Dict[str, Any], new_name: str, old_name: str,
|
||||
default: Optional[Any] = None) -> Optional[Any]:
|
||||
def get_deprecated(
|
||||
config: Dict[str, Any], new_name: str, old_name: str, default: Optional[Any] = None
|
||||
) -> Optional[Any]:
|
||||
"""Allow an old config name to be deprecated with a replacement.
|
||||
|
||||
If the new config isn't found, but the old one is, the old value is used
|
||||
@@ -50,6 +58,10 @@ def get_deprecated(config: Dict[str, Any], new_name: str, old_name: str,
|
||||
logger = logging.getLogger(module_name)
|
||||
logger.warning(
|
||||
"'%s' is deprecated. Please rename '%s' to '%s' in your "
|
||||
"configuration file.", old_name, old_name, new_name)
|
||||
"configuration file.",
|
||||
old_name,
|
||||
old_name,
|
||||
new_name,
|
||||
)
|
||||
return config.get(old_name)
|
||||
return config.get(new_name, default)
|
||||
|
||||
Reference in New Issue
Block a user