Cache commonly called Integration manifest properties (#108141)
parent
fa5af8f187
commit
6173bfe873
|
@ -35,11 +35,16 @@ from .generated.usb import USB
|
||||||
from .generated.zeroconf import HOMEKIT, ZEROCONF
|
from .generated.zeroconf import HOMEKIT, ZEROCONF
|
||||||
from .util.json import JSON_DECODE_EXCEPTIONS, json_loads
|
from .util.json import JSON_DECODE_EXCEPTIONS, json_loads
|
||||||
|
|
||||||
# Typing imports that create a circular dependency
|
|
||||||
if TYPE_CHECKING:
|
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 .config_entries import ConfigEntry
|
||||||
from .helpers import device_registry as dr
|
from .helpers import device_registry as dr
|
||||||
from .helpers.typing import ConfigType
|
from .helpers.typing import ConfigType
|
||||||
|
else:
|
||||||
|
from .backports.functools import cached_property
|
||||||
|
|
||||||
_CallableT = TypeVar("_CallableT", bound=Callable[..., Any])
|
_CallableT = TypeVar("_CallableT", bound=Callable[..., Any])
|
||||||
|
|
||||||
|
@ -650,12 +655,12 @@ class Integration:
|
||||||
|
|
||||||
_LOGGER.info("Loaded %s from %s", self.domain, pkg_path)
|
_LOGGER.info("Loaded %s from %s", self.domain, pkg_path)
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Return name."""
|
"""Return name."""
|
||||||
return self.manifest["name"]
|
return self.manifest["name"]
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def disabled(self) -> str | None:
|
def disabled(self) -> str | None:
|
||||||
"""Return reason integration is disabled."""
|
"""Return reason integration is disabled."""
|
||||||
return self.manifest.get("disabled")
|
return self.manifest.get("disabled")
|
||||||
|
@ -710,7 +715,7 @@ class Integration:
|
||||||
"""Return the integration IoT Class."""
|
"""Return the integration IoT Class."""
|
||||||
return self.manifest.get("iot_class")
|
return self.manifest.get("iot_class")
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def integration_type(
|
def integration_type(
|
||||||
self,
|
self,
|
||||||
) -> Literal["entity", "device", "hardware", "helper", "hub", "service", "system"]:
|
) -> Literal["entity", "device", "hardware", "helper", "hub", "service", "system"]:
|
||||||
|
|
Loading…
Reference in New Issue