Align max expected entities constant between modules (#118102)
This commit is contained in:
parent
722feb285b
commit
33ff84469a
3 changed files with 10 additions and 5 deletions
|
@ -1638,6 +1638,12 @@ FORMAT_DATE: Final = "%Y-%m-%d"
|
||||||
FORMAT_TIME: Final = "%H:%M:%S"
|
FORMAT_TIME: Final = "%H:%M:%S"
|
||||||
FORMAT_DATETIME: Final = f"{FORMAT_DATE} {FORMAT_TIME}"
|
FORMAT_DATETIME: Final = f"{FORMAT_DATE} {FORMAT_TIME}"
|
||||||
|
|
||||||
|
|
||||||
|
# Maximum entities expected in the state machine
|
||||||
|
# This is not a hard limit, but caches and other
|
||||||
|
# data structures will be pre-allocated to this size
|
||||||
|
MAX_EXPECTED_ENTITY_IDS: Final = 16384
|
||||||
|
|
||||||
# These can be removed if no deprecated constant are in this module anymore
|
# These can be removed if no deprecated constant are in this module anymore
|
||||||
__getattr__ = partial(check_if_deprecated_constant, module_globals=globals())
|
__getattr__ = partial(check_if_deprecated_constant, module_globals=globals())
|
||||||
__dir__ = partial(
|
__dir__ = partial(
|
||||||
|
|
|
@ -74,6 +74,7 @@ from .const import (
|
||||||
EVENT_STATE_CHANGED,
|
EVENT_STATE_CHANGED,
|
||||||
EVENT_STATE_REPORTED,
|
EVENT_STATE_REPORTED,
|
||||||
MATCH_ALL,
|
MATCH_ALL,
|
||||||
|
MAX_EXPECTED_ENTITY_IDS,
|
||||||
MAX_LENGTH_EVENT_EVENT_TYPE,
|
MAX_LENGTH_EVENT_EVENT_TYPE,
|
||||||
MAX_LENGTH_STATE_STATE,
|
MAX_LENGTH_STATE_STATE,
|
||||||
UnitOfLength,
|
UnitOfLength,
|
||||||
|
@ -177,7 +178,6 @@ _DEPRECATED_SOURCE_YAML = DeprecatedConstantEnum(ConfigSource.YAML, "2025.1")
|
||||||
# How long to wait until things that run on startup have to finish.
|
# How long to wait until things that run on startup have to finish.
|
||||||
TIMEOUT_EVENT_START = 15
|
TIMEOUT_EVENT_START = 15
|
||||||
|
|
||||||
MAX_EXPECTED_ENTITY_IDS = 16384
|
|
||||||
|
|
||||||
EVENTS_EXCLUDED_FROM_MATCH_ALL = {
|
EVENTS_EXCLUDED_FROM_MATCH_ALL = {
|
||||||
EVENT_HOMEASSISTANT_CLOSE,
|
EVENT_HOMEASSISTANT_CLOSE,
|
||||||
|
|
|
@ -7,16 +7,15 @@ from functools import lru_cache
|
||||||
import re
|
import re
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.const import MAX_EXPECTED_ENTITY_IDS
|
||||||
from homeassistant.core import split_entity_id
|
from homeassistant.core import split_entity_id
|
||||||
|
|
||||||
_MAX_EXPECTED_ENTITIES = 16384
|
|
||||||
|
|
||||||
|
|
||||||
class EntityValues:
|
class EntityValues:
|
||||||
"""Class to store entity id based values.
|
"""Class to store entity id based values.
|
||||||
|
|
||||||
This class is expected to only be used infrequently
|
This class is expected to only be used infrequently
|
||||||
as it caches all entity ids up to _MAX_EXPECTED_ENTITIES.
|
as it caches all entity ids up to MAX_EXPECTED_ENTITY_IDS.
|
||||||
|
|
||||||
The cache includes `self` so it is important to
|
The cache includes `self` so it is important to
|
||||||
only use this in places where usage of `EntityValues` is immortal.
|
only use this in places where usage of `EntityValues` is immortal.
|
||||||
|
@ -41,7 +40,7 @@ class EntityValues:
|
||||||
|
|
||||||
self._glob = compiled
|
self._glob = compiled
|
||||||
|
|
||||||
@lru_cache(maxsize=_MAX_EXPECTED_ENTITIES)
|
@lru_cache(maxsize=MAX_EXPECTED_ENTITY_IDS)
|
||||||
def get(self, entity_id: str) -> dict[str, str]:
|
def get(self, entity_id: str) -> dict[str, str]:
|
||||||
"""Get config for an entity id."""
|
"""Get config for an entity id."""
|
||||||
domain, _ = split_entity_id(entity_id)
|
domain, _ = split_entity_id(entity_id)
|
||||||
|
|
Loading…
Add table
Reference in a new issue