mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Add cached_property to State.name (#108011)
This commit is contained in:
parent
7c848d78ab
commit
1cdfb06d77
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user