Cache commonly called Integration manifest properties (#108141)

pull/108164/head
J. Nick Koston 2024-01-16 10:05:44 -10:00 committed by GitHub
parent fa5af8f187
commit 6173bfe873
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 4 deletions

View File

@ -35,11 +35,16 @@ from .generated.usb import USB
from .generated.zeroconf import HOMEKIT, ZEROCONF
from .util.json import JSON_DECODE_EXCEPTIONS, json_loads
# Typing imports that create a circular dependency
if TYPE_CHECKING:
from functools import cached_property
# The relative imports below are guarded by TYPE_CHECKING
# because they would cause a circular import otherwise.
from .config_entries import ConfigEntry
from .helpers import device_registry as dr
from .helpers.typing import ConfigType
else:
from .backports.functools import cached_property
_CallableT = TypeVar("_CallableT", bound=Callable[..., Any])
@ -650,12 +655,12 @@ class Integration:
_LOGGER.info("Loaded %s from %s", self.domain, pkg_path)
@property
@cached_property
def name(self) -> str:
"""Return name."""
return self.manifest["name"]
@property
@cached_property
def disabled(self) -> str | None:
"""Return reason integration is disabled."""
return self.manifest.get("disabled")
@ -710,7 +715,7 @@ class Integration:
"""Return the integration IoT Class."""
return self.manifest.get("iot_class")
@property
@cached_property
def integration_type(
self,
) -> Literal["entity", "device", "hardware", "helper", "hub", "service", "system"]: