Add a fast path for async_get_platform (#113917)
This commit is contained in:
parent
f662e7e3cf
commit
3b66328591
2 changed files with 7 additions and 3 deletions
|
@ -515,7 +515,7 @@ class ConfigEntry:
|
||||||
|
|
||||||
if domain_is_integration:
|
if domain_is_integration:
|
||||||
try:
|
try:
|
||||||
await integration.async_get_platforms(("config_flow",))
|
await integration.async_get_platform("config_flow")
|
||||||
except ImportError as err:
|
except ImportError as err:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
(
|
(
|
||||||
|
@ -2567,7 +2567,7 @@ async def _load_integration(
|
||||||
# Make sure requirements and dependencies of component are resolved
|
# Make sure requirements and dependencies of component are resolved
|
||||||
await async_process_deps_reqs(hass, hass_config, integration)
|
await async_process_deps_reqs(hass, hass_config, integration)
|
||||||
try:
|
try:
|
||||||
await integration.async_get_platforms(("config_flow",))
|
await integration.async_get_platform("config_flow")
|
||||||
except ImportError as err:
|
except ImportError as err:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Error occurred loading flow for integration %s: %s",
|
"Error occurred loading flow for integration %s: %s",
|
||||||
|
|
|
@ -1065,7 +1065,11 @@ class Integration:
|
||||||
|
|
||||||
async def async_get_platform(self, platform_name: str) -> ModuleType:
|
async def async_get_platform(self, platform_name: str) -> ModuleType:
|
||||||
"""Return a platform for an integration."""
|
"""Return a platform for an integration."""
|
||||||
platforms = await self.async_get_platforms([platform_name])
|
# Fast path for a single platform when its already
|
||||||
|
# cached. This is the common case.
|
||||||
|
if platform := self._cache.get(f"{self.domain}.{platform_name}"):
|
||||||
|
return platform # type: ignore[return-value]
|
||||||
|
platforms = await self.async_get_platforms((platform_name,))
|
||||||
return platforms[platform_name]
|
return platforms[platform_name]
|
||||||
|
|
||||||
async def async_get_platforms(
|
async def async_get_platforms(
|
||||||
|
|
Loading…
Add table
Reference in a new issue