1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-26 14:08:21 +00:00

Add a fast path for async_get_platform (#113917)

This commit is contained in:
J. Nick Koston
2024-03-20 22:34:33 -10:00
committed by GitHub
parent f662e7e3cf
commit 3b66328591
2 changed files with 7 additions and 3 deletions

View File

@@ -1065,7 +1065,11 @@ class Integration:
async def async_get_platform(self, platform_name: str) -> ModuleType:
"""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]
async def async_get_platforms(