diff --git a/homeassistant/components/template/template_entity.py b/homeassistant/components/template/template_entity.py index f9c61850e58d700e9d3edb54734c603e7bdd6bdf..9d08980da325640ccd88f9571d8023c1ee9f04e6 100644 --- a/homeassistant/components/template/template_entity.py +++ b/homeassistant/components/template/template_entity.py @@ -5,7 +5,7 @@ from collections.abc import Callable, Mapping import contextlib import itertools import logging -from typing import Any +from typing import TYPE_CHECKING, Any import voluptuous as vol @@ -56,6 +56,11 @@ from .const import ( CONF_PICTURE, ) +if TYPE_CHECKING: + from functools import cached_property +else: + from homeassistant.backports.functools import cached_property + _LOGGER = logging.getLogger(__name__) TEMPLATE_ENTITY_AVAILABILITY_SCHEMA = vol.Schema( @@ -294,7 +299,7 @@ class TemplateEntity(Entity): super().__init__("unknown.unknown", STATE_UNKNOWN) self.entity_id = None # type: ignore[assignment] - @property + @cached_property def name(self) -> str: """Name of this state.""" return "<None>" diff --git a/homeassistant/core.py b/homeassistant/core.py index bb84e7597b66d2fa992e88d508c579572ebb7a5e..ebd40330d13bb5e2110ee6f492d304a38e3baef0 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -46,7 +46,6 @@ import voluptuous as vol import yarl from . import block_async_io, util -from .backports.functools import cached_property from .const import ( ATTR_DOMAIN, ATTR_FRIENDLY_NAME, @@ -108,11 +107,14 @@ from .util.unit_system import ( # Typing imports that create a circular dependency if TYPE_CHECKING: + from functools import cached_property + from .auth import AuthManager from .components.http import ApiConfig, HomeAssistantHTTP from .config_entries import ConfigEntries from .helpers.entity import StateInfo - +else: + from .backports.functools import cached_property STOPPING_STAGE_SHUTDOWN_TIMEOUT = 20 STOP_STAGE_SHUTDOWN_TIMEOUT = 100 @@ -1436,7 +1438,7 @@ class State: self.state_info = state_info self.domain, self.object_id = split_entity_id(self.entity_id) - @property + @cached_property def name(self) -> str: """Name of this state.""" return self.attributes.get(ATTR_FRIENDLY_NAME) or self.object_id.replace(