Use report_usage in helpers (#130365)

This commit is contained in:
epenet 2024-11-12 09:25:13 +01:00 committed by GitHub
parent 22aed92461
commit 7045b776b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 19 additions and 23 deletions

View File

@ -719,14 +719,14 @@ def template(value: Any | None) -> template_helper.Template:
raise vol.Invalid("template value should be a string") raise vol.Invalid("template value should be a string")
if not (hass := _async_get_hass_or_none()): if not (hass := _async_get_hass_or_none()):
# pylint: disable-next=import-outside-toplevel # pylint: disable-next=import-outside-toplevel
from .frame import report from .frame import ReportBehavior, report_usage
report( report_usage(
( (
"validates schema outside the event loop, " "validates schema outside the event loop, "
"which will stop working in HA Core 2025.10" "which will stop working in HA Core 2025.10"
), ),
error_if_core=False, core_behavior=ReportBehavior.LOG,
) )
template_value = template_helper.Template(str(value), hass) template_value = template_helper.Template(str(value), hass)
@ -748,14 +748,14 @@ def dynamic_template(value: Any | None) -> template_helper.Template:
raise vol.Invalid("template value does not contain a dynamic template") raise vol.Invalid("template value does not contain a dynamic template")
if not (hass := _async_get_hass_or_none()): if not (hass := _async_get_hass_or_none()):
# pylint: disable-next=import-outside-toplevel # pylint: disable-next=import-outside-toplevel
from .frame import report from .frame import ReportBehavior, report_usage
report( report_usage(
( (
"validates schema outside the event loop, " "validates schema outside the event loop, "
"which will stop working in HA Core 2025.10" "which will stop working in HA Core 2025.10"
), ),
error_if_core=False, core_behavior=ReportBehavior.LOG,
) )
template_value = template_helper.Template(str(value), hass) template_value = template_helper.Template(str(value), hass)

View File

@ -997,14 +997,14 @@ class TrackTemplateResultInfo:
continue continue
# pylint: disable-next=import-outside-toplevel # pylint: disable-next=import-outside-toplevel
from .frame import report from .frame import ReportBehavior, report_usage
report( report_usage(
( (
"calls async_track_template_result with template without hass, " "calls async_track_template_result with template without hass, "
"which will stop working in HA Core 2025.10" "which will stop working in HA Core 2025.10"
), ),
error_if_core=False, core_behavior=ReportBehavior.LOG,
) )
track_template_.template.hass = hass track_template_.template.hass = hass

View File

@ -1277,14 +1277,14 @@ def async_register_entity_service(
schema = cv.make_entity_service_schema(schema) schema = cv.make_entity_service_schema(schema)
elif not cv.is_entity_service_schema(schema): elif not cv.is_entity_service_schema(schema):
# pylint: disable-next=import-outside-toplevel # pylint: disable-next=import-outside-toplevel
from .frame import report from .frame import ReportBehavior, report_usage
report( report_usage(
( (
"registers an entity service with a non entity service schema " "registers an entity service with a non entity service schema "
"which will stop working in HA Core 2025.9" "which will stop working in HA Core 2025.9"
), ),
error_if_core=False, core_behavior=ReportBehavior.LOG,
) )
service_func: str | HassJob[..., Any] service_func: str | HassJob[..., Any]

View File

@ -515,18 +515,18 @@ class Template:
will be non optional in Home Assistant Core 2025.10. will be non optional in Home Assistant Core 2025.10.
""" """
# pylint: disable-next=import-outside-toplevel # pylint: disable-next=import-outside-toplevel
from .frame import report from .frame import ReportBehavior, report_usage
if not isinstance(template, str): if not isinstance(template, str):
raise TypeError("Expected template to be a string") raise TypeError("Expected template to be a string")
if not hass: if not hass:
report( report_usage(
( (
"creates a template object without passing hass, " "creates a template object without passing hass, "
"which will stop working in HA Core 2025.10" "which will stop working in HA Core 2025.10"
), ),
error_if_core=False, core_behavior=ReportBehavior.LOG,
) )
self.template: str = template.strip() self.template: str = template.strip()

View File

@ -29,7 +29,7 @@ from homeassistant.util.dt import utcnow
from . import entity, event from . import entity, event
from .debounce import Debouncer from .debounce import Debouncer
from .frame import report from .frame import report_usage
from .typing import UNDEFINED, UndefinedType from .typing import UNDEFINED, UndefinedType
REQUEST_REFRESH_DEFAULT_COOLDOWN = 10 REQUEST_REFRESH_DEFAULT_COOLDOWN = 10
@ -286,24 +286,20 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
to ensure that multiple retries do not cause log spam. to ensure that multiple retries do not cause log spam.
""" """
if self.config_entry is None: if self.config_entry is None:
report( report_usage(
"uses `async_config_entry_first_refresh`, which is only supported " "uses `async_config_entry_first_refresh`, which is only supported "
"for coordinators with a config entry and will stop working in " "for coordinators with a config entry and will stop working in "
"Home Assistant 2025.11", "Home Assistant 2025.11"
error_if_core=True,
error_if_integration=False,
) )
elif ( elif (
self.config_entry.state self.config_entry.state
is not config_entries.ConfigEntryState.SETUP_IN_PROGRESS is not config_entries.ConfigEntryState.SETUP_IN_PROGRESS
): ):
report( report_usage(
"uses `async_config_entry_first_refresh`, which is only supported " "uses `async_config_entry_first_refresh`, which is only supported "
f"when entry state is {config_entries.ConfigEntryState.SETUP_IN_PROGRESS}, " f"when entry state is {config_entries.ConfigEntryState.SETUP_IN_PROGRESS}, "
f"but it is in state {self.config_entry.state}, " f"but it is in state {self.config_entry.state}, "
"This will stop working in Home Assistant 2025.11", "This will stop working in Home Assistant 2025.11",
error_if_core=True,
error_if_integration=False,
) )
if await self.__wrap_async_setup(): if await self.__wrap_async_setup():
await self._async_refresh( await self._async_refresh(