diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index 9b56bb06865..21d04f11551 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -711,7 +711,7 @@ def deprecated( - No warning if neither key nor replacement_key are provided - Adds replacement_key with default value in this case """ - module = inspect.getmodule(inspect.stack()[1][0]) + module = inspect.getmodule(inspect.stack(context=0)[1].frame) if module is not None: module_name = module.__name__ else: diff --git a/homeassistant/helpers/deprecation.py b/homeassistant/helpers/deprecation.py index 38b1dfca437..06f09327dc9 100644 --- a/homeassistant/helpers/deprecation.py +++ b/homeassistant/helpers/deprecation.py @@ -59,7 +59,7 @@ def get_deprecated( and a warning is issued to the user. """ if old_name in config: - module = inspect.getmodule(inspect.stack()[1][0]) + module = inspect.getmodule(inspect.stack(context=0)[1].frame) if module is not None: module_name = module.__name__ else: diff --git a/homeassistant/util/logging.py b/homeassistant/util/logging.py index ba846c0e8b4..816af95718d 100644 --- a/homeassistant/util/logging.py +++ b/homeassistant/util/logging.py @@ -85,7 +85,7 @@ def async_activate_log_queue_handler(hass: HomeAssistant) -> None: def log_exception(format_err: Callable[..., Any], *args: Any) -> None: """Log an exception with additional context.""" - module = inspect.getmodule(inspect.stack()[1][0]) + module = inspect.getmodule(inspect.stack(context=0)[1].frame) if module is not None: module_name = module.__name__ else: