Add new frame helper to better distinguish custom and core integrations (#130025)

* Add new frame helper to clarify options available

* Adjust

* Improve

* Use report_usage in core

* Add tests

* Use is/is not

Co-authored-by: J. Nick Koston <nick@koston.org>

* Use enum.auto()

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
epenet
2024-11-07 18:23:35 +01:00
committed by GitHub
parent ee30520b57
commit a3b0909e3f
6 changed files with 177 additions and 33 deletions

View File

@@ -1556,16 +1556,18 @@ class Components:
raise ImportError(f"Unable to load {comp_name}")
# Local import to avoid circular dependencies
from .helpers.frame import report # pylint: disable=import-outside-toplevel
# pylint: disable-next=import-outside-toplevel
from .helpers.frame import ReportBehavior, report_usage
report(
report_usage(
(
f"accesses hass.components.{comp_name}."
" This is deprecated and will stop working in Home Assistant 2025.3, it"
f" should be updated to import functions used from {comp_name} directly"
),
error_if_core=False,
log_custom_component_only=True,
core_behavior=ReportBehavior.IGNORE,
core_integration_behavior=ReportBehavior.IGNORE,
custom_integration_behavior=ReportBehavior.LOG,
)
wrapped = ModuleWrapper(self._hass, component)
@@ -1585,16 +1587,18 @@ class Helpers:
helper = importlib.import_module(f"homeassistant.helpers.{helper_name}")
# Local import to avoid circular dependencies
from .helpers.frame import report # pylint: disable=import-outside-toplevel
# pylint: disable-next=import-outside-toplevel
from .helpers.frame import ReportBehavior, report_usage
report(
report_usage(
(
f"accesses hass.helpers.{helper_name}."
" This is deprecated and will stop working in Home Assistant 2025.5, it"
f" should be updated to import functions used from {helper_name} directly"
),
error_if_core=False,
log_custom_component_only=True,
core_behavior=ReportBehavior.IGNORE,
core_integration_behavior=ReportBehavior.IGNORE,
custom_integration_behavior=ReportBehavior.LOG,
)
wrapped = ModuleWrapper(self._hass, helper)