Skip to content
Snippets Groups Projects
Unverified Commit 1cdfb06d authored by J. Nick Koston's avatar J. Nick Koston Committed by GitHub
Browse files

Add cached_property to State.name (#108011)

parent 7c848d78
No related branches found
No related tags found
No related merge requests found
......@@ -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>"
......
......@@ -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(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment