Improve async_get_issue_tracker for custom integrations (#118016)

This commit is contained in:
Erik Montnemery 2024-05-24 09:55:05 +02:00 committed by GitHub
parent 24d31924a0
commit f896c7505b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 2 deletions

View file

@ -421,6 +421,9 @@ async def async_from_config_dict(
start = monotonic()
hass.config_entries = config_entries.ConfigEntries(hass, config)
# Prime custom component cache early so we know if registry entries are tied
# to a custom integration
await loader.async_get_custom_components(hass)
await async_load_base_functionality(hass)
# Set up core.

View file

@ -1678,6 +1678,14 @@ def async_get_issue_tracker(
# If we know nothing about the entity, suggest opening an issue on HA core
return issue_tracker
if (
not integration
and (hass and integration_domain)
and (comps_or_future := hass.data.get(DATA_CUSTOM_COMPONENTS))
and not isinstance(comps_or_future, asyncio.Future)
):
integration = comps_or_future.get(integration_domain)
if not integration and (hass and integration_domain):
with suppress(IntegrationNotLoaded):
integration = async_get_loaded_integration(hass, integration_domain)

View file

@ -2,6 +2,7 @@
import asyncio
import os
import pathlib
import sys
import threading
from typing import Any
@ -1110,14 +1111,18 @@ CUSTOM_ISSUE_TRACKER = "https://blablabla.com"
# Integration domain is not currently deduced from module
(None, "homeassistant.components.hue.sensor", CORE_ISSUE_TRACKER),
("hue", "homeassistant.components.mqtt.sensor", CORE_ISSUE_TRACKER_HUE),
# Custom integration with known issue tracker
# Loaded custom integration with known issue tracker
("bla_custom", "custom_components.bla_custom.sensor", CUSTOM_ISSUE_TRACKER),
("bla_custom", None, CUSTOM_ISSUE_TRACKER),
# Custom integration without known issue tracker
# Loaded custom integration without known issue tracker
(None, "custom_components.bla.sensor", None),
("bla_custom_no_tracker", "custom_components.bla_custom.sensor", None),
("bla_custom_no_tracker", None, None),
("hue", "custom_components.bla.sensor", None),
# Unloaded custom integration with known issue tracker
("bla_custom_not_loaded", None, CUSTOM_ISSUE_TRACKER),
# Unloaded custom integration without known issue tracker
("bla_custom_not_loaded_no_tracker", None, None),
# Integration domain has priority over module
("bla_custom_no_tracker", "homeassistant.components.bla_custom.sensor", None),
],
@ -1135,6 +1140,32 @@ async def test_async_get_issue_tracker(
built_in=False,
)
mock_integration(hass, MockModule("bla_custom_no_tracker"), built_in=False)
cust_unloaded_module = MockModule(
"bla_custom_not_loaded",
partial_manifest={"issue_tracker": CUSTOM_ISSUE_TRACKER},
)
cust_unloaded = loader.Integration(
hass,
f"{loader.PACKAGE_CUSTOM_COMPONENTS}.{cust_unloaded_module.DOMAIN}",
pathlib.Path(""),
cust_unloaded_module.mock_manifest(),
set(),
)
cust_unloaded_no_tracker_module = MockModule("bla_custom_not_loaded_no_tracker")
cust_unloaded_no_tracker = loader.Integration(
hass,
f"{loader.PACKAGE_CUSTOM_COMPONENTS}.{cust_unloaded_no_tracker_module.DOMAIN}",
pathlib.Path(""),
cust_unloaded_no_tracker_module.mock_manifest(),
set(),
)
hass.data["custom_components"] = {
"bla_custom_not_loaded": cust_unloaded,
"bla_custom_not_loaded_no_tracker": cust_unloaded_no_tracker,
}
assert (
loader.async_get_issue_tracker(hass, integration_domain=domain, module=module)
== issue_tracker