From 6173bfe8737082191f7eb9e59f8111845654fba1 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 16 Jan 2024 10:05:44 -1000 Subject: [PATCH] Cache commonly called Integration manifest properties (#108141) --- homeassistant/loader.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/homeassistant/loader.py b/homeassistant/loader.py index a4f1a862c45..089a0b522fa 100644 --- a/homeassistant/loader.py +++ b/homeassistant/loader.py @@ -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"]: