Add integration filtering and error if core options to helpers.frame.report (#60009)

Reduces some existing and upcoming boilerplate.
This commit is contained in:
Ville Skyttä
2021-11-20 12:53:04 +02:00
committed by GitHub
parent e5c33474e3
commit f305d99af9
3 changed files with 22 additions and 67 deletions

View File

@@ -2,19 +2,11 @@
from __future__ import annotations
import asyncio
import contextlib
import logging
from typing import Any
import async_timeout
from homeassistant.helpers.frame import (
MissingIntegrationFrame,
get_integration_frame,
report_integration,
)
_LOGGER = logging.getLogger(__name__)
from homeassistant.helpers.frame import report
def timeout(
@@ -24,8 +16,9 @@ def timeout(
if loop is None:
loop = asyncio.get_running_loop()
else:
_report(
"called async_timeout.timeout with loop keyword argument. The loop keyword argument is deprecated and calls will fail after Home Assistant 2022.2"
report(
"called async_timeout.timeout with loop keyword argument. The loop keyword argument is deprecated and calls will fail after Home Assistant 2022.2",
error_if_core=False,
)
if delay is not None:
deadline: float | None = loop.time() + delay
@@ -36,8 +29,9 @@ def timeout(
def current_task(loop: asyncio.AbstractEventLoop) -> asyncio.Task[Any] | None:
"""Backwards compatible current_task."""
_report(
"called async_timeout.current_task. The current_task call is deprecated and calls will fail after Home Assistant 2022.2; use asyncio.current_task instead"
report(
"called async_timeout.current_task. The current_task call is deprecated and calls will fail after Home Assistant 2022.2; use asyncio.current_task instead",
error_if_core=False,
)
return asyncio.current_task()
@@ -46,22 +40,3 @@ def enable() -> None:
"""Enable backwards compat transitions."""
async_timeout.timeout = timeout
async_timeout.current_task = current_task # type: ignore[attr-defined]
def _report(what: str) -> None:
"""Report incorrect usage.
Async friendly.
"""
integration_frame = None
with contextlib.suppress(MissingIntegrationFrame):
integration_frame = get_integration_frame()
if not integration_frame:
_LOGGER.warning(
"Detected code that %s; Please report this issue", what, stack_info=True
)
return
report_integration(what, integration_frame)